[英]Analytics custom vars in a Google Site
Is it possible to register a custom var in a google site? 是否可以在google网站上注册自定义var? I've been trying for a week and still can't get it. 我已经尝试了一个星期但仍然无法得到它。
I know there are two ways to do this. 我知道有两种方法可以做到这一点。
Async: this is recommended by analytics docs, but it doesn't work because gSites doesn't allow to add a node dynamically using DOM. 异步:这是分析文档推荐的,但它不起作用,因为gSites不允许使用DOM动态添加节点。 I tried a lot of times... 我试过很多次......
_gaq.push(['_setCustomVar', 4, 'customVar4', "cuatro", 2 ]);
_gaq.push(['_trackPageview']);
Sync: I can't make this work, it tries to use _gat object before it is ready (or fully loaded) and end with an error. 同步:我无法使其工作,它尝试在准备好(或完全加载)之前使用_gat对象并以错误结束。
var tracker = _gat._getTracker("UA-XXXXXX-X");
tracker._setCustomVar(2,"tracker2","mail",1);
pageTracker._trackPageview();
Can anybody help me? 有谁能够帮我? the problem is in google sites only, creating an app script, and adding it as a gadget. 问题出在谷歌网站上,创建一个应用程序脚本,并将其添加为小工具。
Thanks. 谢谢。
As described in this help page 如本帮助页面所述
<script>
tag 现在您可以插入<script>
标记了 Try to add the common code snippet: 尝试添加公共代码段:
<script type="text/javascript">
_gaq.push(function() {
var tracker = _gat._getTrackerByName();
tracker._setCustomVar(1, 'Feedback', 'Closed', 1);
tracker._trackPageview();
});
</script>
I also recommend you to check the Google Analytic's devguide . 我还建议您查看Google Analytic的偏差 。
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
https://developers.google.com/analytics/devguides/collection/gajs/asyncTracking https://developers.google.com/analytics/devguides/collection/gajs/asyncTracking
Since Google Sites doesn't allow dynamic insertion, just add the script explicitly: 由于Google协作平台不允许动态插入,只需明确添加脚本:
<script type="text/javascript" src="https://ssl.google-analytics.com/ga.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_setCustomVar', 4, 'customVar4', "cuatro", 2 ]);
_gaq.push(['_trackPageview']);
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.