Exclude filter in analytics for WordPress post/page previews
I’ve never had to really create an exclude filter within Google analytics before, never had the need to exclude pages/queries from sites i’ve worked on. However i always need to preview my posts, allows me the opportunity to take another scan over for basic errors and to tweak images (perfectionist at heart).
I’ve hard coded my tracking script into the footer of my wordpress theme, so previewing posts is always tracked within the analytics. No point in creating a custom exclude filter for my home and office ADSL line, as the IP address always changes as well. So the other solution would be just to exclude all “preview=true” URI’s from being tracked, to help having to see my previews in my top content pages breakdown in analytics.
It’s an extremely easy task to do. Simply sign in to your Google Analytics account and edit your blog analytics profile and select the option to “add filter“. You will need to use the custom filter option as seen below:
Once you’re done, you need to select the type of filter you are wanting to create, we are looking to create an exclude filter, so make sure you have the “exclude” option checked. Now you will need to change the “filter field“, which defaults to “visitor geographical domain“, to “Request URI” towards the top of the dropdown (dropup? ). URI meaning everything after the domain name, very different to URL.
Next, you’ll need to add your pattern. As this works in a similar manner to the head match option when creating goals in analytics, you will only need to add the common “pattern” that will appear in URI’s that you do not wish to track. Simply add your “preview=true” for the filter pattern, don’t forget to name your custom filter, then save. You are all done.
And you’re done! Remember this will only affect any new data tracked going forward and does take some time before you will see updated data within your analytics profile. As a side note, be very careful that the “preview=true” function is not used somewhere else within wordpress legitimately, as you may very well want to track that data.
Sometimes it’s best to tweak and customise yourself, than having to really on plugins to easily solve a need/problem. Hope this little tid bit of info may help some of you.