简体   繁体   English

点击后在Google跟踪代码管理器中加载跟踪代码段

[英]Load Tracking Snippets in Google Tag Manager on click

So in Germany and I guess in a lot of other countries aswell we have a lot of privacy regulations and they will be tightened in 2018. What is changing is that you have to actively get a users permission to track them instead of an opt out. 因此,在德国,而且我想在许多其他国家/地区,我们也有很多隐私法规,它们将在2018年收紧。正在发生的变化是,您必须主动获得用户的许可才能跟踪它们,而不是选择退出。

So I figured the easiest way to manage that is using the Google Tag Manager. 因此,我想出了最简单的管理方式,就是使用Google跟踪代码管理器。 My idea is: 我的想法是:

  1. User comes on a website and gets a prompt where he can agree or disagree with beeing tracked. 用户进入网站并获得提示,表示同意或不同意所跟踪的蜜蜂。

  2. If he agrees a cookie is set and the tracking snippets are loaded. 如果他同意设置cookie并加载跟踪代码段。

  3. If he reload the page the GTM would check if the cookie is set and if so load the snippets. 如果他重新加载页面,GTM将检查cookie是否已设置,如果已加载,则加载代码段。

I have two questions tho. 我有两个问题。 My first question is if the tracking snippets will work even if they are loaded after the cookie check. 我的第一个问题是,即使在Cookie检查之后加载了跟踪代码段,跟踪代码段也能正常工作。 For example Google Analytics and Facebook. 例如Google Analytics(分析)和Facebook。

My second question is: What is the best way to load the snippets in step 2? 我的第二个问题是:在第2步中加载代码段的最佳方法是什么? Do I have to configure a trigger in GTM if the button on the website was clicked? 如果单击网站上的按钮,是否必须在GTM中配置触发器?

Thank you in advance! 先感谢您!

I think the easiest way to achieve that, is like that: 我认为最简单的方法是这样的:

I presume that if he agrees, your website is setting cookie acceptTracking and then reloading the page 我认为如果他同意,您的网站将设置Cookie acceptTracking ,然后重新加载页面

In all your website pages wrap GTM code into condition if cookie exists 您的所有网站页面中,如果存在Cookie,则将GTM代码包装成条件

if (document.cookie.match(/^(.*;)?\s*acceptTracking=\s*[^;]+(.*)?$/)) {
   (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','GTM-XXXXXX');
}

That means if cookie doesn't exist, you don't need to load GTM at all. 这意味着如果不存在Cookie,则根本不需要加载GTM。

Because even if you will include GTM without any tags, it will still track user clicks. 因为即使您将包含不带任何标签的GTM,它仍会跟踪用户的点击。 That's way I think better way is do not load GTM at all 我认为这样更好的方法是根本不加载GTM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM