Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analytics): allow custom event parameters for begin_checkout and purchase events #7760

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading