0
votes

I am trying to track eCommerce transactions using google analytics ecommerce tracking...

<?php
$tx_token = '234234234';
$amount = '19.99';
?>

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-12345678-1']);
  _gaq.push(['_trackPageview']);

  _gaq.push(['_addTrans',
    '<?php echo $tx_token; ?>',  // Transaction ID
    'My Store',             // Affiliation or store name
    '<?php echo $amount; ?>',    // Total
  ]);

  _gaq.push(['_addItem',
    'D1D44',
    'My Item',
    'Category / Variation',
    '<?php echo $amount; ?>',
    '1'
  ]);

  _gaq.push(['_trackTrans']);

  (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>

Should this be enough? Do I need the $tx_token value in addItem as well as addTrans?

1

1 Answers

0
votes

Yes, you need the transaction id for each item in the transaction (that's how Google Analytics can tell that the items belong to a transaction). So the transaction id is the required first parameter for each addItem call. Actually that is described quite thoroughly in the GA documentation (Ecommerce Tracking with ga.js).