James Cooper
James Cooper

Reputation: 447

adding a variable to google analytics after .trackPageview?

I have a javascript in my page that I cannot edit for reasons I won't go into..

<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script>  
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._initData();
pageTracker._trackPageview();

What I want is to add the following variable onto/before the trackPageview(); is sent

pageTracker._setDomainName('mydomain.com');

Is there any way I can do this? If I do another ._trackPageview(); will it count twice?

Upvotes: 0

Views: 209

Answers (2)

Greg
Greg

Reputation: 781

Running _setDomainName after _trackPageview will change the domain hash portion of the cookies that Google Analytics uses for tracking. Once the domain hash changes, GA will recognize this as a new visit, and the visitor's source / medium will be reset to (direct) / none.

There's no way to accomplish what you want to do without altering the javascript that you say you can't edit. Once _trackPageview runs, the configuration settings (like domainName) are set in stone and cannot be modified without resetting the visit.

Upvotes: 1

CrayonViolent
CrayonViolent

Reputation: 32537

If you can't edit the page code then how do you plan on doing anything? Or are you saying that you just can't touch that specific code?

Unfortunately, there's nothing you can really do. You can add another _trackPageview after the _setDomainName but you are right, it will count the page twice. Alternatively you could use _trackEvent. That would trigger the code without triggering an extra page view, but it will send an event to GA. If you have other event tracking on your site, it could "muddy the waters" and make it more difficult to filter that out of reports, especially if you're already needing to apply other filters..

Also, setting the domain to something else in a 2nd hit may possibly mess with visit(or) metrics.

I agree with the comment Eike Pierstorff made: That version of GA code is very outdated and should be updated to the current version. Hopefully that might give you enough weight to get the code changed, and you can add the domain code in with the update.

Upvotes: 2

Related Questions