setIpAddress($_SERVER['REMOTE_ADDR']); //$visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']); //if(!empty($_COOKIE['__utma'])) $visitor->fromUtma($_COOKIE['__utma']); //error_log('DEBUG: 1'); //$visitor->fromUtma($_COOKIE['__utma']); //$visitor->setScreenResolution('1480x1200'); // Assemble Session information //$session = new GoogleAnalytics\Session(); //error_log('DEBUG: 2 '); //$session->fromUtmb($_COOKIE['__utmb']); //if(!empty($_COOKIE['__utmb'])) $visitor->fromUtmb($_COOKIE['__utmb']); //error_log('DEBUG: 3 '); // Get filename from the previous request $filename = parse_url(urldecode($_SERVER['REQUEST_URI']), PHP_URL_PATH); //$filetype = preg_replace("/.+\.(.+)/i","$1",$filename); // Assemble Page information //$page = new GoogleAnalytics\Page($filename); //error_log('DEBUG: 4 '); //$page->setTitle($filename); //$page->setReferrer($_SERVER['HTTP_REFERER']); //if(!empty($_SERVER['HTTP_REFERER'])) $page->setReferrer($_SERVER['HTTP_REFERER']); //error_log('DEBUG: 5 '); // Track page view //$tracker->trackPageview($page, $session, $visitor); //error_log('DEBUG: 6 '); // Create the URL for the PDF $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; //error_log('DEBUG: 6 '); $url = $protocol.$_SERVER['HTTP_HOST'].$filename; //error_log('DEBUG: 7 - URL: ' . $url); //$file = fopen("/var/www/vhosts/demo.medicareinteractive.org/pdf/debug.log","a"); //fwrite($file,$url.PHP_EOL); //fclose($file); //GA4 Begin $measurement_id='G-J2L1LNEY8F'; $api_secret='eTwEca5nT4CEW9EX3owPEQ'; $user_id= mt_rand(1000000000,9999999999); //$user_id=sprintf('%10d', (string)$user_id); //error_log('DEBUG: Padded Rand User Id - ' . $user_id); $clientID = $user_id . '.' . (string)time(); if ( isset($_COOKIE['_ga']) ) { $clientID = $_COOKIE['_ga']; } $data = array( 'client_id' => $clientID, 'events' => array( 'name' => 'pdf_download', 'params' => array( 'engagement_time_msec' => '300', 'session_id' => (string)time(), 'file_name' => basename($filename) ) ) ); $ch2 = curl_init(); curl_setopt($ch2, CURLOPT_HEADER, 1); curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch2, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' )); curl_setopt($ch2, CURLOPT_URL, 'https://www.google-analytics.com/mp/collect?measurement_id=' . $measurement_id . '&api_secret=' . $api_secret); curl_setopt($ch2, CURLOPT_POST, 1); curl_setopt($ch2, CURLOPT_POSTFIELDS, json_encode($data)); // error_log('DEBUG: Data - ' . json_encode($data)); $content=curl_exec($ch2); curl_close($ch2); //error_log('DEBUG: Content - ' . $content); //GA4 End //mail('mbednarz@medicarerights.org','URL',$url); // Fetch the PDF (cURL it) $ch = curl_init($url); //error_log('DEBUG: 8 '); // This creates a user-agent string that we set .htaccess to ignore (preventing an endless loop) curl_setopt($ch, CURLOPT_USERAGENT, "LunaMetrics123"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $content2 = curl_exec($ch); //error_log('DEBUG: ' . $content2); //error_log('DEBUG: 9 '); curl_close($ch); // For good measure exit; ?>