From 82c90f1a0f1f095108c0a65ea401592ffa3ed485 Mon Sep 17 00:00:00 2001 From: Capelinha Date: Tue, 6 Oct 2020 21:39:39 -0300 Subject: [PATCH 1/2] refactor(analytics): Add warning in the code Adding a warning in the code so no one can turn the gtag function into an arrow function. PR #2594 --- src/analytics/analytics.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/analytics/analytics.ts b/src/analytics/analytics.ts index 7257b265d..758b48998 100644 --- a/src/analytics/analytics.ts +++ b/src/analytics/analytics.ts @@ -66,6 +66,12 @@ export class AngularFireAnalytics { if (!analyticsInitialized) { if (isPlatformBrowser(platformId)) { window[DATA_LAYER_NAME] = window[DATA_LAYER_NAME] || []; + /** + * According to the gtag documentation, this function that defines a custom datalayer cannot be + * an arrow function because 'arguments' is not an array, it is actually an object that behaves + * like an array and contains more information besides indexes. Transform into arrow Funcion + * created issue #2505 causing the analytics to no longer send data to the console. + */ // 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); From 805f3e0543168c48bee1e82c08b9ea9c2d02d25a Mon Sep 17 00:00:00 2001 From: Capelinha Date: Wed, 7 Oct 2020 19:04:04 -0300 Subject: [PATCH 2/2] refactor(analytics): Update warning Applying changes suggested by other contributors --- src/analytics/analytics.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/analytics/analytics.ts b/src/analytics/analytics.ts index 758b48998..35e9374af 100644 --- a/src/analytics/analytics.ts +++ b/src/analytics/analytics.ts @@ -67,10 +67,10 @@ export class AngularFireAnalytics { if (isPlatformBrowser(platformId)) { window[DATA_LAYER_NAME] = window[DATA_LAYER_NAME] || []; /** - * According to the gtag documentation, this function that defines a custom datalayer cannot be - * an arrow function because 'arguments' is not an array, it is actually an object that behaves - * like an array and contains more information besides indexes. Transform into arrow Funcion - * created issue #2505 causing the analytics to no longer send data to the console. + * According to the gtag documentation, this function that defines a custom data layer cannot be + * an arrow function because 'arguments' is not an array. It is actually an object that behaves + * like an array and contains more information then just indexes. Transforming this into arrow function + * caused issue #2505 where analytics no longer sent any data. */ // tslint:disable-next-line: only-arrow-functions gtag = (window[GTAG_FUNCTION_NAME] as any) || (function(..._args: any[]) {