The developers of Google Website Optimizer have tried their hardest to make their product work in tandem with Google Analytics. Here at VKI, we have found that for the most part, they work great together. However, there are a few situations where GWO can interfere with GA or vice versa. Here is one such situation.
The Problem
There is a well-known problem when implementing an A-B test in Website Optimizer on a page that has Google Analytics installed. If you follow the instructions for installing the control script, and place it right at the top of the original page, you will lose referral information about how visitors got to the landing page. A detailed explanation of the problem and the solution can be found on Ophir Prusak’s blog.
This solution fixes all the referral information except for when visitors come in by a campaign from a search engine (for example AdWords). In this case, one little piece of information is lost: the search terms a visitor typed in to the search engine when they saw your campaign.
Here’s how it works:
- A visitor performs a search on the search engine
- A visitor clicks on your campaign-tagged link.
- They are taken to the original landing page
- The referral information is tracked as coming from the ad campaign. Also, the campaign terms value is set because the referring URL is the search engine, and it includes the search terms in the URL.
- The visitor is redirected by GWO to another version of the page, passing along the campaign parameters in the URL
- GA sees the campaign parameters and rewrites the campaign information. Because the browser now reports the referral as the original landing page, the search terms are not in the referral URL and the campaign terms information is lost!
Why would we care if the search terms are missing? Well, if you are using this well known filter, which appends the actual search terms to the broad match terms, then you may be missing some key information that makes the filter work.
The Solution
Here’s an easy and simple fix. Add the following code to all your variation pages (not the original) right before the call to _trackPageview().
The code checks to see if the previous page the visitor viewed has any campaign variables set in the query string (gclid, utm_campaign, utm_source etc). If campaign information exists, the code then compares the referring URL to the current URL. If they are the same, then we prevent GA from overwriting our campaign information.
So the full Google Analytics Tracking Code (GATC) will look like this
Voila, no lost information!
What’s _setCampaignTrack?
For those of you wondering what _setCampaignTrack function is and what the heck it does, here’s a brief overview. The function _setCampaignTrack enables or disables campaign tracking and stops the campaign cookie (__utmz) from being written or overwritten. All other information is recorded as usual. Normally, you wouldn’t want to disable this functionality. But sometimes – like in our case – we want to disable campaign tracking. The key thing for us is stopping GA from overwriting the campaign cookie that was set on the original landing page.