As I’ve previously written about, I’ve been having some trouble with PayPal PDT ( Payment Data Transfer ) and Google Analytics e-commerce tracking.
If you’ve added Analytics to your PayPal thank-you page, and used PDT to get the data to be sent to Analytics and got that working nicely then you will have discovered that not every sale gets tracked, because not every shopper can be guaranteed to land on your thank-you page.
Now I’ve been doing some testing on an idea to get around this using IPN. The basic premise is this.
- Google Analytics works through a request for __utm.gif from the Analytics server, to which is attached all the tracking information.
- On the page just before leaving for PayPal set the analytics script to local only.
- Use url rewriting to hide a script behind your local __utm.gif.
- Record all the details for the request for the local __utm.gif in a database, referenced to the session.
- Send the session ID information through PayPal’s custom variable.
- User finishes sale.
- IPN script picks up sale, checks session ID and looks up the stored request.
- IPN script rebuilds request and forwards to Google’s __utm.gif.
Now to test this before getting involved in databases and IPNs I just made two pages. One with Analytics set to remote, the next page with analytics set to local. Then I made a local __utm.gif just forward the request for the remote __utm.gif through a server side HTTP request.
Wait a day.
No joy, nothing showing up for the e-commerce tracking, or the visit to the second page, just the first page visits where the script was set to remote.
Then I fiddle for weeks trying to improve the request. Adding all the cookies etc. etc.
So I took a look at the urchin.js file to determine whether or not the local request was being built any differently to the remote one. And it was. If you have a look through urchin.js searching for the local/remote variable (forget the name of it right now) then you’ll see that there are extra things appended to the end of the querystring for the remote call to _utm.gif. The extra stuff is the content of all the analytics cookies.
So I fiddle urchin.js and made a local copy that built the same request for remote and local, including all the cookie data. I had a couple of people hit the two pages and a day later…
Success, there is e-commerce transaction data, items, totals, everything in Analytics now.
I used different sources and the like for a couple of test and those have also come through. Even more surprising though is that where I have had other people test the two pages for me, their locations have been tracked and assigned to the e-commerce transactions correctly. Which I didn’t expect as it’s always the web server making that request, and it’s not moving around!
So that’s something to work on. I’ll keep you updated on the next stage of implementation.