A few days ago I tried to put Google Analytics on my Angular side project. It wasn’t very easy to find the solution for me.

In the examples, they were trying to use the $window property, attaching the “ga” object to the $window and then whenever you change a route in your app, you should $window.ga(‘send’, ‘pageview’, your_url_path_here).

It didn’t work for me, my Analytics dashboard was not showing anything.

After much googling, I found out, that I could do it without the $window. So instead of using $window.ga(‘send’,’pageview’, your_url_path_here), I just use ga(‘send’,’pageview’, your_url_path_here).

Install google analytics in AngularJs app, my current situation:

  • add to your index.html

     
  • create at first run