Google Analytics E-Commerce Tracking Using Paypal PDT

I've changed my mind. In a previous post I was a little critical about Google Analytics. After using it for a while, I believe the good outweighs the bad. "Oh Google Analytics...How have I lived so long without you"?

One of the best features of Analytics is the E-Commerce tracking. With this feature enabled, you can literally track which visitors make a purchase, how much they spent, where they came from, how many times they visited your site, and what actions led up to making that purchase. The feature is great! Getting it setup and working......not so great.

I was surprised to find very little information on setting up E-Commerce tracking for sites that use Paypal. After beating my head against the wall for a few weeks and spending a few hundred dollars, I finally came up with a script that worked. Rather than package and sell my solution, I've decided to give it away in an ebook I wrote.

Grammar and spellun ain't my thang, so if you notice some typos in the book, please spare me the embarrassment and let me know. You can download a copy of the ebook from this link.

You can give the e-book away if you like as long as the content remains unchanged.


If you enjoyed this post, make sure you subscribe to my RSS feed!



Tags: , , ,

18 Responses to “Google Analytics E-Commerce Tracking Using Paypal PDT”

  1. Frank Bruno Says:

    Hey thanks Brent I’ll take a look. Thanks for posting this!

    Frank Bruno

  2. Judith Tramayne Says:

    Thanks Brent! I’ve downloaded your PDF and look forward to reading it.


  3. Iain Says:

    Nice PDF, lays it all out step by step.

    If you’ve just got PDT working on your thankyou page then you’ll soon run into the problem where you find that Analytics is not recording all your sales, because all your visitors are not guaranteed to hit the thank you page.

    I’ve managed to make some headway with this problem and have successfully got server side code to send conversion data to analytics. My next step is to integrate this into a IPN script.

    Extensive ramblings and info can be found on these blog posts.

  4. Rostyslav Says:

    Thanks. Good info.
    I have been searching already how to track Google Analytics with other eCart provider.

  5. Luc @ Pure Web Analytics Says:

    Thanks for posting your article on my website. Gotta love Google Analytics

  6. Poster Maniac Says:

    This is indeed a helpful e-book as it is indeed hard for me to track google analytics before but your share of information is indeed great. I am planning of sharing this information with some friends and they would surely be glad about it.

  7. Janni Says:

    thanks Brend for the exellent step by step analysis of your pdf.

  8. Tampa SEO Says:

    Great e-book. Saved me hours of testing myself. Thanks for sharing!

  9. Brent Crouch Says:

    Glad it worked for you Tampa SEO.

  10. Dale Says:

    Hi Brent, does this work for PayPal’s add to cart buttons as well or just the buy now buttons? Thanks Dale

  11. Brent Crouch Says:

    @Dale – I’m not sure. I’ve never messed around with the add to cart buttons. If you can use the PDT with a cart button, I suspect it would work fine.

  12. Tommy Says:

    Many thanks Brent.
    You probably saved me quite a few hours.

  13. Tommy Says:

    Hi Brent.
    I’ve been using your method for a few days now but there are a couple of problems which prevent the tracking from taking place.
    1st off, since I’m not a cgi programmer (I’m a php man) I didn’t know how to fully implement the script correctly. Luckily I found this article which put some order into things for me –
    I’m sure other readers could benefit from it, and maybe you’ll put this information in your ebook (which I think is really great btw).
    2nd problem this entire method doesn’t cover is that with PDT, after the purchase the buyer will get a screen – still within PayPal – that says the transaction is complete and please wait 5 seconds to be transferred to the site. If they don’t wait 5 seconds and either close the window, or simply click away to another site then the cgi script is never called, and GA will not get the information on the purchase.
    PayPal’s IPN notifies the site of a purchase, but doesn’t trigger javascript, so it still doesn’t notify GA of the purchase.
    Did you manage to come up with a solution for this one?

  14. Brent Crouch Says:

    No I haven’t. There are instances that you point out in which the script will not work. Using the IPN would be the fail safe method, I just don’t know of anyway to make that work due to the issue you mentioned.

  15. Brent Crouch Says:

    Great Tommy. Thanks for the feedback.

  16. Rebel SEO Says:

    Your code seems to be written for a circumstance where there is only one item being purchased. That’s why you have mc_gross for both the transaction total and the item price variable. So this will not work for add to cart, where there is more than one item.
    I’m working in php, so its going to be a bit different, but what you need to do (I think) is create an iteration by wrapping the pageTracker._addItem section with some looping code.
    My hunch is that you can use PayPal’s num_cart_items variable to achieve this.
    while ($i<=$num_cart_items);
    …or something like that. I'll return to left yall know if it works. Thanks for the ebook.

  17. Jon Says:

    Thank you for your generosity!!

  18. Jon Says:

    Hey I wondered if anybody knows a good tutorials on setting up ecommerce tracking for a 3rd party? (ecommerce template)

Leave a Reply