gpt4 book ai didi

wordpress - 为什么 Google Analytics 不使用 _setcustomvar 跟踪我的所有事件?

转载 作者:行者123 更新时间:2023-12-03 16:00:36 27 4
gpt4 key购买 nike

我正在使用以下代码
_gaq.push(['_setCustomVar',1,'logged-in','administrator',1],['_trackPageview']);
跟踪我网站上的登录用户级别(运行 WordPress)。

现在我的问题是,上个月我有大约 100 个新注册,但谷歌分析只显示我网站上活跃的 65 个注册用户。

这是解释结果的错误还是我做错了什么?

最佳答案

序言
使用 Google Analytics(GA),您不可能注册所有点击。这不是 GA 特定的问题。任何分析工具都可能受到影响。

例如,想象一下,用户在您的 WP 网站上注册时连接中断。 javascript 代码可能不会被执行。新用户有望注册,但不会通知 GA。

解决方法
此解决方法是将 GA 通知与您在服务器端 上的注册过程权利 绑定(bind):

第 1 步: 使用 user_register 钩子(Hook)注册一个 php 函数。

add_action('user_register', 'myplugin_registration_save');function myplugin_registration_save($user_id) {    // GA will be notified here ...}

Step 2: Inside this registred function notify GA of the new user registration.
Here comes php-ga. It's a GA client written in PHP. You can implement nearly every parameter and tracking feature of the original GA Javascript client. Call it to track your GA custom vars.

Here is a sample code from the php-ga site:

use UnitedPrototype\GoogleAnalytics;

// Initilize GA Tracker
$tracker = new GoogleAnalytics\Tracker('UA-12345678-9', 'example.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();

// Assemble Page information
$page = new GoogleAnalytics\Page('/page.html');
$page->setTitle('My Page');

// Track page view
$tracker->trackPageview($page, $session, $visitor);

还有更多
即使您实现了变通方法,它也可能无法成功通知 GA。例如,如果 GA 服务器尝试一些重负载,您的通知可能会丢失。

我建议您同时使用系统通知: GA Javascript 客户端和 GA PHP 客户端。

为他们分配两个不同的事件“JS-new-user-registred”和“PHP-new-user-registred”。通过两个注册事件,您可以提高分析数据的质量。您也提高了新注册通知率。

永远记住,这种方法可能不是 100% 准确的。例如,在客户端,ga.js 文件可能被阻止(防火墙等)。同时,您的 PHP 客户端可能无法成功通知 GA。结果是没有跟踪新的注册。

关于wordpress - 为什么 Google Analytics 不使用 _setcustomvar 跟踪我的所有事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16560994/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com