Skip to content

Commit 424b9d9

Browse files
authored
feat(analytics): allow custom event parameters for begin_checkout and purchase events (#7760)
* Allow extra params in begin_checkout/purchase * Add tests
1 parent 6401b88 commit 424b9d9

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

packages/analytics/__tests__/analytics.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ describe('Analytics', function () {
272272
}),
273273
).toThrowError('firebase.analytics().logBeginCheckout(*):');
274274
});
275+
276+
it('accepts arbitrary custom event parameters', function () {
277+
expect(() =>
278+
firebase.analytics().logBeginCheckout({
279+
value: 123,
280+
currency: 'EUR',
281+
foo: 'bar',
282+
}),
283+
).not.toThrow();
284+
});
275285
});
276286

277287
describe('logGenerateLead()', function () {
@@ -459,6 +469,16 @@ describe('Analytics', function () {
459469
}),
460470
).toThrowError('firebase.analytics().logPurchase(*):');
461471
});
472+
473+
it('accepts arbitrary custom event parameters', function () {
474+
expect(() =>
475+
firebase.analytics().logPurchase({
476+
value: 123,
477+
currency: 'EUR',
478+
foo: 'bar',
479+
}),
480+
).not.toThrow();
481+
});
462482
});
463483

464484
describe('logRefund()', function () {

packages/analytics/lib/index.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ export namespace FirebaseAnalyticsTypes {
179179
coupon?: string;
180180

181181
items?: Item[];
182+
/**
183+
* Custom event parameters.
184+
*/
185+
[key: string]: any;
182186
}
183187

184188
export interface CampaignDetailsEventParameters {
@@ -334,6 +338,10 @@ export namespace FirebaseAnalyticsTypes {
334338
* A single ID for a ecommerce group transaction.
335339
*/
336340
transaction_id?: string;
341+
/**
342+
* Custom event parameters.
343+
*/
344+
[key: string]: any;
337345
}
338346

339347
export interface ScreenViewParameters {

packages/analytics/lib/structs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const AddToWishlist = struct({
6565
currency: 'string?',
6666
});
6767

68-
export const BeginCheckout = struct({
68+
export const BeginCheckout = struct.interface({
6969
items: struct.optional([Item]),
7070
value: 'number?',
7171
currency: 'string?',
@@ -131,7 +131,7 @@ export const Refund = struct({
131131
transaction_id: 'string?',
132132
});
133133

134-
export const Purchase = struct({
134+
export const Purchase = struct.interface({
135135
affiliation: 'string?',
136136
coupon: 'string?',
137137
currency: 'string?',

0 commit comments

Comments
 (0)