info@adi.do0845 260 2343

Google Analytics with RBS WorldPay - Technical Blog

On the 25th November, WorldPay changed their system, no doubt for security reasons and not just to irritate the web community but doing so did cause a few problems.

Basically, they disabled javascript from running on their servers. There's a page, the NotificationURL, which you create on the web site's server but that is pulled through by WorldPay, some tags replaced and then rendered from their server. We used to put the GA code here but alas, this is no longer possible.

So... you need a workaround. Now personally, I would work around it by not using WorldPay at all but sometimes these decisions aren't ours to make. Our first step was to do what any self respecting developer would do -> Google it.

I found this article:

http://www.tatvic.com/blog/google-analytics-worldpay-ecommerce-tracking/

Its actually very good and we used it as the principle behind fixing the problem but our implementation was a little different.
Mainly:
1) They use forms to post variables whereas we build up a querystring and redirect
2) They use... ugh.... PHP! :) We use ASP.NET.

My advice would be to read the article above first, admire the pretty pictures, understand the principle, try not to feel queezy at the PHP code or the occasional poor English and then come back here to see how to do it in our world.

.....

.....

Welcome back.

OK so hopefully by now you get the idea. We're wanting to modify the last page before we go off to RBS WorldPay so that we push the GA cookies through the transaction process. Then on completion, we retrieve those cookies and send them back to Google to be tracked.

Step 1: Send the GA Cookies to World Pay

Put javascript like this at the bottom of the page before the user is taken to WorldPay's Payment Page.

<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
var save_url=pageTracker._getLinkerUrl("http://www.yourdomain.com/paymentComplete.aspx?key=value");
var aPosition = save_url.indexOf("&");
document.getElementById('<%=hfGoogleData.ClientID%>').value = save_url.substring(aPosition + 1);
</script>


Presumably you don't need telling that the UA-XXXXXXX-X needs to be replaced with your own Google Analytics Tracking number and that the domain name needs changing.

The _getLinkerUrl parameter is the URL of the page that the customer comes back to after being to WorldPay. Being that WorldPay doesn't auto-redirect the customer back to your website, you may not have had a page for this before so create paymentComplete.aspx. If you did have one already, just put the URL to that in here instead.

You may also need to change this line
var aPosition = save_url.indexOf("&");

The point of save_url is to have all of the GA cookies in the returned querystring. After you call __getLinkerUrl, it will be set to something like:
...sitedomain.com/paymentComplete.aspx?key=value&__utma=XXXX__utmb=XXX

In our case, we are already passing key=value so we're looking for the first & (highlighted) so that the substring only includes the GA stuff. If you don't have a querystring, you would search for ? instead, if you have multiple of your own querystring parameters, well then I'm afraid you need to write a little more javascript.

The other important thing in that javascript is:

document.getElementById('<%=hfGoogleData.ClientID%>').value = save_url.substring(aPosition + 1);

This is referring to a ASP.NET Hidden Field control that we've added to the page, just put this line somewhere near the javascript.

<asp:HiddenField ID="hfGoogleData" runat="server" />

All we have to do now is on the Submit to WorldPay button, grab the contents of that hidden field and pass it to WorldPay.

Thankfully WorldPay provide a useful feature whereby you can pass any custom variables and they will happily carry them and pass them back. You don't need to define them anywhere in WorldPay's system, the only criteria is that they start with MC_. This is our Submit to WorldPay button code.

Private Sub lnkPlaceOrder_Click(ByVal sender as Object, ByVal e as System.Web.UI.ImageClickEvent Args) Handles lnkPlaceOrder.Click
CreateOrder()
Response.Redirect(ConfigurationManager.AppSettings("WorldPayTargetUrl") & "&MC_analytics" & HttpUtility.UrlEncode(hfGoogleData.Value.ToString))
End Sub

The only really important detail here is that you must URL encode the value in the hidden field as it itself is a querystring and we want it to pass as one parameter not several.

Step 2: Get the Customer Back

The NotificationURL is the one that WorldPay pulls off your server and processes, its defined in your Production settings in your RBS WorldPay account. If you had GA code in there before, take it out, all you really need here is a button that reads something like "Click Here to Complete".
Herein lies the weakness of this implementation, if they don't click this button then you'll never get the customer to come back to the site and therefore will not get your tracking data!! So.. make the button look important!!

Key thing to remember here is to UrlDecode the returned (posted) parameter from WorldPay, for example:

<a href="http://www.yourdomain.com/paymentComplete.aspx?key=value&<%=HttpUtility.UrlDecode(Request.Form("MC_analytics"))%>">CLICK HERE TO COMPLETE</a>

Step 3: Track It

If you're fixing an old problem, your old code was probably in the NotificationURL page so you just need to move it here instead but here's an example of what should be on this page other than a nice message saying
"Thank you for coming back so we could track your every move, much appreciated!"
You may wish to alter the wording.

Step 4: Test It

Put an order through and then sit back, have a nap and wait to see whether your GA tracking ever comes through.

Hope you found this blog useful.

Happy coding.

Ross Coombes
Technical Director

Why web designers should think like Simon Cowell




(Photograph: Ken McKay/Rex Features - Guardian)

If you asked ten people to look at a website and say if they liked it or not, you'd probably get a wide variety of responses from 'Hate it' to 'That looks good!'.

What is one persons Jedward, is another persons Leona (it pains me to use an X factor comparison but hey). There are very few areas of the Internet which provoke such emotion and talking points as web design and how a website should (or perhaps shouldn't) look.

I've been in many meetings with MDs and marketing managers of companies telling us how their websites should look and how it should be one way or another. In a large majority of instances, it is the case that they know their markets better than anyone and therefore have the ideas on how their website should look to get the best results.

But in some cases recently, we have seen that what is perhaps viewed as a bad website or something which looks old, boring or out of date actually outperforms websites which are cared for and have much attention & money spent on them. Some people might look at a website and say the design is rubbish. It's fine to have an opinion but if the person making the comment isn't part of the target market, how much value should you put on their opinion? By the way when we say outperform, we are talking about online sales and/or online enquiries which in 99% of cases is the most important measurable, not visits or even worse 'hits'.

How do we know this? Website statistics. An often overlooked part of the web design and build process (especially in our experience for smaller digital agencies) is the analysis of statistics. They help us to understand what works from a traffic perspective and also from a user point of view. Whilst some packages such as Google Analytics do an amazing job of telling us what is going on at a top level, they still lack detail at the individual (but there are ways to find this out).

What Google Analytics, and in particular, Website Optimiser, allow us to do is test out our theories on the design side of things to see what works best for each client. What we believe to be the 'best' design often isn't the best for the market. What we prefer and assume will work best, often wont. Ideally we should let the public our target market decide for us.


(Image from Political Carnival)

The point I'm trying to make is that there is no 'best' design and you shouldn't be thinking there is. There are now many tools available which allow us to test and tweak versions of web pages to try and find the most profitable or successful version a page. We shouldn't be stuck with our own prejudices and accept them as being the best, we should let website visitors decide for us. Perhaps if more of us thought like Simon Cowell (heaven forbid!) and let our own audience decide for us, in the way the public votes for their favourite X factor contestant, our websites might get better results.

Comments? Leave them below...