Skip to content

Commit

Permalink
fix(analytics): allow more than 25 event parameters
Browse files Browse the repository at this point in the history
it is useful for google analytics 360 customers

Related #5676

Re-ordered tests at the same time, so that DebugView was
able to reliably record events during e2e test runs
  • Loading branch information
mikehardy committed Sep 3, 2021
1 parent 71a6d6d commit 5dde564
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
3 changes: 3 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jest.doMock('react-native', () => {
},
NativeModules: {
...ReactNative.NativeModules,
RNFBAnalyticsModule: {
logEvent: jest.fn(),
},
RNFBAppModule: {
NATIVE_FIREBASE_APPS: [
{
Expand Down
8 changes: 0 additions & 8 deletions packages/analytics/__tests__/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 19 additions & 16 deletions packages/analytics/e2e/analytics.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
});
});
7 changes: 6 additions & 1 deletion packages/analytics/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
7 changes: 0 additions & 7 deletions packages/analytics/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

1 comment on commit 5dde564

@vercel
Copy link

@vercel vercel bot commented on 5dde564 Sep 3, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.