According to Google Analytics our account is receiving data. I uploaded to our Alpha site here on Monday and so far I can only see 1 visit on the 19th and nothing for the rest of the week, I had people from other offices and other states visit the site :(
Curious if you may see something obviously wrong with the code below: Everything looks good, even the Search term tracking works (consoles out the term)
//GOOGLE ANALYTICS
//======================================================================
WHOAT.analytics = (function ($, w, undefined) {
'use strict';
//initial google setup
var _gaq = _gaq || [];
_gaq.lang = 'en';
_gaq.push(['_setAccount', 'UA-xxxxx-x']);
_gaq.push(['_setDomainName', 'whoat.net']);
_gaq.push(['_setAllowLinker', false]);
_gaq.push(['_gat._anonymizeIp']);
_gaq.push(['_trackPageview']);
// console.log('inside Analytics');
console.log(_gaq);
function init() {
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript';
var s = document.getElementsByTagName('script')[0];
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
s.parentNode.insertBefore(ga, s);
console.log(ga);
}());
}
//TRACK PAGE VIEWS
var trackPageView = function (url) {
//get the url from the pathname if it wasn't passed in
if (url === null || url === undefined) {
url = w.location.pathname;
}
//if an id is part of the url, replace the id with 'details'
url = url.replace(new RegExp(/\/[0-9]+$/), '/details');
_gaq.push(['_trackPageview', url]);
console.log('analytics trackPageView: '+url);
};
//TRACK SEARCH EVENT
var trackSearchEvent = function (searchTerm) {
var url = w.location.pathname;
url = url.replace(new RegExp(/\/[0-9]+$/), '/details');
_gaq.push(['_trackEvent', 'search', searchTerm, 'url for search is ' + url]);
console.log('analytics trackSearchEvent: '+searchTerm);
};
//TRACK VIDEO EVENT
var trackVideoEvent = function (event, videoID, time) {
var label;
if (time !== null && time !== undefined) {
label = 'video id is ' + videoID + " and time is " + time;
} else {
label = 'video id is ' + videoID;
}
_gaq.push(['_trackEvent', 'video', event, label]);
};
//track the page just landed on
trackPageView();
return {
trackPageView: trackPageView,
trackSearchEvent : trackSearchEvent,
trackVideoEvent : trackVideoEvent,
init : init
};
}(jQuery, window));
$(document).ready(function () {
WHOAT.analytics.init();
}); // document ready
Our Alpha site here: http://neytiri.whoat.net/
The console.logs read out, and no errors (besides the vimeo one)
I needed to move the var _gaq = _gaq || [];
_gaq = _gaq || [];
and all the _gaq
variables outside of the closure. So above the //GOOGLE ANALYTICS
Works perfectly now :)
Brian's answer here is what fixed this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.