通过GTM进行iFrame跨域跟踪

时间:2019-02-06 21:35:57

标签: google-analytics cross-domain google-tag-manager

我的客户的网站包含捐赠表单(https://www.resurge.org/donate/),该表单是来自第三方提供商的嵌入式iframe。我在主域和iframe页面上安装了单独的GTM容器,并希望将原始clientId传递给iFrame。在父页面上,我有以下代码:

<script>
setTimeout(function(){ 
  ga(function(tracker) {
    var clientId = tracker.get('clientId');
    var frameWindow = document.getElementById('my_iframe').contentWindow;
    // change https://xyz.shoppingcart.com to match your iFrame domain
    frameWindow.postMessage(clientId, 'https://app.etapestry.com'); 
  });
}, 2000); 
</script>

以及在iFrame中:

<script>
  window.addEventListener('message', function(event) {
    // Ignores messages from untrusted domains.
    if (event.origin != 'https://www.resurge.org') return;
    // Creates the tracker with the data from the parent page.
    ga('create', 'UA-19540393-1', 'auto', {clientId: event.data});
    ga('send', 'pageview');
  });
</script>

GA调试器显示以下结果:

Running command: ga("create", "UA-19540393-1", {name: "gtm2", allowLinker: true, cookieDomain: "auto"})   
  Creating new tracker: gtm2 
  Auto cookieDomain found: "etapestry.com" 
Running command: ga("gtm2.set", "&gtm", "2wg1r0WMV887L") 
Running command: ga("gtm2.set", "hitCallback", [function])

我希望在cookieDomain: "auto"之后看到原始的clientId。不知道我在这里想念的是什么。

0 个答案:

没有答案