I am using the standard Google analytics snippet on pages to send info to google analytics.
For various reasons, my page is arrived at with a query parameter.
In an ideal world, this would not be the case but it is not a perfect world so instead I must avoid it being sent to google analytics as it contains personal information.
I have tried the following:
What was suggested here: , as follows: ((I am so sorry the formatting is really not playing ball D:)
_gaq.push(['_trackPageview', location.pathname ]);
(function(i, s, o, g, r, a, m) { i['GoogleAnalyticsObject']=r; i[r]=i[r]||function() { (i[r].q=i[r].q||[]).push(arguments) }, i[r].l=1*new Date(); a=s.createElement(o), m=s.getElementsByTagName(o)[0]; a.async=1; a.src=g; m.parentNode.insertBefore(a,m) })(window, document, 'script', '//www.google-analytics/analytics.js', 'ga'); ga('create', '@gaToken', 'auto'); ga('send', 'pageview', location.pathname);
I have been manually adding a query parameter to the url and using ObservePoint to check the content. The Content Information contains a Document Location URL of "http://localhost/my/url/page?uiop=qwert"... which appears to mean that the _gaq.push line isn't doing anything at all.
I tried digging into the function and manually changing the url, but it just resulted in an endless loop of page refreshing:
(function(i, s, o, g, r, a, m) { alert(i.location.href); var locn = i.location.href.indexOf("?") i.location.href = i.location.href.substring(0, locn) i['GoogleAnalyticsObject']=r; i[r]=i[r]||function() { (i[r].q=i[r].q||[]).push(arguments) }, i[r].l=1*new Date(); a=s.createElement(o), m=s.getElementsByTagName(o)[0]; a.async=1; a.src=g; m.parentNode.insertBefore(a,m)})(window, document, 'script', '//www.google-analytics/analytics.js', 'ga');ga('create', '@gaToken', 'auto');
I do not have access to Tag Manager, which I thought might be an option based on the following: /
Any suggestions would be very greatly appreciated, am rather at the end of my wits :(
(Apologies for the formatting, it was not co-operating :(
I am using the standard Google analytics snippet on pages to send info to google analytics.
For various reasons, my page is arrived at with a query parameter.
In an ideal world, this would not be the case but it is not a perfect world so instead I must avoid it being sent to google analytics as it contains personal information.
I have tried the following:
What was suggested here: https://stackoverflow./a/3669333/2295284, as follows: ((I am so sorry the formatting is really not playing ball D:)
_gaq.push(['_trackPageview', location.pathname ]);
(function(i, s, o, g, r, a, m) { i['GoogleAnalyticsObject']=r; i[r]=i[r]||function() { (i[r].q=i[r].q||[]).push(arguments) }, i[r].l=1*new Date(); a=s.createElement(o), m=s.getElementsByTagName(o)[0]; a.async=1; a.src=g; m.parentNode.insertBefore(a,m) })(window, document, 'script', '//www.google-analytics./analytics.js', 'ga'); ga('create', '@gaToken', 'auto'); ga('send', 'pageview', location.pathname);
I have been manually adding a query parameter to the url and using ObservePoint to check the content. The Content Information contains a Document Location URL of "http://localhost/my/url/page?uiop=qwert"... which appears to mean that the _gaq.push line isn't doing anything at all.
I tried digging into the function and manually changing the url, but it just resulted in an endless loop of page refreshing:
(function(i, s, o, g, r, a, m) { alert(i.location.href); var locn = i.location.href.indexOf("?") i.location.href = i.location.href.substring(0, locn) i['GoogleAnalyticsObject']=r; i[r]=i[r]||function() { (i[r].q=i[r].q||[]).push(arguments) }, i[r].l=1*new Date(); a=s.createElement(o), m=s.getElementsByTagName(o)[0]; a.async=1; a.src=g; m.parentNode.insertBefore(a,m)})(window, document, 'script', '//www.google-analytics./analytics.js', 'ga');ga('create', '@gaToken', 'auto');
I do not have access to Tag Manager, which I thought might be an option based on the following: http://www.lunametrics./blog/2015/04/17/strip-query-parameters-google-analytics/
Any suggestions would be very greatly appreciated, am rather at the end of my wits :(
(Apologies for the formatting, it was not co-operating :(
Share Improve this question edited May 23, 2017 at 11:46 CommunityBot 11 silver badge asked May 24, 2016 at 16:25 Froom2Froom2 1,2792 gold badges15 silver badges26 bronze badges 3- You can also leave the tracking code unchanged an remove the query strings via a filter within the GA view. – Eike Pierstorff Commented May 24, 2016 at 18:41
- Yes, but I need to prevent it going to GA in the first place because I don't have the ability to filter out our query string everywhere on ga. – Froom2 Commented May 25, 2016 at 8:35
- In that case @dorians answer is the correct one (it's even part of the official docs: developers.google./analytics/devguides/collection/…) and you need to figure out why it is not working. Is there a chance that maybe your debugger is playing tricks on you ? Try the GA debugger, or Google Tag Assistant. – Eike Pierstorff Commented May 25, 2016 at 8:40
2 Answers
Reset to default 7Your first option is the correct one, but the code you used is for a previous version of Google Analytics.
Instead, replace ga('send', 'pageview');
with ga('send', 'pageview', location.pathname);
See the page tracking documentation for reference.
You could try using Google Tag Manager: in the setup for the tag, there's an option called 'Fields to set', where you can manually edit any of the information that's being sent to Google Analytics (note that this happens locally, so would solve your data protection problem).
Here's an example where I've manually edited the 'Page field', which is what you need to do. In this case, I've chosen a pair of custom variables to feed in, but you'll probably need a custom JavaScript variable that takes the standard {{Page Path}} variable (which is what would be fed by default) and returns everything preceeding the first question mark.