Max
Max

Reputation: 841

Google Analytics Ecommerce Tracking Not Working As Expected with PayPal

Whenever a customer buys a product from my site via PayPal, I'm redirecting him back to download the product.

I'd like to push that transaction in Analytics, but it doesn't work as expected.

PayPal redirects him back with a few $_GET variables: transaction ID (tx), amount paid (amt).

 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', '[MY_CODE_HERE]']);
 _gaq.push(['_setAllowLinker', true]);
 _gaq.push(['_trackPageview']);

 _gaq.push(['_addTrans',
 '<?php echo $_GET['tx']; ?>',                         // transaction ID - required
 '<?php echo $_GET['amt']; ?>',                        // total - required
 '0',                                                  // tax
 '0'                                                   // shipping
 ]);
 _gaq.push(['_addItem',
 '<?php echo $_GET['tx']; ?>',                         // transaction ID - required
 'SKU here',                                           // SKU/code - required
 'Product here',                                       // product name
 '<?php echo $_GET['amt']; ?>',                        // unit price - required
 '1'                                                   // quantity - required
 ]);
 _gaq.push(['_trackTrans']);

 (function() {
 // the remaining here.
 })();

$_GET['tx'] and $_GET['amt'] are working correctly, but the transaction isn't showing in Analytics.

The profile is set as an Ecommerce site. I can view transactions from a different payment processor, FastSpring.

The transaction from PayPal doesn't appear in Analytics at all.

Upvotes: 1

Views: 635

Answers (1)

Max
Max

Reputation: 841

_addTrans and _addItem must have all settings, including those optional with simply ''.

 _gaq.push(['_addTrans',
 '<?php echo $_GET['tx']; ?>',                         // transaction ID - required
 '',                                                   // affiliation or store name
 '<?php echo $_GET['amt']; ?>',                        // total - required
 '0',                                                  // tax
 '0',                                                  // shipping
 '',                                                   // city
 '',                                                   // state or province
 ''                                                    // country
 ]);
 _gaq.push(['_addItem',
 '<?php echo $_GET['tx']; ?>',                         // transaction ID - required
 'SKU here',                                           // SKU/code - required
 'Product here',                                       // product name
 '',                                                   // category or variation
 '<?php echo $_GET['amt']; ?>',                        // unit price - required
 '1'                                                   // quantity - required
 ]);

I suggest using GA Debug, a Chrome extension, for debugging.

Upvotes: 2

Related Questions