Answers for "adding google analytics to angular"

1

adding google analytics to angular

...
import{Router, NavigationEnd} from '@angular/router';
...
declare let gtag: Function;
...
export class AppComponent {
  constructor(public router: Router){   
      this.router.events.subscribe(event => {
         if(event instanceof NavigationEnd){
             gtag('config', 'xx-xxxxx-xx', 
                   {
                     'page_path': event.urlAfterRedirects
                   }
                  );
          }
       }
    )}
}
Posted by: Guest on March-13-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language