与谷歌标签管理
问题描述:
推自定义变量我使用GA代码在我的网站像下面与谷歌标签管理
<script type="text/javascript" language="javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-1']);
_gaq.push(['_setDomainName', '.myweb.co.uk']);
if (source != '') {
_gaq.push(function() {
extga._setCampValues(source, medium, name);
});
}
// Set the custom variable ranking
var url = String(document.referrer);
// confirm they came from G
if (url.indexOf("google.co") != -1 || url.indexOf("google.be") != -1 || url.indexOf("google.ie") != -1 || url.indexOf("google.fr") != -1) {
var urlVars = {};
var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
urlVars[key] = value;
});
// Push to GA Custom Variables
_gaq.push(['_setCustomVar', '1', 'Keywords Rankings', urlVars["cd"], 1]);
}
//Track the record in GA
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
现在我想更换与谷歌代码管理工具GA代码。我的问题是,我们如何使用Google标记managera在Google Analytics上推送cstom变量,目前我正在使用_gaq.push方法为广告系列推送自定义数据。
问候, 哈比卜
答
另一种选择是使用自定义Javascript宏来处理自定义变量。你可以把你的整个组自定义变量的排名中它:
function(){
var url = {{referrer}}; //there is a GTM macro for the HTTP referrer
// confirm they came from G
if (url.indexOf("google.co") != -1 || url.indexOf("google.be") != -1 || url.indexOf("google.ie") != -1 || url.indexOf("google.fr") != -1) {
var urlVars = {};
var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
urlVars[key] = value;
});
// Return the Custom Variable value
return urlVars["cd"];
}
}
*注意,我没有测试此代码,但它应该是八九不离十。
然后你可以使用该宏,你可能命名它像{{customVar1Val}}并把它插入到谷歌Analytics(分析)标签:
答
一旦你移动到谷歌代码管理工具,您_gaq.push()
与dataLayer.push()
取代。 在内部,dataLayer.push()在标签触发规则被触发时调用_gaq.push()。
创建Google Analytics(分析)tag
并使用您的帐户,域名等进行配置。默认情况下,它会在所有页面上使用射击rule
运行。
您既可以使用GUI来管理GA配置,也可以使用自定义html代码段并粘贴代码。
您将要使用macros
来构建自定义变量。 使用自定义JavaScript宏,你可以重用你现有的代码。然后将这个宏包含在你的GA标签中。
答
你的问题可以在Tag Manager developers guide回答。甚至有一节叫做Migrating Tags to Google Tag Manager,您可以在其中阅读
...本节介绍最佳实践迁移工作流程。该过程有5个主要步骤:
- 地图网站(可选)
- 列表项
- 执行标准谷歌标签管理器代码段
- 添加事件和变量
- 添加标签,在相关发射规则谷歌代码管理工具的管理界面
- 最终迁移交换
感谢Blexy的帮助 –
您好我也使用_gaq.push(['_ trackPageview','/ activity-weekends/inquiry /']);将自定义目标推送到GA,我们如何在GTM中处理这个问题。谢谢 –