Skip to content

Commit

Permalink
alerts-ui: Clean url before reporting to google analytics
Browse files Browse the repository at this point in the history
- Query parameters are not tracked.
- The token is removed from urls containing an unique token.
  • Loading branch information
AlexITC committed Feb 18, 2018
1 parent 8c8f73a commit a605bd9
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion alerts-ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,41 @@ export class AppComponent implements OnInit {

return true;
}).subscribe((x: any) => {
(<any>window).gtag('config', environment.gtag.id, { 'page_path': x.url });
const dirtyUrl: string = x.url || '';
const url = this.cleanUrlForAnalytics(dirtyUrl);
(<any>window).gtag('config', environment.gtag.id, { 'page_path': url });
});
}

private cleanUrlForAnalytics(dirtyUrl: string): string {
const urlWithoutParams = this.removeQueryParams(dirtyUrl);
const urlWithoutToken = this.removeTokens(urlWithoutParams);

return urlWithoutToken;
}

private removeTokens(dirtyUrl: string): string {
const urlWithToken = ['/verify-email'];
const result = urlWithToken
.filter(prefix => dirtyUrl.indexOf(prefix) >= 0)
.map(prefix => dirtyUrl.substring(0, dirtyUrl.indexOf(prefix) + prefix.length) );

if (result.length === 0) {
return dirtyUrl;
} else {
return result[0];
}
}

private removeQueryParams(url: string): string {
const index = url.indexOf('?');
if (index >= 0) {
return url.substring(0, index);
} else {
return url;
}
}

englishLang(): Object {
return {
'home.examples': 'Examples',
Expand Down

0 comments on commit a605bd9

Please sign in to comment.