在Google跟踪代码管理器中设置动态宏 [英] Setting a Dynamic Macro in Google Tag Manager

查看:90
本文介绍了在Google跟踪代码管理器中设置动态宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种类型的Universal Analytics(UA)帐户:所有子网域上的汇总属性ID以及仅出现在该子网域上的子网域特定ID。总共有7个子域属性。



我想知道,不是为每个子域/属性设置2个标签(ecomm事务标签和常规UA标签)总共有16个 - 如果我可以设置这两个标签并使UA-ID为相应属性动态更改。



示例:使用id为UA-XXXXXXXX - {{UA ID}},其中{{UA ID}}由我定义并根据当前子域的规则进行设置。某处 - 不要求开发者创建一个新的变量对 - 将一个属性关联到1,将属性两个关联到2等等,这样正确的跟踪器就会在右侧子域中被触发。

b
$ b

感谢!

解决方案

我通过以下解决方法完成了此操作:




  • 我创建了一个自定义的html标记,当DOM准备就绪时加载(规则{{event}} == gtm.dom) $ b
  • 在这个自定义标签中,我放了一些javascript来确定子域(或者其他动态属性)并设置一个变量 - 让我们称之为ua - 相应的 在同一个标​​记中,我将ua变量和自定义事件推送到数据层:

    dataLayer.push({
    'ua':ua,
    'event':'INIT'
    });

  • 我创建了一个宏UA ID,它从上面的push变量


  • 我创建了一个规则on init({{event}} == INIT

  • 规则来触发所有的后续标签(因此只有在设置了UA变量后才能执行)



到目前为止(即,在过去的2个月里)这个工作得很好,所以它也可能适用于你。

I have two types Universal Analytics (UA) accounts: a rollup property ID that goes on all subdomains, and a subdomain-specific ID that only appears on that subdomain. There are a total of 7 subdomain properties.

I was wondering, instead of setting up 2 tags (ecomm transaction tag and the regular UA tag) for each subdomain/property - a total of 16 - if I could set up just those two tags and have the UA-ID dynamically changed for the corresponding property.

Example: set up the tag with the id as "UA-XXXXXXXX-{{UA ID}}" where "{{UA ID}}" is defined by me and set with a rule depending on what the current subdomain is. Somewhere - without asking the devs to create a new variable pair - have property one associated to "1", property two associated to "2" and so forth, so that the right tracker is fired on the right subdomain.

Thanks!

解决方案

I did this via the following workaround:

  • I created a custom html tag that loads when the DOM is ready ( rule "{{event}} == gtm.dom)
  • inside that custom tag I put some javascript to determine the subdomain (or whatever dynamic property) and set a variable - let's call it "ua" - accordingly
  • inside the same tag I push the ua variable and a custom event to the datalayer :

    dataLayer.push({ 'ua':ua, 'event': 'INIT' });

  • I created a macro "UA ID" that gets it's value from the push variable above

  • I created a rule "on init" ( {{event}} == INIT
  • I used that rule to fire all subsquent tags (so they would be executed only after the UA variable has been set)

So far (i.e. for the last 2 months) this is working rather well, so it might work for you, too.

这篇关于在Google跟踪代码管理器中设置动态宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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