Google Analytics 📈 in Angular App — Example

Google Analytics in Angular App

Do you need to measure traffic on your Angular routes? Then you are here right. In this example I will demonstrate how to create simple and elegant Angular service to measure traffic on your Angular App with Google Analytics.

Prerequisites

You should have already set up you Google Analytics account and have your UA-XXXXXXXX-X.

Example

First of all we will include Google Analytics in index.html.

Then we will create our Google Analytics service. Here we will subscribe for routing events, but only when we are in production.

The last step is app.module.ts, where we will inject our GoogleAnalyticsService.

And we are set up. Now we can test it, don’t forgot to comment out production mode line in GoogleAnalyticsService, when in dev environment. Here is screen from one of my apps.

Google Analytics with Angular 2

Google Analytics with Angular App

Related Post

PPTP VPN on MAC OS X Sierra, High Sierra and Mojav... PPTP VPN for Mac OS X Introduction PPTP VPN is no longer supported on macOS Sierra and High Sierra and that is just fine, because there are some se...
Right Click to Create New File on Mac OS X TL;DR; Windows has a lot of cons but it has also some pros. One of them is a smooth way to create empty file on right-click. Mac OS doesn't come with...
Translate Selected Text to English on Right Click ... TL;DR; Need instant translation right in context menu? You can accomplish it for free with one line of code in Automator, or you can proc...
FREE ePub Quicklook and Spotlight Plugins for Mac ... When you have a lot of ePub books, it can be useful to see excerpt and meta data information in quicklook. Even more important...
Right-Click to Translate (Look Up) with Google Tra... If you are not native english speaker, you may be frustrated with default "look up" options you get after selecting a text and right clicking. There a...
MacBook wifi issue – OS X keeps reconnecting Last few weeks I was facing annoying wifi problems. My mac was reconnecting every 5 minutes. On top of that BSSID was reseting so I saw BSSID changing...
Buy me a coffeeOut of coffee 😱, please help!