Skip to content
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
5 changes: 5 additions & 0 deletions packages/GA4Client/src/commerce-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ CommerceHandler.prototype.logCheckoutOptionEvent = function (
return false;
}

ga4CommerceEventParameters = this.common.mergeObjects(
ga4CommerceEventParameters,
this.common.limitEventAttributes(event.EventAttributes)
);

return this.sendCommerceEventToGA4(
mapGA4EcommerceEventName(event),
ga4CommerceEventParameters
Expand Down
86 changes: 86 additions & 0 deletions packages/GA4Client/test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,92 @@ describe('Google Analytics 4 Event', function () {
done();
});

it('should include EventAttributes on GA4 add_shipping_info event when CheckoutOption has GA4.CommerceEventType add_shipping_info', function (done) {
mParticle.forwarder.process({
CurrencyCode: 'USD',
EventName: 'Test add_shipping_info Event',
EventDataType: MessageType.Commerce,
EventCategory: CommerceEventType.ProductCheckoutOption,
EventAttributes: {
page_url: 'https://example.com/checkout',
page_path: '/checkout',
mpID: '123',
SessionID: 'session-abc',
foo: 'bar',
},
CustomFlags: {
'GA4.CommerceEventType': 'add_shipping_info',
'GA4.ShippingTier': 'ground',
},
ProductAction: {
ProductActionType: ProductActionType.Click,
ProductList: [],
},
});

result = [
'event',
'add_shipping_info',
{
shipping_tier: 'ground',
coupon: null,
items: [],
page_url: 'https://example.com/checkout',
page_path: '/checkout',
mpID: '123',
SessionID: 'session-abc',
foo: 'bar',
send_to: 'testMeasurementId',
},
];
window.dataLayer[0].should.eql(result);

done();
});

it('should include EventAttributes on GA4 add_payment_info event when CheckoutOption has GA4.CommerceEventType add_payment_info', function (done) {
mParticle.forwarder.process({
CurrencyCode: 'USD',
EventName: 'Test add_payment_info Event',
EventDataType: MessageType.Commerce,
EventCategory: CommerceEventType.ProductCheckoutOption,
EventAttributes: {
page_url: 'https://example.com/checkout',
page_path: '/checkout',
mpID: '123',
SessionID: 'session-abc',
foo: 'bar',
},
CustomFlags: {
'GA4.CommerceEventType': 'add_payment_info',
'GA4.PaymentType': 'credit-card',
},
ProductAction: {
ProductActionType: ProductActionType.Click,
ProductList: [],
},
});

result = [
'event',
'add_payment_info',
{
payment_type: 'credit-card',
coupon: null,
items: [],
page_url: 'https://example.com/checkout',
page_path: '/checkout',
mpID: '123',
SessionID: 'session-abc',
foo: 'bar',
send_to: 'testMeasurementId',
},
];
window.dataLayer[0].should.eql(result);

done();
});

it('should log a view_cart event using ProductActionType.Unknown and a custom flag', function (done) {
mParticle.forwarder.process({
CurrencyCode: 'USD',
Expand Down
Loading