@mparticle/web-google-analytics-4-client-kit 1.4.2 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -127,12 +127,19 @@ var EVENT_NAME_MAX_LENGTH = 40;
127
127
  var EVENT_ATTRIBUTE_KEY_MAX_LENGTH = 40;
128
128
  var EVENT_ATTRIBUTE_VAL_MAX_LENGTH = 100;
129
129
  var EVENT_ATTRIBUTE_MAX_NUMBER = 100;
130
+ var PAGE_TITLE_MAX_LENGTH = 300;
131
+ var PAGE_REFERRER_MAX_LENGTH = 420;
132
+ var PAGE_LOCATION_MAX_LENGTH = 1000;
130
133
 
131
134
  var USER_ATTRIBUTE_KEY_MAX_LENGTH = 24;
132
135
  var USER_ATTRIBUTE_VALUE_MAX_LENGTH = 36;
133
136
 
134
137
  var PRODUCT_ATTRIBUTE_MAX_NUMBER = 10;
135
138
 
139
+ var PAGE_TITLE_KEY = 'page_title';
140
+ var PAGE_LOCATION_KEY = 'page_location';
141
+ var PAGE_REFERRER_KEY = 'page_referrer';
142
+
136
143
  var RESERVED_PRODUCT_KEYS = [
137
144
  'item_category',
138
145
  'item_category2',
@@ -186,7 +193,21 @@ Common.prototype.truncateAttributes = function (
186
193
  if (!isEmpty(attributes)) {
187
194
  Object.keys(attributes).forEach(function (attribute) {
188
195
  var key = truncateString(attribute, keyLimit);
189
- var val = truncateString(attributes[attribute], valueLimit);
196
+ var valueLimitOverride;
197
+ switch (key) {
198
+ case PAGE_TITLE_KEY:
199
+ valueLimitOverride = PAGE_TITLE_MAX_LENGTH;
200
+ break;
201
+ case PAGE_REFERRER_KEY:
202
+ valueLimitOverride = PAGE_REFERRER_MAX_LENGTH;
203
+ break;
204
+ case PAGE_LOCATION_KEY:
205
+ valueLimitOverride = PAGE_LOCATION_MAX_LENGTH;
206
+ break;
207
+ default:
208
+ valueLimitOverride = valueLimit;
209
+ }
210
+ var val = truncateString(attributes[attribute], valueLimitOverride);
190
211
  truncatedAttributes[key] = val;
191
212
  });
192
213
  }
@@ -659,6 +680,11 @@ CommerceHandler.prototype.logPromotionEvent = function (event) {
659
680
  event.PromotionAction.PromotionList.forEach(function (promotion) {
660
681
  ga4CommerceEventParameters = buildPromotion(promotion);
661
682
 
683
+ ga4CommerceEventParameters = self.common.mergeObjects(
684
+ ga4CommerceEventParameters,
685
+ self.common.limitEventAttributes(event.EventAttributes)
686
+ );
687
+
662
688
  self.sendCommerceEventToGA4(
663
689
  mapGA4EcommerceEventName(event),
664
690
  ga4CommerceEventParameters
@@ -685,6 +711,11 @@ CommerceHandler.prototype.logImpressionEvent = function (event, affiliation) {
685
711
  affiliation
686
712
  );
687
713
 
714
+ ga4CommerceEventParameters = self.common.mergeObjects(
715
+ ga4CommerceEventParameters,
716
+ self.common.limitEventAttributes(event.EventAttributes)
717
+ );
718
+
688
719
  self.sendCommerceEventToGA4(
689
720
  mapGA4EcommerceEventName(event),
690
721
  ga4CommerceEventParameters
@@ -1053,13 +1084,16 @@ EventHandler.prototype.logError = function () {
1053
1084
  EventHandler.prototype.logPageView = function (event) {
1054
1085
  var TITLE = 'GA4.Title';
1055
1086
  var LOCATION = 'GA4.Location';
1087
+ var REFERRER = 'GA4.Referrer';
1056
1088
 
1057
1089
  // These are being included for backwards compatibility from the legacy Google Analytics custom flags
1058
1090
  var LEGACY_GA_TITLE = 'Google.Title';
1059
1091
  var LEGACY_GA_LOCATION = 'Google.Location';
1092
+ var LEGACY_GA_REFERRER = 'Google.DocumentReferrer';
1060
1093
 
1061
- var pageLocation = location.href,
1062
- pageTitle = document.title;
1094
+ var pageLocation = location.href;
1095
+ var pageTitle = document.title;
1096
+ var pageReferrer = document.referrer;
1063
1097
 
1064
1098
  if (event.CustomFlags) {
1065
1099
  if (event.CustomFlags.hasOwnProperty(TITLE)) {
@@ -1073,12 +1107,19 @@ EventHandler.prototype.logPageView = function (event) {
1073
1107
  } else if (event.CustomFlags.hasOwnProperty(LEGACY_GA_LOCATION)) {
1074
1108
  pageLocation = event.CustomFlags[LEGACY_GA_LOCATION];
1075
1109
  }
1110
+
1111
+ if (event.CustomFlags.hasOwnProperty(REFERRER)) {
1112
+ pageReferrer = event.CustomFlags[REFERRER];
1113
+ } else if (event.CustomFlags.hasOwnProperty(LEGACY_GA_REFERRER)) {
1114
+ pageReferrer = event.CustomFlags[LEGACY_GA_REFERRER];
1115
+ }
1076
1116
  }
1077
1117
 
1078
1118
  var eventAttributes = this.common.mergeObjects(
1079
1119
  {
1080
1120
  page_title: pageTitle,
1081
1121
  page_location: pageLocation,
1122
+ page_referrer: pageReferrer,
1082
1123
  },
1083
1124
  event.EventAttributes
1084
1125
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-google-analytics-4-client-kit",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
5
5
  "description": "mParticle integration sdk for Google Analytics",
6
6
  "main": "dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js",