html Google Analytics跨域设置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Google Analytics跨域设置相关的知识,希望对你有一定的参考价值。

Google Analytics cross domain setup.

more info at https://support.google.com/analytics/answer/1034342?hl=en&ref_topic=2772342 

ecommerce tacking https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce
<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','//www.google-analytics.com/analytics.js','ga');

  ga('require', 'linker');
  ga('require', 'ec', 'ec.js');
  ga('linker:autoLink', ['YOUR_SITE.com', 'yahoo.net'] );
  ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
  ga('send', 'pageview');
</script>



<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','//www.google-analytics.com/analytics.js','ga');
  
  ga('require', 'linker');
  ga('require', 'ec', 'ec.js');
  ga('linker:autoLink', ['YOUR_SITE.com', 'yahoo.net'] );
  ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
  ga('send', 'pageview');

  ga('ecommerce:addTransaction', {
    'id': orderNum, // Transaction ID. Required.
    'affiliation': 'Store / site name', // Affiliation or store name.
    'revenue': orderSubTotal, // Grand Total.
    'shipping': orderShipping, // Shipping.
    'tax': orderTax // Tax.
  });

  for(var i=0,j=numOfItems; i<j; i++){
    ga('ecommerce:addItem', {
      'id': orderNum, // Transaction ID. Required.
      'name': items[i], // Product name. Required.
      'sku': ids[i], // SKU/code.
      'price': price[i], // Unit price.
      'quantity': qtys[i] // Quantity.
    });
  }
  ga('ecommerce:send');
</script>

以上是关于html Google Analytics跨域设置的主要内容,如果未能解决你的问题,请参考以下文章

使用 Google Analytics 对子域进行跨域跟踪

JavaScript 跨域Google Analytics广告系列转置

Google Analytics 跨域:链接器参数哈希错误或过期

getLinkerUrl 未跨域传递 cookie - Google Analytics

Shopify 的传统 Google Analytics 跨域跟踪不传递数据

Google Analytics 跨域转化跟踪和归因于 AdWords 广告系列