Skip to content
Closed
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
7 changes: 7 additions & 0 deletions packages/GA4Client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [1.5.0](https://github.com/mparticle-integrations/mparticle-javascript-integration-google-analytics-4/compare/v1.4.5...v1.5.0) (2025-05-05)


### Features

* Map product position to GA4 item index ([#62](https://github.com/mparticle-integrations/mparticle-javascript-integration-google-analytics-4/issues/62)) ([308076c](https://github.com/mparticle-integrations/mparticle-javascript-integration-google-analytics-4/commit/308076cc22b6a7f9e78bfb0c40486654e09a2a98))

## [1.4.5](https://github.com/mparticle-integrations/mparticle-javascript-integration-google-analytics-4/compare/v1.4.4...v1.4.5) (2024-10-09)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,9 @@ function parseProduct(product, affiliation) {
case 'Variant':
productWithAllAttributes.item_variant = product.Variant;
break;
case 'Position':
productWithAllAttributes.index = product.Position;
break;
case 'Attributes':
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,9 @@ var GoogleAnalytics4Kit = (function (exports) {
case 'Variant':
productWithAllAttributes.item_variant = product.Variant;
break;
case 'Position':
productWithAllAttributes.index = product.Position;
break;
case 'Attributes':
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions packages/GA4Client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/GA4Client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mparticle/web-google-analytics-4-client-kit",
"version": "1.4.5",
"version": "1.5.0",
"author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
"description": "mParticle integration sdk for Google Analytics",
"main": "dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js",
Expand Down
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