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

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

merged 1 commit into from
Sep 24, 2020

Conversation

Capelinha
Copy link
Contributor

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

Description

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.

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
@jamesdaniels
Copy link
Member

jamesdaniels commented Sep 24, 2020

Great catch! I'll merge and cut in the next RC, thanks.

@jamesdaniels jamesdaniels merged commit 77a9a15 into angular:master Sep 24, 2020
@jamesdaniels
Copy link
Member

Cut in 6.0.3-canary.77a9a15

@Capelinha Capelinha deleted the fix/analytics-not-send-data branch September 24, 2020 11:12
Comment on lines +69 to +72
// 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);
});
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

@Splaktar
Copy link
Contributor

For reference, this regression was introduced in 23e2f1e.

Capelinha added a commit to Capelinha/angularfire that referenced this pull request Oct 7, 2020
Adding a warning in the code so no one can turn the gtag function into an arrow function.

PR angular#2594
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AngularFireAnalyticsModule not send data
4 participants