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.

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

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来