Skip to content

Commit

Permalink
feat(analytics): allow custom event parameters for begin_checkout and…
Browse files Browse the repository at this point in the history
… purchase events (#7760)

* Allow extra params in begin_checkout/purchase

* Add tests
  • Loading branch information
Minishlink authored May 3, 2024
1 parent 6401b88 commit 424b9d9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/analytics/__tests__/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ describe('Analytics', function () {
}),
).toThrowError('firebase.analytics().logBeginCheckout(*):');
});

it('accepts arbitrary custom event parameters', function () {
expect(() =>
firebase.analytics().logBeginCheckout({
value: 123,
currency: 'EUR',
foo: 'bar',
}),
).not.toThrow();
});
});

describe('logGenerateLead()', function () {
Expand Down Expand Up @@ -459,6 +469,16 @@ describe('Analytics', function () {
}),
).toThrowError('firebase.analytics().logPurchase(*):');
});

it('accepts arbitrary custom event parameters', function () {
expect(() =>
firebase.analytics().logPurchase({
value: 123,
currency: 'EUR',
foo: 'bar',
}),
).not.toThrow();
});
});

describe('logRefund()', function () {
Expand Down
8 changes: 8 additions & 0 deletions packages/analytics/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export namespace FirebaseAnalyticsTypes {
coupon?: string;

items?: Item[];
/**
* Custom event parameters.
*/
[key: string]: any;
}

export interface CampaignDetailsEventParameters {
Expand Down Expand Up @@ -334,6 +338,10 @@ export namespace FirebaseAnalyticsTypes {
* A single ID for a ecommerce group transaction.
*/
transaction_id?: string;
/**
* Custom event parameters.
*/
[key: string]: any;
}

export interface ScreenViewParameters {
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics/lib/structs.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const AddToWishlist = struct({
currency: 'string?',
});

export const BeginCheckout = struct({
export const BeginCheckout = struct.interface({
items: struct.optional([Item]),
value: 'number?',
currency: 'string?',
Expand Down Expand Up @@ -131,7 +131,7 @@ export const Refund = struct({
transaction_id: 'string?',
});

export const Purchase = struct({
export const Purchase = struct.interface({
affiliation: 'string?',
coupon: 'string?',
currency: 'string?',
Expand Down

0 comments on commit 424b9d9

Please sign in to comment.