跨网域跟踪使用iframe跟踪错误的ID

时间:2018-10-07 02:03:04

标签: javascript iframe google-analytics

所以我有带有iframe和链接器的google Analytics代码:

下面的代码获取错误的客户端ID:

_FB_f118d95cc82c2a8data&logged_in=false&xd_action=proxy_ready;

   <iframe id="iframe-name" src="[URL]" onload="iframe_init();"></iframe>

   <script>
    (function(i,s,o,g,r,a,m) 
     {i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new  Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
    ga('create', 'UA-XXXXX-1', 'auto', {storage: 'none','allowLinker': true});

      ga('require', 'linker');
      ga('linker:autoLink', ['https://www.domain2.com/'],false,true); 
      ga('send', 'pageview');
      function iframe_init(){
        if(typeof ga!=='undefined') {
          ga(function(tracker) {
          window.localStorage.setItem('ga_clientId',tracker.get('clientId')); 
          var clientId = window.localStorage.getItem('ga_clientId');
          var frameWindow = document.getElementById('booking_form').contentWindow;
          var frameURL = 'https://www.domain2.com/';
          frameWindow.postMessage(clientId, frameURL);
          console.log("DRAFT CLIENT ID ",clientId);

        });
    }
  }
</scrip>

0 个答案:

没有答案