I'm using php-ga and a php page on my server to serve up an image in an email, but also at the same time track a page view (/email-viewed) to google analytics for our website. So when the user opens the email with images enabled, my php script fires off the page view to google analytics. Now after this happens, the users often click on some links in the email that returns them to our website. I can tell people are clicking these links because the landing pages are logged within google analytics.
The problem I am having is that google analytics does not consider the two actions to be one session. Is there any way i can force/trick google analytics into believing that these two page views are one session?
This is my email-tracking.gif image that gets loaded by my server and treated as php:
// Initilize GA Tracker
$tracker = new GoogleAnalytics\Tracker('UA-REMOVED-1', 'www.REMOVED.com');
// Assemble Visitor information
// (could also get unserialized from database)
$visitor = new GoogleAnalytics\Visitor();
$visitor->setIpAddress($_SERVER['REMOTE_ADDR']);
$visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']);
$visitor->setScreenResolution('1024x768');
// Assemble Session information
// (could also get unserialized from PHP session)
$session = new GoogleAnalytics\Session();
if(isset($_GET['location'])){
$img='./images/'.$_GET['location'].'.gif';
// Assemble Page information
$page = new GoogleAnalytics\Page('/quote-email');
$page->setTitle('Quote Email Viewed');
}
else {
}
// Track page view
$tracker->trackPageview($page, $session, $visitor);
header("Content-Type: image/gif");
readfile($img);
?>