我想跟踪每个客户,我该怎么做谷歌分析上的文档有这个代码
ga(‘set’, ‘&uid’, {{USER_ID}}); // Set the user ID using signed-in user_id.
我如何在其中传递用户ID,因为开放式购物车有一个管理面板设置来输入谷歌分析,如果我的客户没有登录,我应该做什么。
最佳答案
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']);
}
这应该可以做到 - 还可以检查客户是否登录。
关于javascript - 在 Opencart 中使用用户 ID 实现 Google Analytics,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27798822/