-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fix(analytics): Fix custom data layer function #2594
Conversation
Change arrow function to a normal function to use the arguments object as described in the gtag documentation. That way, analytics sends data back to Google again. Fixes #2505
Great catch! I'll merge and cut in the next RC, thanks. |
Cut in |
// 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); | ||
}); |
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.
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.
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.
You are right, I can make and submit another PR when I have free time
For reference, this regression was introduced in 23e2f1e. |
Adding a warning in the code so no one can turn the gtag function into an arrow function. PR angular#2594
Change arrow function to a normal function to use the arguments object as described in the gtag documentation. That way, analytics sends data back to Google again.
Fixes #2505
Checklist
yarn install
,yarn test
run successfully? yesDescription
Since updating to version 6.0.1, analytics no longer sends data to the Firebase Console. Analyzing and debugging this lib I realized that the code that defines a custom datalayer in gtag has been changed from a normal function to an arrow function.
After some research I learned that 'arguments' is not an array, it is actually an object that behaves like an array and contains more information besides indexes.
I'm not sure what the analytics need for this 'arguments' object, but I know that by making this change, the analytics sent the data back to the Console.