diff --git a/packages/GA4Client/src/commerce-handler.js b/packages/GA4Client/src/commerce-handler.js index 15c407a..cf02373 100644 --- a/packages/GA4Client/src/commerce-handler.js +++ b/packages/GA4Client/src/commerce-handler.js @@ -210,10 +210,17 @@ CommerceHandler.prototype.logCheckoutOptionEvent = function ( }; CommerceHandler.prototype.logPromotionEvent = function (event) { - var ga4CommerceEventParameters; + var self = this; try { + var ga4CommerceEventParameters; event.PromotionAction.PromotionList.forEach(function (promotion) { ga4CommerceEventParameters = buildPromotion(promotion); + + self.sendCommerceEventToGA4( + mapGA4EcommerceEventName(event), + ga4CommerceEventParameters + ); + return true; }); } catch (error) { console.error( @@ -222,22 +229,25 @@ CommerceHandler.prototype.logPromotionEvent = function (event) { ); return false; } - - this.sendCommerceEventToGA4( - mapGA4EcommerceEventName(event), - ga4CommerceEventParameters - ); - return true; }; CommerceHandler.prototype.logImpressionEvent = function (event, affiliation) { - var ga4CommerceEventParameters; + var self = this; try { + var ga4CommerceEventParameters; event.ProductImpressions.forEach(function (impression) { ga4CommerceEventParameters = parseImpression( impression, affiliation ); + + + self.sendCommerceEventToGA4( + mapGA4EcommerceEventName(event), + ga4CommerceEventParameters + ); + + return true; }); } catch (error) { console.log( @@ -246,13 +256,6 @@ CommerceHandler.prototype.logImpressionEvent = function (event, affiliation) { ); return false; } - - this.sendCommerceEventToGA4( - mapGA4EcommerceEventName(event), - ga4CommerceEventParameters - ); - - return true; }; CommerceHandler.prototype.logViewCart = function (event, affiliation) { diff --git a/packages/GA4Client/src/common.js b/packages/GA4Client/src/common.js index 1c20642..6ac4fff 100644 --- a/packages/GA4Client/src/common.js +++ b/packages/GA4Client/src/common.js @@ -7,7 +7,8 @@ var ConsentHandler = require('./consent'); var EVENT_NAME_MAX_LENGTH = 40; var EVENT_ATTRIBUTE_KEY_MAX_LENGTH = 40; var EVENT_ATTRIBUTE_VAL_MAX_LENGTH = 100; -var EVENT_ATTRIBUTE_MAX_NUMBER = 100; +// maximum event attributes reduced to 99 instead of 100 since now we include send_to as GA4 event parameter +var EVENT_ATTRIBUTE_MAX_NUMBER = 99; var USER_ATTRIBUTE_KEY_MAX_LENGTH = 24; var USER_ATTRIBUTE_VALUE_MAX_LENGTH = 36;