Skip to content

Commit

Permalink
fix(analytics): allow custom event parameters for screen_view events (#…
Browse files Browse the repository at this point in the history
…5811)

* fix(analytics): allow custom event parameters for screen_view events

Fixes #4594.

* style(lint): fix prettier error

Co-authored-by: Mike Hardy <github@mikehardy.net>
  • Loading branch information
tomonacci and mikehardy authored Oct 25, 2021
1 parent 89b104a commit 02e888e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/analytics/__tests__/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ describe('Analytics', function () {
'firebase.analytics().logScreenView(*):',
);
});
it('accepts arbitrary custom event parameters while rejecting defined parameters with wrong types', function () {
expect(() => firebase.analytics().logScreenView({ foo: 'bar' })).not.toThrow();
expect(() =>
// @ts-ignore test
firebase.analytics().logScreenView({ screen_name: 123, foo: 'bar' }),
).toThrowError('firebase.analytics().logScreenView(*):');
});
});

describe('logAddPaymentInfo()', function () {
Expand Down
4 changes: 4 additions & 0 deletions packages/analytics/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ export namespace FirebaseAnalyticsTypes {
* Current class associated with the view the user is currently viewing.
*/
screen_class?: string;
/**
* Custom event parameters.
*/
[key: string]: any;
}

export interface RefundEventParameters {
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/lib/structs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Item = struct({
price: 'number?',
});

export const ScreenView = struct({
export const ScreenView = struct.interface({
screen_class: 'string?',
screen_name: 'string?',
});
Expand Down

1 comment on commit 02e888e

@vercel
Copy link

@vercel vercel bot commented on 02e888e Oct 25, 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.