In my previous post I discussed how an incorrect Default Page setting can cause a single page on your website to be counted as two different pages. That same concept is the driving force behind Common Google Analytics Configuration Mistake #2. If your website uses query string parameters you may be creating hundreds or thousands of unique page views which don’t actually exist.
Google Analytics creates a unique page view using the path name, the file name and any query string parameters present in the location bar of the browser. Remember, the query string parameters are all the junk after the question mark. GA strips the domain name from the URL and the remaining info becomes a unique page.
This URL:
http://www.mysite.com/dir/index.php?sess=1234&ocId=3&var1=foo&var2=bar
Results in this page view:
/dir/index.php?sess=1234&ocId=3&var1=foo&var2=bar
And this URL:
http://www.mysite.com/dir/index.php?sess=4567&ocId=6&var1=bar&var2=foo
Results in this page view:
/dir/index.php?sess=4567&ocId=6&var1=bar&var2=foo
Now, if the query string parameters passed between pages have no functional significance, i.e. they do not influence the content that is shown to the user, they should be ignored when GA creates a unique page view. Because the query string parameters do not offer any insight into what the visitor is doing, we want GA to track the above URLs as two views to a single page, not two views for two different pages.
The concept here is that the query string parameters do not tell us anything about the visitor’s actions. If your query string parameters describe what the visitor is doing then you do not want to remove them. Example, if one of your query string parameters is a product ID then you would not want to remove it. You want to know which products a visitor views during their session.
To force GA to skip certain query string parameters when processing we enter the unwanted parameters in the ‘Exclude URL Query Parameters:’ filed in the ‘Main Website Profile Information’ section.
Just enter a comma separated list of the parameters in the field I’ve outlined above. Here’s an example:
sess,ocId,var1,var2
If your site uses query string parameters to pass ANY information, I recommend you audit all query string parameters and identify which ones can be ignored. Here’s a tip, use the Top Content report to quickly identify the website query string parameters. When you pull up the Top Content report use the in-report-filter and enter \?
. This will immediately display all the records containing query string parameters.
Remember, this is going to affect other parts of Google Analytics. Once you add a query string parameter to the list, it will be completely ignored. It will not be listed in ANY of the GA reports. Also, when you exclude a query string parameter you no longer need match that variable when creating goals and funnels.
As usual, changing this setting will not affect the data that has already been processed by Google Analytics. Only data processed in the future will reflect this change.
Hi Justin,
With respect to query string variables, I noticed you made the following comment in an older post:
“Measuring internal site search with Google Analytics is possible. However, it depends on your website architecture. To track internal search terms with Google Analytics your internal search engine must pass the search term entered by the user in the query string. Google Analytics captures all of the data in the location bar of the browser, including the query string. If the search term is missing from the query string then GA will not be able to track it.”
What happened to the URI? I have a situation where search terms are not passed via the URL, but I wanted to pass them via the URI and then eventually see conversion data based on site search terms. I take it that the URI won’t be of any service for the Site Search tracking, but is there a way to extract the searched terms and put them in the User Defined variable, while still capturing all page views during a user session. I find that any filters that I write to capture the search terms will ultimately exclude other page views from the profile, thus I am at a bit of an impass.
Many thanks for any input!
Cheers,
Robert
Hi Robert,
Sorry for the confusion. The URI contains query string parameters. It sounds like you you need to create virtual pageviews using urchinTracker() (or pageTracker.trackPageview() ). When you use these functional you create a new Request URI which GA sees as a standard pageview.
You can create the pageview on the click of a button or when the search results page loads in the visitor’s browser.
Hope that helps,
Justin
I have been looking for an effective way to create a profile which ignores all query parameters. With the help of an Excel macro that I discovered (possibly on another post on this site?) I found that there were about 200 different query parameters across the different pages of the site. Rather than maintain a 200+ item list (which may change), I decided to use search and replace filters to change the recorded URIs. I initially tried to filter “\?.*” to “”, but GA will not accept an empty replace field (nor will it accept whitespace). To get around that I went to filters which looked like “aspx\?.*” filtered to “aspx”. That seems to work ok, but it requires multiple filters for different extensions. It doesn’t seem like a particularly elegant way to go about it, but I haven’t found any other ideas. It would be a simple fix in the javascript, but that would prevent any additional profiles from recording parameters which may be of interest. Any thoughts?
Hey Mike,
Good troubleshooting. Exactly the steps that I would follow. I would use an advanced filter that strips off all query string parameters. Remember, you can capture parts of the URL and then rewrite those parts out to a field. Try this reg ex:
(.*?)\?
Then put $A1 in the constructor.
You could tweak the JS and pass it an explicit value that does not include the query string parameters. I know all the data is available in the DOM, so you can use all JS, you don’t need to worry about using but would have to look it up.
Try the advanced filter.
Justin
This is a great post. Is there a way to batch ignore query string data? We have many campaigns tracked and they all start with the same string of characters “?code=”. If I enter that into the ignore field will it ignore all those that start with that string?
Thanks again for the post.
Hey Jon,
This setting, is in fact, a batch field. If you enter ‘code’ into the field then it will strip all instances of the query string parameter regardless of the value.
Hope that helps and thanks for the question!
Justin
I’m currently struggling and I hope someone can help me. What if your site uses “SEO Friendly” (aka “Static”) URIs?
For example, instead of:
http://www.domain.com/products.aspx?page=23
We use:
http://www.domain.com/products/23
I don’t want to see the page number (23) so how would I strip that out?
Thanks for any help!
Johnny,
In that case you can either leave the data or you would need to use an advanced filter to remove the 23 from the URL. The advanced filter would need to capture different parts of the URI and override the Request URI field. Here are the basic settings:
Field A: Request URI
Pattern A: (^/products/)
Constructor: Request URI
Output Patter: $A1
Make sure to test the above filter! Without know the exact format of your URLs it may not be right. But that should get you moving in the right direction.
Thanks for the question,
Justin
Hi Justin, thanks for your reply. I constructed an advanced filter in a different way using RegEx, and I think it will work fine.
(.*products)/(\d.*)$
Thanks!
(The Google Conversion University is excellent, too — I didn’t understand RegEx before their video!)
– Johnny
Interesting post, keep the good stuff coming, good content appreciated!
Thank you so much for including the bit at the end about edits only applying to future data! Exactly the question I was trying to answer. :D
I would like to be able to track the referrer.
For example:
http://www.example.com/examplepage.htm?ref=fb is a link I posted on facebook
http://www.example.com/examplepage.htm?ref=nl is a link from a newsletter I sent out.
I would like to be able to track where my visitors are coming from.
What would be the best strategy in such a scenario?
PS: Regarding my post above, I know I could use UTM tags, for xample:
http://www.example.com/examplepage.htm?utm_source=nl&utm_medium=e&utm_campaign=v%20
However, due to the non-commercial nature of my pages I would like to
a) keep the links short and
b) avoid the word “campaign”.
PPS: After more searching I found “Master Tracking Codes” and UTM_id, but it is not longer supported:
http://support.google.com/urchin45/bin/answer.py?hl=en&answer=2633697&topic=2633609&ctx=topic
Is there any way to do it with Google Analytics?
@Platini: You’re correct, you need to use utm_ campaign tracking parameters. You don’t need them all, you can just use utm_source. But why not use all of them for great data, then shorten the link with bit.ly or some other shortener?
Hi Justin,
Thanks for writing this post. Could you clarify the following about the “Exclude URL Query Param”:
1) Are the values entered into the field case-sensitive?
For example, “ocId” would be excluded but, “ocid” would not in the above URL
2) Can regular expressions be entered into the field?
For example, ocId1, ocId2, ocId3, ocId4, ocId5 could be simplified to “ocId\d”
@Alex:
1. I would suggest you use a lowercase filter to normalize the all of your URIs to lowercase. That will make your data more consistent. Then the case does not matter :)
2. No, you can not use a regular expression. You need to use a comma-separated list of all the parameters.
Hope that helps, Justin
Hi Justin,
Q1. Great advice!
Q2. That’s a shame. One for the feature request pile perhaps:)
Further investigation seems to indicate like the new GA version also has a character limit for the delimited string. Is this number documented anywhere?
And finally, when updating exclude query settings filters, how long after the changes are made will the rules be applied to the profile in terms of ‘real time’ and standard reports?
*Apologies for the Spanish Inquisition but, I’m trying to troubleshoot an issue and so your advice is much appreciated.