diff --git a/packages/GA4Client/CHANGELOG.md b/packages/GA4Client/CHANGELOG.md index 6bdea12..337e0d7 100644 --- a/packages/GA4Client/CHANGELOG.md +++ b/packages/GA4Client/CHANGELOG.md @@ -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) diff --git a/packages/GA4Client/dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js b/packages/GA4Client/dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js index f77eca6..4cb9e05 100644 --- a/packages/GA4Client/dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js +++ b/packages/GA4Client/dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js @@ -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: diff --git a/packages/GA4Client/dist/GoogleAnalytics4EventForwarderClientSide-Kit.iife.js b/packages/GA4Client/dist/GoogleAnalytics4EventForwarderClientSide-Kit.iife.js index 69eb76c..76c1ae8 100644 --- a/packages/GA4Client/dist/GoogleAnalytics4EventForwarderClientSide-Kit.iife.js +++ b/packages/GA4Client/dist/GoogleAnalytics4EventForwarderClientSide-Kit.iife.js @@ -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: diff --git a/packages/GA4Client/package-lock.json b/packages/GA4Client/package-lock.json index 481915f..c637159 100644 --- a/packages/GA4Client/package-lock.json +++ b/packages/GA4Client/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mparticle/web-google-analytics-4-client-kit", - "version": "1.4.5", + "version": "1.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@mparticle/web-google-analytics-4-client-kit", - "version": "1.4.5", + "version": "1.5.0", "license": "Apache-2.0", "dependencies": { "@mparticle/web-sdk": "^2.12.2", @@ -23215,4 +23215,4 @@ "dev": true } } -} \ No newline at end of file +} diff --git a/packages/GA4Client/package.json b/packages/GA4Client/package.json index c99ca19..cbe7f5d 100644 --- a/packages/GA4Client/package.json +++ b/packages/GA4Client/package.json @@ -1,6 +1,6 @@ { "name": "@mparticle/web-google-analytics-4-client-kit", - "version": "1.4.5", + "version": "1.5.0", "author": "mParticle Developers (https://www.mparticle.com)", "description": "mParticle integration sdk for Google Analytics", "main": "dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js", diff --git a/packages/GA4Client/src/commerce-handler.js b/packages/GA4Client/src/commerce-handler.js index e679d5b..7d4bd75 100644 --- a/packages/GA4Client/src/commerce-handler.js +++ b/packages/GA4Client/src/commerce-handler.js @@ -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 diff --git a/packages/GA4Client/test/src/tests.js b/packages/GA4Client/test/src/tests.js index a9f688c..3823c4d 100644 --- a/packages/GA4Client/test/src/tests.js +++ b/packages/GA4Client/test/src/tests.js @@ -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',