为什么Google Analytics不会使用_setcustomvar跟踪我的所有活动? [英] Why Google Analytics doesn't track all my events with _setcustomvar?

查看:194
本文介绍了为什么Google Analytics不会使用_setcustomvar跟踪我的所有活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码:
$ b

_gaq.push(['_ setCustomVar',1,'logged-in','administrator ',1],['_ trackPageview']);



用于跟踪我的网站上登录的用户级别(运行WordPress) / p>

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



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

解决方案

PREAMBLE

使用Google Analytics(GA)时,无法获得所有已注册的匹配结果。这不是GA的具体问题。任何分析工具都可能受到影响。


想象一下,例如,用户在您的WP网站上注册时连接断开。机会是JavaScript代码不会被执行。新用户希望注册,但GA不会收到通知。




解决方法

这种解决方法是将GA的通知与注册过程绑定在一起 在服务器端

第1步:注册php函数 user_register hook。

 
add_action('user_register','myplugin_registration_save');
函数myplugin_registration_save($ user_id){
// GA将在这里通知...
}



<第2步:在此注册功能中,通知新用户注册的GA。

php-ga 。这是一个用PHP编写的GA客户端。您几乎可以实现原始GA Javascript客户端的每个参数和跟踪功能。打电话跟踪您的GA定制变量。



以下是来自php-ga网站的示例代码:

 使用UnitedPrototype \GoogleAnalytics; 

//启动GA跟踪器
$ tracker = new GoogleAnalytics\Tracker('UA-12345678-9','example.com');

//汇编访问者信息
//(也可以从数据库中反序列化)
$ visitor = new GoogleAnalytics\Visitor();
$ visitor-> setIpAddress($ _ SERVER ['REMOTE_ADDR']);
$ visitor-> setUserAgent($ _ SERVER ['HTTP_USER_AGENT']);
$ visitor-> setScreenResolution('1024x768');

//汇编会话信息
//(也可以从PHP会话中反序列化)
$ session = new GoogleAnalytics\Session();

//汇编页面信息
$ page = new GoogleAnalytics\Page('/ page.html');
$ page-> setTitle('My Page');

//轨迹页面视图
$ tracker-> trackPageview($ page,$ session,$ visitor);



还有更多

即使您实施解决方法,也可能无法成功通知GA。如果GA服务器试验了一些重负载的情况,您的通知可能会丢失。



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



将它们分配给两个不同的事件'JS-new-user-registred'和'PHP-new -user-registred。通过两次注册活动,您可以提高分析数据的质量。您也可以提高新的注册通知率。



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


I'm using the following code

_gaq.push(['_setCustomVar',1,'logged-in','administrator',1],['_trackPageview']);

to track logged-in user levels on my site (running WordPress).

Now my problem is that in the last month I had around 100 new registrations, but Google Analytics only shows me 65 registered users active on my site.

Is this an error in interpreting the results or am I doing something wrong?

解决方案

PREAMBLE
With Google Analytics(GA), it's impossible to get ALL your hits registred. This is not a GA specific problem. Any analytics tool can be affected.

Imagine for instance, that the user gets its connection broken while registring on your WP site. Chances are that the javascript code won't be executed. The new user will be registred hopefully, but GA won't be notified.


WORKAROUND
This workaround would be to tied the notification of GA with your registration process right on the server side:

Step 1: Register a php function with the user_register hook.

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);


THERE IS MORE
Even if you implement the workaround, it may not be able to notify GA sucessfully. If GA server experiment some heavy load for instance, your notification may be lost.

I would advice you to use both system notification : GA Javascript client AND GA PHP client.

Assign them two distinct events 'JS-new-user-registred' and 'PHP-new-user-registred'. With two registred events you improve the quality of your analytic data. You improve the new registrations notification rate too.

Always keep in mind that this approach may not be 100% accurate. For example, on the client side the ga.js file may be blocked (firewall etc). At the same time, your PHP client may not be able to notify succesfully GA. It results that the new registration is not tracked.

这篇关于为什么Google Analytics不会使用_setcustomvar跟踪我的所有活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆