I need to record a page view using analytics for a certain url with values of utm_source and utm_term which are sent from serverside.
I thought this would do the job:
<script>
var trackPageViewUrl = window.location.pathname +
"?utm_source={utm_source}&utm_term={utm_term}";
trackPageViewUrl = trackPageViewUrl.replace("{utm_source}", '<%= ServerSideVar1 %>')
.replace("{utm_term}", '<%= ServerSideVar2 %>');
// Tracking code
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-X']);
_gaq.push(['_trackPageview', trackPageViewUrl]);
(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>
No the problem is that I see pageviews from the url window.location.pathname but there are no values for utm_source and utm_term on which I could filter.
Thanks in advance.
Sadly, GA does not support this behavior, though it would be great. There are some hacks out there. See this question for some alternatives (including one that I proposed, the current accepted answer):
Track campaigns with Google Analytics without query string parameters?