Last active
August 29, 2015 13:56
-
-
Save gabrielhpugliese/9239002 to your computer and use it in GitHub Desktop.
Change preventTracking function to match your requirements of dev env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trackWoopra = function (name, options) { | |
// woopra | |
var user = Meteor.user(), | |
identification = {}; | |
if (Meteor.user()) { | |
identification = { | |
name: user.profile.name, | |
email: user._id | |
}; | |
if (user.profile && user.profile.username) { | |
identification.username = user.profile.username; | |
} | |
} | |
woopra.identify(identification); | |
if (! name) { | |
return woopra.track(); | |
} | |
return woopra.track(name, options); | |
}; | |
trackGAEvent = function (category, action, label) { | |
_gaq.push(['_trackEvent', category, action, label]); | |
}; | |
trackEvent = function (name, options) { | |
if (preventTracking()) { | |
return; | |
} | |
//trackWoopra(name, options); | |
var label = _.values(options).join('_'), | |
action = 'click'; | |
return trackGAEvent(name, action, label); | |
}; | |
trackPageview = function (path) { | |
var settings = Meteor.settings, | |
UA = null; | |
if (preventTracking()) { | |
return; | |
} | |
if (settings && settings.public) { | |
UA = Meteor.settings.public.ga; | |
} | |
else { | |
// production | |
UA = 'UA-XXXXXXX-Y'; | |
} | |
// ga | |
window._gaq = window._gaq || []; | |
window._gaq.push(['_setAccount', UA]); | |
window._gaq.push(['_trackPageview', path]); | |
// woopra | |
//trackWoopra(); | |
} | |
preventTracking = function () { | |
if (Meteor.settings.public.DEBUG) { | |
console.debug('In localhost not tracking GA'); | |
return true; | |
} | |
return false; | |
}; | |
Deps.autorun(function () { | |
var current = Router.current(); | |
if (! current) { | |
return; | |
} | |
var path = current.path; | |
trackPageview(path); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment