Skip to content

Instantly share code, notes, and snippets.

@Splaktar
Forked from StephenFluin/app.component.ts
Last active July 14, 2016 05:27
Show Gist options
  • Save Splaktar/578d849b116d6c6a129d07ccfb89cf56 to your computer and use it in GitHub Desktop.
Save Splaktar/578d849b116d6c6a129d07ccfb89cf56 to your computer and use it in GitHub Desktop.
Angular 2 Analytics via Routing
//...
import {ROUTER_DIRECTIVES, Router, Event, NavigationEnd} from '@angular/router';
import {environment} from './environment';
//...
declare var ga : any;
//..
constructor(private router: Router ) {
if (environment.production) {
router.events.subscribe(
(event: Event) => {
if (event instanceof NavigationEnd) {
ga('send', 'pageview', event.urlAfterRedirects);
}
}
);
}
}
//..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment