Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Using Google Analytics to track the same session in client javascript and server side tracking calls?

Ask Question

We are implementing a 3rd party payment system into our site (Barclays CPI). We want to use Google Analytics to track where paying customers came from eg; keywords, email campaigns etc. However, the Barclays CPI returns the payment authorisation result via a server-to-server http request, not a normal web page with google analytics code. This breaks the analytics chain, we lose the client cookie that identifies the visitor.

On the Barclays CPI confirmation screen the user can press a Continue button to return to our site, where we could put javascript tracking code in, but pressing the Continue button is optional . We need 100% accurate analytics stats for budgeting, planning and reporting purposes.

Server side tracking calls to the rescue?

I know that it is possible to make server side tracking calls, eg; http://www.diaryofaninja.com/projects/details/ga-dot-net , but I want to link the server side tracking calls to the same browser analytics session so we know where the paying customer has come from and can trace his path through the site prior to payment.

Is it a good idea take the value of all the google cookies just before the user went to the 3rd party site, and then somehow attach them to the server side analytics call so that the payment authorisation result is connected to the same browser session? Is this possible?

Thanks

Got this working. Using ga.aspx from the Google Analytics for mobile as a base you can store the original utma and utmz cookie values from the browser session and store them in a way you can retrieve outside of the browser. In my case, the order id. Then you need to make a __utm.gif image request to google to track outside of the browser. To keep the same analytics session details as the original user, get the stored utma and utmz values and put them in the utmcc parameter for the __utm.gif request. You'll need to url encode the values first eg;

url += "&utmcc=" + Uri.EscapeDataString( utma + utmz) 

Gareth, this is just an idea; I’ve not done this before.

But is it possible to pass a unique reference to Barclays, then before the redirect to them store the cookie information in the db.

Then when you get the request from Barclays, could you read the previously passed unique reference from the request, lookup the cookie values, then do a httpwebrequest to the google analytics gif, passing the cookie values.

http://www.google-analytics.com/__utm.gif //from http pages
https://ssl.google-analytics.com/__utm.gif //from https pages
    ?utmwv=1 //Urchin/Analytics version
&utmn=634440486
&utmcs=UTF-8 //document encoding
&utmsr=1440x900 //screen resolution
&utmsc=32-bit //color depth
&utmul=nl //user language
&utmje=1 //java enabled
&utmfl=9.0%20%20r28 //flash
&utmcr=1 //carriage return
&utmdt=Linklove » The optimum keyword density //document title
&utmhn=www.vdgraaf.info //document hostname
&utmr=http://www.google.nl/search?q=seo+optimal+keyword+density&sourceid=navclient-ff&ie=UTF-8&rlz=1B3GGGL_nlNL210NL211 //referer URL
&utmp=/the-optimum-keyword-density.html //document page URL
&utmac=UA-320536-6 //Google Analytics account
&utmcc= //cookie settings
    __utma=
                    21661308. //cookie number
                    1850772708. //number under 2147483647
                    1169320752. //time (20-01-2007) cookie first set
                    1172328503. //time (24-02-2007) cookie previous set
                    1172935717. //time (03-03-2007) today
    __utmb=
                    21661308;+ //cookie number
    __utmc=
                    21661308;+ //cookie number
    __utmz=
                    21661308. //cookie number
                    1172936273. //time (03-03-2007) today
        utmccn=(organic)| //utm_campaign
        utmcsr=google| //utm_source
        utmctr=seo+optimal+keyword+density| //utm_term
        utmcmd=organic;+ //utm_medium

The get request information is from here and here

Hi Steven great to hear from you. Thanks for your answer I was thinking along these lines. I'm just going to have to try it and take it from there (hopefully without raising a red flag against our analytics account!) We do create our own order id to which I can attach the cookie values before the barclays redirect, I want to pass the client ip address too in the hope that that will attach the server-side tracking data to the same client analytics session. I suspect some of the __utm values will need to be updated, it's a shame there isn't a solid google solution for this. – Typo Johnson Jan 10, 2012 at 9:32 Hey Gareth, good to hear from you to, the only other option I can think of is rather than use Barclays as the payment gateway, just use them for their merchant account and use a third party, like recurly/braintree. I believe they allow you to post the cc details directly to them then they process the payment and redirect back to your success page with customer token/name/address details. This would get round most of the PCI requirements (I'm assuming this is why your redirect to Barclays). Good luck! – WooHoo Jan 10, 2012 at 10:29

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.