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 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗