douguizhuang8276 2012-08-20 19:18
浏览 68
已采纳

当用户点击链接继续访问网站时,使用php-ga和维护会话的Google Analytics电子邮件视图

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);
?>
  • 写回答

1条回答 默认 最新

  • druzuz321103 2012-08-20 20:22
    关注

    Google analytics pageviews/events are logged with the pixel call to ga servers and the sessions are tracked with the GA cookie. Now there are multiple problems with trying to track email opens and preserving sessions.

    1. Not all clients fetch the images by default.
    2. When server-side api is used to track the event like in case of php-ga, ga cookie is still not set till user actually clicks through and lands on an actual page which requests ga pixel and thus sets the cookie with a new sessionID.

    To go around this, one could use only the server api on all page views. One would then be able to

    1. Serialize the php-ga Session object to client session in email open call.
    2. On normal page view, if there is a session information, unserialize it and construct the GoogleAnalytics\Session object before passing it in trackPageView call.

    This approach, however, will require re-designing the entire ga tracking scheme and replace javascript api usage with php-ga. There is a possible work-around which involves creating the ga pixel url and setting it as src attribute in your mails. This approach has been discussed here, and detailed description here. The documentation, however mentions that you need to use mobile specific tracking code for creating the url, so it might or might not still combine the sessions. But it still looks pretty close to simulating seamless tracking of opens and clicks in email campaigns.

    Even if this setup works, the email opens that do not happen on a web browser (in case of mail clients like Outlook or Mail), the events will still not be in the same session. Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧