File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { Component } from '@angular/core' ;
2+ import { Router } from '@angular/router' ;
23import { faGithub } from '@fortawesome/free-brands-svg-icons' ;
34import { FragmentScrollService } from './shared/fragment-scroll.service' ;
4- import { Router } from '@angular/router ' ;
5+ import { AnalyticsService } from './shared/analytics.service ' ;
56
67@Component ( {
78 selector : 'demo-root' ,
@@ -10,6 +11,7 @@ import { Router } from '@angular/router';
1011 providers : [
1112 // This cannot be provided in root
1213 FragmentScrollService ,
14+ AnalyticsService ,
1315 ] ,
1416} )
1517export class DemoComponent {
@@ -19,9 +21,11 @@ export class DemoComponent {
1921
2022 constructor (
2123 private fragmentScroller : FragmentScrollService ,
24+ private analytics : AnalyticsService ,
2225 private router : Router ,
2326 ) {
2427 fragmentScroller . startFragmentScroller ( router ) ;
28+ analytics . startTracking ( router ) ;
2529 }
2630
2731 public closeNav ( ) {
Original file line number Diff line number Diff line change 1+ import { Injectable } from '@angular/core' ;
2+ import { NavigationEnd , Router } from '@angular/router' ;
3+ import { filter , map } from 'rxjs/operators' ;
4+
5+ declare const gtag : Function ;
6+
7+ @Injectable ( )
8+ export class AnalyticsService {
9+
10+ private readonly enabled : boolean ;
11+
12+ constructor ( ) {
13+ this . enabled = window && window . location && window . location . href . includes ( 'ngqp.io' ) ;
14+ }
15+
16+ public startTracking ( router : Router ) : void {
17+ if ( ! this . enabled ) {
18+ return ;
19+ }
20+
21+ router . events . pipe (
22+ filter ( event => event instanceof NavigationEnd ) ,
23+ map ( event => event as NavigationEnd ) ,
24+ ) . subscribe ( event => {
25+ const url = event . urlAfterRedirects ;
26+ gtag ( 'config' , 'UA-131508204-1' , { 'page_path' : url } ) ;
27+ } ) ;
28+ }
29+
30+ public trackEvent ( action : string ) : void {
31+ if ( ! this . enabled ) {
32+ return ;
33+ }
34+
35+ gtag ( 'event' , action ) ;
36+ }
37+
38+ }
Original file line number Diff line number Diff line change 2828 < meta property ="og:image:type " content ="image/svg+xml "/>
2929
3030 < link rel ="icon " type ="image/x-icon " href ="favicon.ico ">
31+
32+ < script async defer src ="https://buttons.github.io/buttons.js "> </ script >
33+ < script async src ="https://www.googletagmanager.com/gtag/js?id=UA-131508204-1 "> </ script >
34+ < script >
35+ window . dataLayer = window . dataLayer || [ ] ;
36+ function gtag ( ) {
37+ dataLayer . push ( arguments ) ;
38+ }
39+
40+ gtag ( 'js' , new Date ( ) ) ;
41+ </ script >
3142 </ head >
3243 < body >
3344 < demo-root > </ demo-root >
3445 </ body >
35-
36- < script async defer src ="https://buttons.github.io/buttons.js "> </ script >
3746</ html >
You can’t perform that action at this time.
0 commit comments