javascriptangularjsgoogle-analyticsangulartics

how do I turn off google analytics while using angulartics


I'm using Google Analytics with Angulartics in my webapp. I was getting a lot of noise from my app when developing locally so I turned off Google Analytics by just not loading the script if I am running on localhost like this:

<script>
if (window.location.host.indexOf('localhost') < 0) { 
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

        /* Google Analytics Code snippet*/

}
</script>

but now it occurs to me that Angulartics may blow up if this script is not loaded and my analytics object does not exist. I am not seeing any errors, so it would seem that Angulartics handles this case well, but since I am not familiar with the Angulartics internals I want to be sure before I ship this piece of code.

Will this cause any issues? Have I overlooked anything?


Solution

  • Okay, I did some digging through the Angulartics source and it appears that they do indeed check for the existence of window.ga in all instances on the following lines:

    so it would appear my initial assumption was correct and Angulartics does seem to handle cases in which Google Analytics is unavailable without blowing up.