If you have a website and it runs well, your next priority should be to make sure your analytics setup is sound. This was a challenge I just had to conquer myself and sometimes it isn’t as easy as it seems like it should be. Here’s my tale…
Setting up Google Analytics in Magento Enterprise
Configuring Google Analytics in Magento couldn’t be easier. There’s a config page, you put in your profile number, activate it and then you’re done. Except in my case we weren’t.
We have a bit of a unique setup. We have a sub-domain that we need to track as well and for us, there’s no need to have the data separated into a separate profile because the sub-domain is only used for the cart. We have the main
http://www. sub-domain as well as the
What is a self referral?
It’s pretty simple. When your visitor traffic is properly tracking source by source but you also have traffic and conversions tracking under the same domain name as what you’re trying to track. Because the only different sub-domain we have is in our cart, this meant that only our conversion data was wrong. Fortunately (or so I thought), Google provides special code to use when you need to track sub-domains.
Google’s Recommended Code for Sub-Domains
This is the code that Google recommends you use when tracking a site that has one or more sub-domains.
This is the newest asynchronous Google Analytics tracking code. The only part that’s different from the standard install is
_gaq.push(['_setDomainName', 'domain.com']);. However, in Magento, there’s no way to define that variable without modifying core PHP files. But that’s exactly what we had to do to get that setup properly.
After this was installed and we verified that it was rendering properly on both sub-domains, we waited a day and reviewed our Google Analytics account. Still, this didn’t fix our problem. We were still tracking self referrals and there was no change at all.
At this point, I went back to the drawing board which pretty much means that I went back to Google searches.
I found a few other forum threads talking about another snippet that could be added that will help fix these issues. That’s when I decided that Google’s recommendation for code was going out the window.
This is what worked for me. If you’re facing similar problems with self referrals, I hope it works for you too. However, the only real way to get things working is trial and error. Trial and error never fails forever.
The addition is
Honestly, that’s all it took. It all seems simple now but at the time it was incredibly frustrating. As soon as the code went live and I inspected the GET requests for
__utm.gif I knew that it was working properly and the problem had been solved.
Verifying Referral Data in Firebug/Chrome
Click on the GET request for
__utm.gif and then you’ll get the detail for that request. Pay special attention to the section under “Query String Parameters”, specifically the parameter called
utmcc. That parameter is what recalls the tracking data stored in cookies. Here’s the value from that parameter:
Within that value, check out the parameter
utmcsr, which is equal to the referral source. When you’re evaluating this on your own domain it’s important to look at this on the first page you visit when transitioning from one sub-domain to the other. That’s where the cookie information will get all screwed up. If the referrer is equal to your domain, then you still have a problem. If it is equal to the original referrer like direct, organic, etc, then you’ve solved the problem.
If I’m being honest I still do not understand why the Google Analytics code that’s recommended by Google in my account wasn’t enough. It’s really frustrating. If anyone has additional insight I’d love to understand.
I hope this has been informative. Please leave a comment if you have a question and I’ll do my best to answer or provide ideas.