This repository was archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 395
chore: send analytics data on all navigation ends #401
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {Injectable} from '@angular/core'; | ||
|
||
import {environment} from '../../../environments/environment'; | ||
|
||
@Injectable() | ||
/** | ||
* Google Analytics Service - captures app behaviors and sends them to Google Analytics (GA). | ||
* Presupposes that GA script has been loaded from a script on the host web page. | ||
* Associates data with a GA "property" from the environment (`gaId`). | ||
*/ | ||
export class GaService { | ||
|
||
private previousUrl: string; | ||
|
||
constructor() { | ||
this.ga('create', environment['matGaId'] , 'auto', 'mat'); | ||
this.ga('create', environment['ngGaId'] , 'auto', 'ng'); | ||
} | ||
|
||
locationChanged(url: string) { | ||
this.sendPage(url); | ||
} | ||
|
||
sendPage(url: string) { | ||
// Won't re-send if the url hasn't changed. | ||
if (url === this.previousUrl || !environment.production) { | ||
return; | ||
} | ||
this.previousUrl = url; | ||
this.ga('set', 'page', '/' + url); | ||
this.ga('mat.send', 'pageview'); | ||
this.ga('ng.send', 'pageview'); | ||
} | ||
|
||
ga(...args: any[]) { | ||
const gaFn = (window as any)['ga']; | ||
if (gaFn) { | ||
gaFn(...args); | ||
} | ||
} | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export const environment = { | ||
production: true | ||
matGaId: 'UA-8594346-24', // Production id | ||
ngGaId: 'UA-8594346-15', // Production id | ||
production: true, | ||
}; |
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e2e tests run on local host or other non-prod host, this causes all the GA pings to be ignored/filtered out automatically. In other words, it's typically not necessary to treat e2e tests differently.