For the third time in less than a month, some hooligan has stolen my Google Analytics tracking code! I checked my Google Analytics reports today, as I do frequently, to find an increase in traffic. At first, I was excited to see where this new traffic was coming from! There was a bunch of new referrals, maybe one of my articles got picked up somewhere and there was a bunch of referral traffic coming in.
Unfortunately that wasn’t the case. The increase in traffic was going to a bunch of landing pages that I knew were not part of my site, and being referred by a bunch of sites that wouldn’t be linking to me in the first place. I had seen this before (twice) and I knew immediately what was going on.
Someone had stolen my Google Analytics tracking code…again!
What likely happened was that someone saw one of my posts where I posted a code or markup intensive example, so they viewed the source of the page and copied everything. When they pasted the code onto their own website, they must have not noticed my Google Analytics tracking code was left behind, or they didn’t know any better.
It’s partially my fault though, as I didn’t have a filter set up to prevent this data from polluting my Google Analytics reports. I take the blame for that…
So today, I’d like to show you a really easy filter to implement that will prevent this from ever happening to you!
Setting Up The Google Analytics Filter
Log into your Google Analytics account, and click the Admin button, usually on the right side of the navigation bar.
Select the Account, Property, Profile that you want the filter to be applied to. Note that if you have multiple Properties and Profiles you may want to add the filter to many or all of them – it’s up to you.
Click on the Filters link in the Profile column.
Next, we’ll create our custom filter.
- Name the filter something memorable, I chose Exclude External but Prevent Tracking Code Theives would also be appropriate.
- Leave the Filter Type at it’s default of Predefined Filter.
- Set the next three drop-downs to Include only, traffic to the hostname, and that contain.
- In the Hostname field, enter your domain name – leaving out http:// and www. – just enter example.com (replacing example with your domain name). Don’t worry about subdomains.
- Save it!
Head over to the reporting side of Google Analytics and monitor your Real Time traffic for a few minutes to make sure that you are still tracking visitors. It would be tragic to accidentally set the filter to Exclude when you meant Include…so make sure that you set it up right!
Monitor your traffic over the next few days to make sure everything is normal, then you won’t have to worry about your tracking code being stolen ever again!