如何动态更改Google代码帐户ID - 角度应用

时间:2022-11-23 08:13:07

i am trying to implement google tag manager in my app (angular 5 app)

我想在我的应用程序(角5应用程序)中实现谷歌标记管理器

however, my app is serving a few clients (companies accounts), that access the app from multiples paths e.g:www.myapp.com/dymamiPath123 (totally dynamically - cant be hardcode)

但是,我的应用程序服务于几个客户端(公司帐户),从多个路径访问应用程序,例如:www.myapp.com/dymamiPath123(完全动态 - 不能硬编码)

i need that change the google tag id per the data that comes from server (i save each account google tag id in my DB)

我需要根据来自服务器的数据更改谷歌标签ID(我在我的数据库中保存每个帐户谷歌标签ID)

i currently have this in my index.html

我目前在我的index.html中有这个

 <script>
    (function(w, d, s, l, i) {
        w[l] = w[l] || [];
        w[l].push({
            'gtm.start': new Date().getTime(),
            event: 'gtm.js'
        });
        var f = d.getElementsByTagName(s)[0],
            j = d.createElement(s),
            dl = l != 'dataLayer' ? '&l=' + l : '';
        j.async = true;
        j.src =
            'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
        f.parentNode.insertBefore(j, f);
    })(window, document, 'script', 'dataLayer', '** id ***');
</script>

how can i change it before\after the app is deployed? it is enough to change the id in the function? (not that i know how) or change in all the rendered tags?

在部署应用程序之后,如何在\之前更改它?它足以改变函数中的id? (不是我知道怎么做)或改变所有渲染的标签?

thanks!

谢谢!

1 个解决方案

#1


0  

Why dont use only one GTM and make a lookup table for the web property you want to send info to?

为什么不只使用一个GTM并为要发送信息的Web属性创建查找表?

So you only ll need a variable that has always available the origin of the user (lets call it origin). And you set all your tag with triggers for specific origins or generic ones but always us a table in order to send hits to different GA accounts depending on the origin.

因此,您只需要一个始终可用用户来源的变量(让我们称之为原点)。并且您将所有标记设置为特定来源或通用触发器的触发器,但始终是我们的表格,以便根据来源向不同的GA帐户发送匹配。

Finally you can choose to duplicate hits if you want to have a central web property with all the data (use a custom dimension on user level to save the origin). Here is our guru: https://www.simoahava.com/gtm-tips/send-google-analytics-tag-multiple-properties/

最后,如果您希望拥有包含所有数据的*Web属性,则可以选择复制匹配(在用户级别使用自定义维度来保存原点)。这是我们的大师:https://www.simoahava.com/gtm-tips/send-google-analytics-tag-multiple-properties/

Hope it helps!

希望能帮助到你!

#1


0  

Why dont use only one GTM and make a lookup table for the web property you want to send info to?

为什么不只使用一个GTM并为要发送信息的Web属性创建查找表?

So you only ll need a variable that has always available the origin of the user (lets call it origin). And you set all your tag with triggers for specific origins or generic ones but always us a table in order to send hits to different GA accounts depending on the origin.

因此,您只需要一个始终可用用户来源的变量(让我们称之为原点)。并且您将所有标记设置为特定来源或通用触发器的触发器,但始终是我们的表格,以便根据来源向不同的GA帐户发送匹配。

Finally you can choose to duplicate hits if you want to have a central web property with all the data (use a custom dimension on user level to save the origin). Here is our guru: https://www.simoahava.com/gtm-tips/send-google-analytics-tag-multiple-properties/

最后,如果您希望拥有包含所有数据的*Web属性,则可以选择复制匹配(在用户级别使用自定义维度来保存原点)。这是我们的大师:https://www.simoahava.com/gtm-tips/send-google-analytics-tag-multiple-properties/

Hope it helps!

希望能帮助到你!