PayPal E-commerce Tracking with Google Analytics

Updated post: http://www.teknohippy.net/2008/03/04/paypal-ipn-pdt-analytics-tracking-getting-there/

Trying to track E-commerce transactions with Google Analytics (GA) and PayPal can be problematic.

PayPal has two ways of returning data to your server. Payment Data Transfer (PDT) and Instant Payment Notification (IPN).

PDT can be used to setup GA tracking by including the relevant GA scripts on a receipt page, processing the PDT data server-side and populating those scripts. Instruct PayPal that this page is your “return” page and when visitors return to it the e-commerce and goal data will be tracked.

The big problem with this is that PayPal users do not have to return to the receipt page, even if you’ve turned on the auto return feature. The pause before redirecting is very long and many people just abandon on the PayPal pages.

IPN on the other hand will always get triggered. The problem is it calls a script on your server from PayPal’s server-side scripts. This means your IPN script never runs in the users browser and so the GA JavaScript is never executed and no tracking will happen.

Now at it’s heart all the GA script really does is assemble a call to an image on the GA servers, __utm.gif to be more specific. Appended to this request is a lengthy querystring with all the information for Analytics to log.

It should therefore be possible to capture users info or the actual __utm.gif querystring on the page just before leaving for PayPal, temporarily store this in a database against the users SessionID, and pass the SessionID to PayPal as a custom pass-through variable.

The easiest way to collect the querystring from the pre-PayPal page is to set “_userv = 2;” in the tracking code. This means that __utm.gif will be requested from both the Analytics server and your server. Trap the call to _utm.gif with some server-side script and you’ve got the whole querystring very easily, as well as the corresponding SessionID.

The user is now off to PayPal to complete their transaction.

Then in your IPN script, lookup the SessionID and recover the __utm.gif querystring, change the utmp path variable for the path of the reciept page and then use your server-side script to make an http request to __utm.gif.

This will then at least track and goal reporting will work. The IP address will be wrong but the rest of the data will be correct.

More complex is building the querystring for the  __utmSetTrans() call. I’ve had a look into what’s sent and a separate call is made to __utm.gif for the transaction and each item within it.

I suppose it would be possible to set _userv to 0 and only have a local __utm.gif request on the checkout page. Then the Ecommerce tracking data could also be included. All the script hiding behind the local __utm.gif needs to do is record all requests when visitors hit the checkout page. It can pass on the actualy request for the tracking (but not the transaction), when it happens. Then in the IPN script the tracking request path can be rewritten and replayed, followed by the transaction requests. Sounds like it should work.

I guess I should go make it happen and test it!

9 Responses to “PayPal E-commerce Tracking with Google Analytics”

  1. I’m now in the process of tesing this. Waiting to see if results appear in Analytics reports.

  2. When your browser requests the __utm.gif image, it is sending an HTTP request that also contains header information such as cookies. I haven’t looked into this yet, but I’m guessing that GA will use information from those cookies.

  3. My next thing to try, simply requesting the gif was not enough, thanks for the heads up. I’m now working on duplicating the complete request as easily as possible.

  4. I’m getting nowhere with this. I’ve replicated the whole of the request before forwarding it onwards to the google __utm.gif. So that’s all the cookies, and any other headers, all looped through and copied over. Still nothing turns up in analytics the next day. :(

  5. Hi Guys,

    I’ve been trying to integrate GA E-commerce tracking with Paypal for a few weeks now. There doesn’t seem to be a lot of info out there on the subject.

    After a few weeks and a few hundred dollars, I’ve come up with a script that fully integrates Paypal with GA E-commerce. I’ve wrote a free ebook that includes the script you’ll need at no cost.

    There is nothing for sell here. I just wanted to see this info more widely available.

    You can get the ebook from this link.

    http://www.brentcrouch.com/2008/03/02/google-analytics-e-commerce-tracking-using-paypal-pdt/

    Good Luck,

    Brent Crouch

  6. Thanks for that Brett, a nice step by step guide for those that are also feeling lost. If you’ve just done the whole PDT thing then you’ll soon be running into the problem described in the main post.

  7. [...] I’ve previoulsy written about, I’ve been having some trouble with PayPal PDT ( Payment Data Transfer ) and Google Analytics [...]

  8. [...] I’ve previously written about, I’ve been having some trouble with PayPal PDT ( Payment Data Transfer ) and Google Analytics [...]

  9. flashbooter…

    [...]PayPal E-commerce Tracking with Google Analytics | teknohippy.net[...]…

Leave a Reply

Taglines? Where were going we don't need, taglines.