Skip to content

fix(analytics): Fix custom data layer function #2594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ export class AngularFireAnalytics {

if (!analyticsInitialized) {
if (isPlatformBrowser(platformId)) {
gtag = (window[GTAG_FUNCTION_NAME] as any) || ((...args: any[]) => {
(window[DATA_LAYER_NAME] as any).push(args);
});
window[DATA_LAYER_NAME] = window[DATA_LAYER_NAME] || [];
// tslint:disable-next-line: only-arrow-functions
gtag = (window[GTAG_FUNCTION_NAME] as any) || (function(..._args: any[]) {
(window[DATA_LAYER_NAME] as any).push(arguments);
});
Comment on lines +69 to +72
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should have a comment in here that warns developers/contributors to making this an arrow function causes GA to break completely.

In the current state, it's likely that someone will come in and "fix" this breaking GA again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I can make and submit another PR when I have free time

analyticsInitialized = zone.runOutsideAngular(() =>
new Promise(resolve => {
window[GTAG_FUNCTION_NAME] = (...args: any[]) => {
Expand Down