Skip to content

Commit

Permalink
fix(docs): update analytics tracking to exclude duplicated events (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnixaa authored Jun 21, 2018
1 parent 946e68c commit 36e2611
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
19 changes: 16 additions & 3 deletions docs/app/@theme/services/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable, Inject } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { Location } from '@angular/common';

import { filter } from 'rxjs/operators';
import { filter, delay, map } from 'rxjs/operators';
import { NB_WINDOW } from '@nebular/theme';
declare const ga: any;

Expand All @@ -20,9 +20,12 @@ export class NgdAnalytics {
if (this.enabled) {
this.router.events.pipe(
filter((event) => event instanceof NavigationEnd),
map(() => this.location.path()),
filter((location: string) => this.trackLocation(location)),
delay(50),
)
.subscribe(() => {
ga('send', {hitType: 'pageview', page: this.location.path()});
.subscribe((location: string) => {
ga('send', { hitType: 'pageview', page: location });
});
}
}
Expand All @@ -32,4 +35,14 @@ export class NgdAnalytics {
ga('send', 'event', eventName, eventVal);
}
}

private trackLocation(path: string) {
if (path.match(/\/components\/[a-zA-Z-]+\/?$/)
|| path.match(/\/docs\/?$/)
|| path.match(/\/example\//)) {

return !!path.match(/\/components\/components-overview\/?$/);
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class NgdTabbedBlockComponent implements OnDestroy {
this.tabs$.pipe(filter((tabs) => tabs && tabs.length)),
])
.subscribe(([params, tabs]) => {
this.router.navigate([tabs[0].tab], { relativeTo: activatedRoute });
this.router.navigate([tabs[0].tab], { relativeTo: activatedRoute, replaceUrl: true });
});

combineLatest([
Expand Down
4 changes: 3 additions & 1 deletion docs/app/example/example.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AfterViewInit, Component, Inject, OnDestroy, OnInit } from '@angular/co
import { Router } from '@angular/router';
import { takeWhile } from 'rxjs/operators';
import { NB_DOCUMENT, NbThemeService } from '@nebular/theme';
import { NgdIframeCommunicatorService } from '../@theme/services';
import { NgdAnalytics, NgdIframeCommunicatorService } from '../@theme/services';

@Component({
selector: 'ngd-example',
Expand All @@ -16,12 +16,14 @@ export class NgdExampleComponent implements OnInit, AfterViewInit, OnDestroy {
constructor(private communicator: NgdIframeCommunicatorService,
private themeService: NbThemeService,
private router: Router,
private analytics: NgdAnalytics,
@Inject(NB_DOCUMENT) private document) {
}

ngOnInit() {
this.setupId();
this.subscribeOnThemeSwitch();
this.analytics.trackEvent('example-view', this.id);
}

ngAfterViewInit() {
Expand Down
2 changes: 0 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-61945105-4', 'auto');
ga('send', 'pageview');

</script>

</head>
Expand Down

0 comments on commit 36e2611

Please sign in to comment.