简体   繁体   中英

Google Universal Analytics E-Commerce Tracking

So I've got the correct ecommerce tracking code for the new Google Universal Analytics, but I'm confused about how the variables populate? How do I get the correct item, price, category or number of items (for addItem) into this script? I've been looking all over the web, I don't think I'm seeing the full picture here.

<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('create', 'UA-44464798-1', 'safeway.com');
  ga('send', 'pageview');
  ga('require', 'ecommerce', 'ecommerce.js');

  ga('ecommerce:addTransaction', {
  'id': '200028184',                // Transaction ID. Required.
  'affiliation': 'Safeway',   // Affiliation or store name.
  'revenue': '11.99',              // Grand Total.
  'shipping': '5.00',               // Shipping.
  'tax': '1.00'                    // Tax.
});

  ga('ecommerce:addItem', {
  'id': '200028184',               // Transaction ID. Required.
  'name': 'Apples',   // Product name. Required.
  'sku': 'CVC2US',                  // SKU/code.
  'category': '',        // Category - you can put some category if we have such
  'price': '11.99',                // Unit price.
  'quantity': '1'                  // Quantity.
});

 // If there are additional items they should be added the same way. The sum of all    Items prices should match with the "revenue" data from above. 

  ga('ecommerce:send');  // 
</script>

I don't know what language your site is written in. Assuming its PHP or asp.net you will need to go in to the code that builds the site itself and add these tags as well.

So to answer your question, the variables and values are populated by you in the code behind of your site. Probably at the same time as when the user is checking out.

Instead of values in your script, you want to refer to the values of variables. These would get assigned by the shopping cart code at the moment of purchase completion.

The Google documentation has a PHP example. Analytics JS Ecommerce Dev Notes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM