Reputation: 487
so the code I have is very basic and looks like this...
jQuery(document).ajaxSuccess(function(e, xhr, opt){
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'xxxx']);
_gaq.push(['_trackPageview', '/goal1']);
});
I have this in my footer
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'xxxx']);
_gaq.push(['_trackPageview']);
(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);
})();
And yet it does not work, any suggestions on how i could get this to work is appreciated, also I did a alert to make sure the ajax success works and it worked so i am 100% positive it should work.
Upvotes: 0
Views: 298
Reputation: 44629
you'll have to write it this way
var _gaq = window._gaq || [];
Else, _gaq is undefined at this point because of variable Hoisting in Javascript.
Upvotes: 2
Reputation: 350
Eliminate these 2 lines:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'xxxx']);
They're clearing the analytics object. You should just have the push in the success handler.
Upvotes: 0