Our application has an issue with tracking google analytics requests. Internal links are not tracked in firefox unless the method that is used to send the request to google is called via a setTimeout. So I had this code working but have been away for a few months to find that a colleague completely changed the config file and removed the setTimeout call. Now when I put the code back in (with additional new variables) I get a js error in the browswer saying that callGA is not defined. Here is my code:
function trackPageview(id, countryCity, unique, bu, bg, areaClick, uri) {
setTimeout("callGA('" + id + "','" + countryCity + "','" + unique + "','" + bu + "','" + bg + "','" + areaClick + "','" + uri +"')", 1);
}
function callGA(id, countryCity, unique, bu, bg, areaClick, uri) {
_gaq.push([ '_setAccount', id ]);
_gaq.push([ '_setCustomVar', 1, 'Location', countryCity, 3 ]);
_gaq.push([ '_setCustomVar', 2, 'Unique', unique, 3 ]);
_gaq.push([ '_setCustomVar', 3, 'BU', bu, 3 ]);
_gaq.push([ '_setCustomVar', 4, 'BG', bg, 3 ]);
_gaq.push([ '_setCustomVar', 5, 'Portlet', areaClick, 3 ]);
if (uri) { _gaq.push([ '_trackPageview', uri ]); } else { _gaq.push([ '_trackPageview' ]); }
};
trackPageviews is being called in a number of locations. I have put an alert in here and its fine, the issue is on the setTimeout line.
Any help would be much appreciated.
Why not put the
callGAfunction inside the setTimeout?