From 5dde56414caf3b79a5b6c4b1c61485789d7b564b Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Thu, 2 Sep 2021 23:20:02 -0500 Subject: [PATCH] fix(analytics): allow more than 25 event parameters it is useful for google analytics 360 customers Related https://github.com/invertase/react-native-firebase/discussions/5676 Re-ordered tests at the same time, so that DebugView was able to reliably record events during e2e test runs --- jest.setup.ts | 3 ++ .../analytics/__tests__/analytics.test.ts | 8 ----- packages/analytics/e2e/analytics.e2e.js | 35 ++++++++++--------- packages/analytics/lib/index.d.ts | 7 +++- packages/analytics/lib/index.js | 7 ---- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/jest.setup.ts b/jest.setup.ts index 877d37e26d..f824111b85 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -9,6 +9,9 @@ jest.doMock('react-native', () => { }, NativeModules: { ...ReactNative.NativeModules, + RNFBAnalyticsModule: { + logEvent: jest.fn(), + }, RNFBAppModule: { NATIVE_FIREBASE_APPS: [ { diff --git a/packages/analytics/__tests__/analytics.test.ts b/packages/analytics/__tests__/analytics.test.ts index 19a45f3816..916163d9b0 100644 --- a/packages/analytics/__tests__/analytics.test.ts +++ b/packages/analytics/__tests__/analytics.test.ts @@ -130,14 +130,6 @@ describe('Analytics', function () { ); }); - it('errors if more than 25 params provided', function () { - expect(() => - firebase.analytics().logEvent('invertase', Object.assign({}, new Array(26).fill(1))), - ).toThrowError( - "firebase.analytics().logEvent(_, *) 'params' maximum number of parameters exceeded (25).", - ); - }); - describe('logScreenView()', function () { it('errors if param is not an object', function () { // @ts-ignore test diff --git a/packages/analytics/e2e/analytics.e2e.js b/packages/analytics/e2e/analytics.e2e.js index 0e70537988..6dd363b71f 100644 --- a/packages/analytics/e2e/analytics.e2e.js +++ b/packages/analytics/e2e/analytics.e2e.js @@ -32,22 +32,6 @@ describe('analytics()', function () { }); }); - describe('setAnalyticsCollectionEnabled()', function () { - it('true', async function () { - await firebase.analytics().setAnalyticsCollectionEnabled(true); - }); - - it('false', async function () { - await firebase.analytics().setAnalyticsCollectionEnabled(false); - }); - }); - - describe('resetAnalyticsData()', function () { - it('calls native fn without error', async function () { - await firebase.analytics().resetAnalyticsData(); - }); - }); - describe('setSessionTimeoutDuration()', function () { it('default duration', async function () { await firebase.analytics().setSessionTimeoutDuration(); @@ -432,4 +416,23 @@ describe('analytics()', function () { await firebase.analytics().setDefaultEventParameters({ number: 1, stringn: '123' }); }); }); + + // Test this one near end so all the previous hits are visible in DebugView is that is enabled + describe('resetAnalyticsData()', function () { + it('calls native fn without error', async function () { + await firebase.analytics().resetAnalyticsData(); + }); + }); + + // Test this last so it does not stop delivery to DebugView + describe('setAnalyticsCollectionEnabled()', function () { + it('false', async function () { + await firebase.analytics().setAnalyticsCollectionEnabled(false); + }); + + // Enable as the last action, so the rest of the hits are visible in DebugView if enabled + it('true', async function () { + await firebase.analytics().setAnalyticsCollectionEnabled(true); + }); + }); }); diff --git a/packages/analytics/lib/index.d.ts b/packages/analytics/lib/index.d.ts index 3e7fa2de6e..9b8422bef2 100644 --- a/packages/analytics/lib/index.d.ts +++ b/packages/analytics/lib/index.d.ts @@ -642,7 +642,12 @@ export namespace FirebaseAnalyticsTypes { */ export class Module extends FirebaseModule { /** - * Log a custom event with optional params. + * Log a custom event with optional params. Note that there are various limits that applied + * to event parameters (total parameter count, etc), but analytics applies the limits during + * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. + * While integrating this API in your app you are strongly encouraged to enable + * [DebugView](https://firebase.google.com/docs/analytics/debugview) - + * any errors in your events will show up in the firebase web console with links to relevant documentation * * #### Example * diff --git a/packages/analytics/lib/index.js b/packages/analytics/lib/index.js index 1b17d0fa10..5243c1b9cc 100644 --- a/packages/analytics/lib/index.js +++ b/packages/analytics/lib/index.js @@ -94,13 +94,6 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - // maximum number of allowed params check - if (params && Object.keys(params).length > 25) { - throw new Error( - "firebase.analytics().logEvent(_, *) 'params' maximum number of parameters exceeded (25).", - ); - } - return this.native.logEvent(name, params); }