문제

I'm migrating my Google Analytics from Traditional to Asynchronous tracking. I now have my general scripts located as the documentation details just before the closing tag.

Like this ...

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXXXX-1']);
  _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>

Later in the page, "near" the closing BODY tag -- I programmatically push the "_addTrans", "_addItme", and "_trackTrans" methods in the methods array. Like this ...

    <script type="text/javascript">
        try {
                _gaq.push(['_trackPageview', '/checkout/order_confirmation.aspx']);
                _gaq.push(['_addTrans',
                  '1234',           // order ID - required
                  'Mountain View',  // affiliation or store name
                  '11.99',          // total - required
                  '1.29',           // tax
                  '5',              // shipping
                  'San Jose',       // city
                  'California',     // state or province
                  'USA'             // country
                ]);
                _gaq.push(['_addItem',
                  '1234',           // order ID - required
                  'DD44',           // SKU/code
                  'T-Shirt',        // product name
                  'Green Medium',   // category or variation
                  '11.99',          // unit price - required
                  '1'               // quantity - required
                ]);
                _gaq.push(['_trackTrans']);

        } catch (err) { }
    </script>

Is this permissible? Since they are not together as detail in the API docs, will my Ecommerce tracking still work?

Thanks

도움이 되었습니까?

해결책

It works. It doesn't need to be in the same tag. You should notice that the call to _setAccount still has to be the first one run. And in your example you're firing 2 pageviews. The first one uses the default document.location.href and the other uses a custom/virtual pageview. That may not be exactly what you want, you should have a single pageview per page.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top