Reputation: 8527
I want to call the following code from my pages, and sometimes pass a PageName parameter.
function _ga(PageName) {
_gaq = [['_setAccount', 'UA-00000000-0'], ['_setDetectFlash', false], ['_trackPageview', PageName]];//global variable
var d = document,
t = 'script',
g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = 'https://ssl.google-analytics.com/ga.js';
s.parentNode.insertBefore(g, s);
}
What will happen if the PageName variable is undefined
? Would Analytics interpret it as ['_trackPageview']
.
I cannot test it live, but as far as i can see nothing crashes when the variable is undefined
.
I can add extra code if Analytics does not accept undefined
.
Upvotes: 0
Views: 323
Reputation: 22832
Yes. The following 3 calls are equivalent.
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageview', undefined]);
_gaq.push(['_trackPageview', '']);
You can easily test this by executing the 3 calls in any site that uses Google Analytics (Including Stack Exchange) and then examining the gif requests on the network panel.
You will notice that all the calls will use the current url by default by examining the utmp parameter of the gif request.
Upvotes: 1