I’m testing Google Analytics Campaign tracking. I have the following JavaScript code on my local page triggered by an onclick event:
<script type="text/javascript">
function trackCampGoogle() {
try {
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
_gaq.push(['_setCampNameKey', 'ga_campaign']); // name
_gaq.push(['_setCampMediumKey', 'ga_medium']); // medium
_gaq.push(['_setCampSourceKey', 'ga_source']); // source
_gaq.push(['_setCampTermKey', 'ga_term']); // term/keyword
_gaq.push(['_setCampContentKey', 'ga_content']); // content
_gaq.push(['_setCampNOKey', 'ga_nooverride']); // don't override
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_trackPageview','CampTrackerGoogle']);
setTimeout('document.location = "' + link.href + '"', 100);
}catch(err){}
}
</script>
When I click the link in Chrome with the GA Debugger on, the tracking beacon fires, but doesn’t show campaign data being passed:
Campaign Count : 1
Campaign Source : (direct)
Campaign Medium : (none);
Campaign Name : (direct)
This is, uh, frustrating. What am I missing? We need the campaign data to be passed via JavaScript rather than in the URL.
You can use
_setto do this, before the_trackPageviewand_setDomainName.