跨域跟踪设置Google Analytics

时间:2012-03-02 10:49:53

标签: javascript html google-analytics

我尝试使用谷歌分析设置跨域跟踪。基本上我有一个小部件,可以将顾客引导到他们可以购买物品的购物篮。

我们需要为客户提供一些代码才能放入收据页面,但我无法进行设置。我在两个域上设置了一个虚拟项目,主页上有以下代码(开发时将是小部件),代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title> 
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-27715734-3']);
  _gaq.push(['_setDomainName', 'myDomainA.com']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>


</head>
<body>


     <p>Direct to techport page &nbsp; <a href ="http://techport.e-talemarketing.co/Payment.html"onclick="_gaq.push(['_link', 'http://techport.e-talemarketing.co/Payment.html']); return false;"><input id="btnTechport" type="button" value="techport" /></a></p>

     <p>Direct to forOffice page &nbsp; <a href ="http://foroffice.etailtesting.co.uk/Payment.html"onclick="_gaq.push(['_link', 'http://foroffice.etailtesting.co.uk/Payment.html']); return false;"><input id="btnForOffice" type="button" value="ForOffice" /></a></p>

并将以下内容放在虚拟收据页面上:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-27715734-3']);
  _gaq.push(['_setDomainName', 'myDomainA.com']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

     // add item might be called for every item in the shopping cart
        // where your ecommerce engine loops through each item in the cart and
        // prints out _addItem for each
        _gaq.push(['_addItem',
                        'techport222',           // order ID - required
                        '54321',                    // SKU/code - required
                        'Shiny jewels',          // product name
                        '',                             // category or variation
                        '8',                           // unit price - required
                        '3'    

                         ]);

        _gaq.push(['_trackTrans']); //confirms that a purchase has occurred and submits transaction to the Analytics servers

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>



</head>
<body>
    <p>
       TechPort Payment receipt for item</p>
</body>
</html>

在Google Analytics中设置我的帐户时,我已将默认网址设为主页面网址,以便www.MyDomainA.com。

并添加了2个不同的购物篮。

我看不到任何被跟踪的事件,任何人都可以看到我做错了什么?

我已在两个配置文件中将电子商务跟踪设置为true。

编辑:我很有可能因为我现在可以看到事件而感到不耐烦 - 我只是认为谷歌分析的事件部分是实时的......

1 个答案:

答案 0 :(得分:1)

你有多久了?有时需要几天的时间才能看到事件。在您的情况下,您似乎错过了电子商务跟踪开始时的_addTrans方法。

 _gaq.push(['_addTrans',      
      '1234',           // order ID - required
      'Womens Apparel', // affiliation or store name
      '28.28',          // total - required
      '1.29',           // tax
      '15.00',          // shipping
      'San Jose',       // city
      'California',     // state or province
      'USA'             // country
   ]);
   ...
   _gaq.push(['_addItem',...

   ...
   _gaq.push(['_trackTrans',...

此处的文档 - http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans