I’ve been trying to find a solution for this but haven’t seen anything useful google’ing around. The issue might be that i’m using terminology that has other meanings.
I have a site that has utilizes the same URL’s for both guests and members. In order to track visits and goals correctly i need a way to tell if the visitor is a logged in user or a guest.
The easiest way i can think of is if i just prefix my URL’s with something like
/member/
I thought maybe i could do this in the google tracking code by adding this:
_gaq.push(['_trackPageview'], '/member' + window.location.pathname);
the full code is:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'xxxxxxxxxx']);
_gaq.push(['_trackPageview'], '/member' + window.location.pathname);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
However this isn’t working, also reading the google analytic docs, this seems to be a way to add an ‘additional’ page view.
I can update the servers code to prefix the urls with /member/ and then strip it before processing the path for the controllers, but i would rather not risk breaking a stable system thats about to go live.
Does anyone know how this can be done in JS before the normal URL is tracked?
Thanks,
Dan
You have a minor syntax error with your
_trackPageviewcall.It should just be this:
Note that the
/member+part is now within the array, not outside of it.What you were doing was passing the
_trackPageviewfunction name without a second parameter to be its argument (which, by default, tracks the pageview aslocation.pathname+location.search, and then passing a string /member+window.location.pathname to the array, which did nothing.Passing the custom URL as a 2nd item in an array will make it work just fine.