iFinity Blogs 

Maintaining your Google Analytics Tracking through redirects

by Bruce Chapman on Friday, October 28, 2011 7:02 PM

A very useful feature of Google Analytics is the ability to track different urls for the same thing by including items such as campaign, source, medium, keyword and ad version.  This allows you to host links in different locations and then determine which is the most successful location, ad version, or combination.

This gives you extra information in your Analytics page, like this:


Above : Detailed Medium + Campaign information shown in Google Analytics from Url tracking codes

However, sometimes during the process of redirecting, this detail gets lost, and as a result Google Analytics loses the information, and can’t provide accurate reports.  This also affects the use of AdWords.

With the Url Master module, the redirection sometimes occurs because another part of the Url triggers a redirect action.  This could be because it has the wrong domain name, the wrong case, or maybe it has a TabId parameter included in it.

Because of the way the module works, it attempts to discern which parts of a raw Url is part of a querystring, and which part is part of a friendly Url path.  In DotNetNuke, a raw Url looks something like http://example.com/default.aspx?tabid=165&key=value.  If this were redirected using the Url Master module, you’d end up with http://example.com/page-name/key/value.aspx – which is most likely correct.

However, if you include analytics tracking information in the Url, then the Url Master module tends to not know where the tracking codes start and the rest of the path ends.  And so you might end up with a Url that looks like this:


Which isn’t correct, because the analytics code looks specifically at the querystring of the Url for the tracking information, and it’s been moved into the main path of the Url.

What the above Url should look like is this:


If you have the above problem, you’ll probably find out because expected analytics tracking isn’t working, and you’re getting discrepancies between your data.

NOTE: The Google Analytics Url Builder Tool is a good way to build these Urls quickly.

The Url Master ‘doNotIncludeInPathRegex’ Filter is the Solution

There is a regex field in the Url Master module which handles this situation.  What this regex pattern does is identify key/value pairs that shouldn’t be in the path, and moves them to the querystring.  So, in this case, all you need to do is identify the utm_ parts, and the inbuilt logic will shuffle them to a querystring value.

The one caveat is that you have to identify all of the path – not just the ‘key’ – you need to capture the /key/value pair.

For the above url with Google tracking codes, you could just write a matching pattern like this:


This would match both the key - /utm_source and the value /[^/']+

Small Regex tutorial – the [a] pattern matches any ‘a’ character.   So [/] matches any / in some text.  The ^ pattern is a NOT operator. So [^/'] matches anything that is NOT /.  And the + character following means ‘match 1 or more times’.  So [^/]+ means ‘match 1 or more characters you find that aren’t a ‘/’.  And that’s how you match any value that follows utm_source.  See, regex isn’t that hard, is it?

However, there is one small problem with the above pattern is that it (1) presumes the source/keyword/campaign values will always be in the correct order, and that there won’t be any other utm_ values.  In fact there are 5 possible utm_ keys – including term, medium, keyword and content.

So what we need is a more generic function that will make sure NO Google Analytics tracking segments are matched and included in a Url path.  And that’s our solution regex:


Anyone who was paying attention in the first Regex tutorial will know that this says match anything starting with /utmxxxxx and the value following that, and match as many of those as you can find, as long as they are all grouped together.

At this point, you need to go to your Host->Friendly Url Settings page, navigate to the Regex Settings tab, scroll down to the ‘doNotIncludeInPathRegex’ field, and copy and paste that value in.

Apply the changes, and you should have fixed your problem!

This information is also posted on the Url Master Knowledge Base.

A Note about the DotNetNuke Blog Module

If you’re thinking about tracking your Blog entries from your DotNetNuke hosted blog, you’ll come into a little bit of trouble.

The DotNetNuke Blog module has a feature where by it will enforce the ‘Permalink’ Url (which is just the canonical Url of a post) by comparing it to the requested Url for an entry, and if they are different, it will 301 redirect away from the requested Url to the stored Permalink Url.  Which is great, because it means that you won’t get any duplicate content problems caused by different blog posts being linked with different Urls.

But the Blog authors didn’t foresee a world where everyone had utmsource=my+blog+campaign stuck on the back of the Urls, and it will detect a tracked blog entry as incorrect, and redirect away.  And because the tracking in Google Analytics is done by javascript once the page is loaded, you’ll lose the extra utm_ parameters on the querystring, and your tracking will not work.

I’ve rolled my own solution on this blog, which just means cracking open the source code and adding a little change to compare the Urls sans querystring.  I’ll monitor this for a while, and if it’s working OK will see if I can get it included in the next Blog release.  But if you’re trying to track your blog entries using Analytics with unique tracking codes, you’ll find that it isn’t working.

Sound Interesting?

I’m doing an entire session on Tracking Social Media Campaigns for Effectiveness at the upcoming DotNetNuke World conference.  Why not come along and learn more information like this?

Do you know of any more problems with tracking Urls in DotNetNuke via Analytics?

Let me know via the comments and I’ll ferret out an answer for you!

Blogs Parent Separator Crafty Code
Bruce Chapman

The craft of writing code. The outcomes from being crafty with code. Crafty Code is tales from the coding bench.

2 comment(s) so far...

moorecreative 11/13/2013

As always, stellar write up and advice Bruce, thanks! I'm having troube with a DNN6 site runing iFinity URL, and a month or so back, I read through this information, went into the host level Freindly URL Settings and put in the regex to allow for a particular Google Adwords tracking value of (/GClid[^/]+/[^/]+)+ this solved the problem for all internal pages of the site so that urls would now work such as /ParentPage/Overview?GClid=Test123 with the query string still in place. the home page, though doesn't it still converts it to /Home/GClid/123 now, on the home page, i have several redirect rules specifically to take alternate page names like these Home, Default.aspx, home, Default, default, index and direct them all 301 over to just the slash / is that interfering here? and what's a workaround that you would recommend testing? is this a good place for using the "Post Process Friendly URL" feature? (i'll admit that i haven't thought of a use for me for that feature till now)

Bruce Chapman 11/13/2013

I believe the bug with the regex not working on the home page was a bug that was fixed at some point. Perhaps try upgrading to the latest version of the module and see if that fixes the problem.

Bruce Chapman
Hi, I'm Bruce Chapman, and this is my blog. You'll find lots of information here - my thoughts about business and the internet, technical information, things I'm working on and the odd strange post or two.
Connect with Bruce Chapman on Google+

Share this page
Get more!
Subscribe to the Mailing List
Email Address:
First Name:
Last Name:
You will be sent a confirmation upon subscription

Follow me on Twitter
Stack Exchange
profile for Bruce Chapman at Stack Overflow, Q&A for professional and enthusiast programmers
Klout Profile

Page Tags