-
-
Save Splaktar/578d849b116d6c6a129d07ccfb89cf56 to your computer and use it in GitHub Desktop.
Angular 2 Analytics via Routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
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