【问题标题】:Implement Google Analytics With Userid in Open Cart在 Opencart 中使用用户 ID 实现 Google Analytics
【发布时间】:2015-01-06 12:34:59
【问题描述】:

我想跟踪每个客户我怎么能这样做谷歌分析的文档有这个代码

ga(‘set’, ‘&uid’, {{USER_ID}}); // Set the user ID using signed-in user_id.

如果我的客户没有登录,我如何在此传递用户 ID,因为打开的购物车有一个管理面板设置来输入谷歌分析和 ehat,我应该怎么做。

【问题讨论】:

  • 希望$this->customer->getuserid() 会给你用户ID。您可以将此添加到代码中
  • @Lepanto 其实是$this->customer->getId()
  • @shadyyx 谢谢!
  • 我感觉到这里通常存在误解 - Userid 功能无法帮助您区分用户。它可以启用跨设备跟踪,但您仍会获得汇总数据。
  • 除了用户id外,还必须在用户范围内使用自定义维度(可以使用相同的值,需要维度才能在界面中公开值)。请记住,您不得使用任何会泄露用户身份的内容(不过,您绑定到后端系统的 id 是可以的)并且不得使用 unqiue 设备标识符(IMEI 等)。自定义维度不会显示在标准报告中,您需要创建自定义报告。

标签: javascript php google-analytics opencart


【解决方案1】:

Opencart 在管理中使用一个设置,您可以在其中插入整个 GA 代码。您也可以将其用于用户跟踪。您要做的唯一更改是将这行 JS 代码添加到管理中的该字段中:

ga('set', '&uid', #CUSTOMER_ID#);

这个字符串将被 PHP 在catalog/controller/common/header.php 中解析,就像这样 - 找到这一行

$this->data['google_analytics'] = html_entity_decode( ... );

在这一行之后放上这段代码:

if ($this->customer->isLogged()) {
    // replace %s with customer ID
    $this->data['google_analytics'] = str_replace('#CUSTOMER_ID#', $this->customer->getId(), $this->data['google_analytics']);
} else {
    // customer is not logged in, remove the user tracking part
    $this->data['google_analytics'] = str_replace("ga('set', '&uid', #CUSTOMER_ID#);", "", $this->data['google_analytics']);
}

应该这样做 - 还要检查客户是否已登录。

【讨论】:

  • 谢谢伙计,它正在工作,但在我的谷歌分析上它仍然显示聚合数据,我想做的是我想通过他们的 id 跟踪每个客户,以便我可以跟踪访问过的用户 id哪个网址和等等等等。你能告诉我这个过程吗?
  • 我不是 GA 专家,但通过 Google 快速搜索,我找到了 this resource。希望它能解决你的问题。如果您要使用新的 analytics.js,您可以使用 this way.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-14
  • 2023-02-14
  • 1970-01-01
  • 1970-01-01
  • 2014-09-22
  • 2016-05-04
  • 2014-03-16
相关资源
最近更新 更多