Adding support to Google Analytics
Adding Google Analytics to a web application is typically a straightforward process. However, when you make the jump to a Single Page Application (SPA) framework, such as AngularJS, things get a little more complicated for Google Analytics. Because of Angular's ng-view
directive (within your index.html
) injecting content upon route changes, the tracking necessary for Google Analytics does not get updated upon such events. Luckily, Angular's community has stepped up to this challenge and produced a third-party module called angular-google-analytics
that resolves the challenges faced in this endeavor. The
angular-google-analytics
module resolves our worries by providing a service that sends a new pageview event to Google Analytics whenever your Angular application's $location.path()
changes.
Setting up the angular-google-analytics module
I'll assume that you already have a Google account with a Google Analytics site set up and ready to receive data. This means...