@mparticle/web-sdk 2.28.3 → 2.29.1

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.
package/dist/mparticle.js CHANGED
@@ -393,7 +393,7 @@ var mParticle = (function () {
393
393
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
394
394
  };
395
395
 
396
- var version = "2.28.3";
396
+ var version = "2.29.1";
397
397
 
398
398
  var Constants = {
399
399
  sdkVersion: version,
@@ -552,7 +552,8 @@ var mParticle = (function () {
552
552
  OfflineStorage: 'offlineStorage',
553
553
  DirectUrlRouting: 'directURLRouting',
554
554
  CacheIdentity: 'cacheIdentity',
555
- AudienceAPI: 'audienceAPI'
555
+ AudienceAPI: 'audienceAPI',
556
+ CaptureIntegrationSpecificIds: 'captureIntegrationSpecificIds'
556
557
  },
557
558
  DefaultInstance: 'default_instance',
558
559
  CCPAPurpose: 'data_sale_opt_out',
@@ -755,6 +756,91 @@ var mParticle = (function () {
755
756
  var moveElementToEnd = function moveElementToEnd(array, index) {
756
757
  return array.slice(0, index).concat(array.slice(index + 1), array[index]);
757
758
  };
759
+ var queryStringParser = function queryStringParser(url, keys) {
760
+ if (keys === void 0) {
761
+ keys = [];
762
+ }
763
+ var urlParams;
764
+ var results = {};
765
+ if (!url) return results;
766
+ if (typeof URL !== 'undefined' && typeof URLSearchParams !== 'undefined') {
767
+ var urlObject = new URL(url);
768
+ urlParams = new URLSearchParams(urlObject.search);
769
+ } else {
770
+ urlParams = queryStringParserFallback(url);
771
+ }
772
+ if (isEmpty(keys)) {
773
+ urlParams.forEach(function (value, key) {
774
+ results[key] = value;
775
+ });
776
+ } else {
777
+ keys.forEach(function (key) {
778
+ var value = urlParams.get(key);
779
+ if (value) {
780
+ results[key] = value;
781
+ }
782
+ });
783
+ }
784
+ return results;
785
+ };
786
+ var queryStringParserFallback = function queryStringParserFallback(url) {
787
+ var params = {};
788
+ var queryString = url.split('?')[1] || '';
789
+ var pairs = queryString.split('&');
790
+ pairs.forEach(function (pair) {
791
+ var _a = pair.split('='),
792
+ key = _a[0],
793
+ value = _a[1];
794
+ if (key && value) {
795
+ params[key] = decodeURIComponent(value || '');
796
+ }
797
+ });
798
+ return {
799
+ get: function get(key) {
800
+ return params[key];
801
+ },
802
+ forEach: function forEach(callback) {
803
+ for (var key in params) {
804
+ if (params.hasOwnProperty(key)) {
805
+ callback(params[key], key);
806
+ }
807
+ }
808
+ }
809
+ };
810
+ };
811
+ // Get cookies as a dictionary
812
+ var getCookies = function getCookies(keys) {
813
+ // Helper function to parse cookies from document.cookie
814
+ var parseCookies = function parseCookies() {
815
+ if (typeof window === 'undefined') {
816
+ return [];
817
+ }
818
+ return window.document.cookie.split(';').map(function (cookie) {
819
+ return cookie.trim();
820
+ });
821
+ };
822
+ // Helper function to filter cookies by keys
823
+ var filterCookies = function filterCookies(cookies, keys) {
824
+ var results = {};
825
+ for (var _i = 0, cookies_1 = cookies; _i < cookies_1.length; _i++) {
826
+ var cookie = cookies_1[_i];
827
+ var _a = cookie.split('='),
828
+ key = _a[0],
829
+ value = _a[1];
830
+ if (!keys || keys.includes(key)) {
831
+ results[key] = value;
832
+ }
833
+ }
834
+ return results;
835
+ };
836
+ // Parse cookies from document.cookie
837
+ var parsedCookies = parseCookies();
838
+ // Filter cookies by keys if provided
839
+ return filterCookies(parsedCookies, keys);
840
+ };
841
+ var getHref = function getHref() {
842
+ return typeof window !== 'undefined' && window.location ? window.location.href : '';
843
+ };
758
844
 
759
845
  function getNewIdentitiesByName(newIdentitiesByType) {
760
846
  var newIdentitiesByName = {};
@@ -1456,8 +1542,8 @@ var mParticle = (function () {
1456
1542
  },
1457
1543
  device_info: {
1458
1544
  platform: dist.DeviceInformationPlatformEnum.web,
1459
- screen_width: window.screen.width,
1460
- screen_height: window.screen.height
1545
+ screen_width: typeof window !== 'undefined' ? window.screen.width : 0,
1546
+ screen_height: typeof window !== 'undefined' ? window.screen.height : 0
1461
1547
  },
1462
1548
  user_attributes: lastEvent.UserAttributes,
1463
1549
  user_identities: convertUserIdentities(lastEvent.UserIdentities),
@@ -2108,7 +2194,7 @@ var mParticle = (function () {
2108
2194
  return __generator(this, function (_a) {
2109
2195
  switch (_a.label) {
2110
2196
  case 0:
2111
- return [4 /*yield*/, this.makeRequest(this.url, fetchPayload.body, fetchPayload.method)];
2197
+ return [4 /*yield*/, this.makeRequest(this.url, fetchPayload.body, fetchPayload.method, fetchPayload.headers)];
2112
2198
  case 1:
2113
2199
  response = _a.sent();
2114
2200
  return [2 /*return*/, response];
@@ -2124,10 +2210,13 @@ var mParticle = (function () {
2124
2210
  // 3 LOADING Downloading; responseText holds partial data.
2125
2211
  // 4 DONE The operation is complete.
2126
2212
  // https://go.mparticle.com/work/SQDSDKS-6736
2127
- XHRUploader.prototype.makeRequest = function (url, data, method) {
2213
+ XHRUploader.prototype.makeRequest = function (url, data, method, headers) {
2128
2214
  if (method === void 0) {
2129
2215
  method = 'post';
2130
2216
  }
2217
+ if (headers === void 0) {
2218
+ headers = {};
2219
+ }
2131
2220
  return __awaiter(this, void 0, void 0, function () {
2132
2221
  var xhr;
2133
2222
  return __generator(this, function (_a) {
@@ -2145,6 +2234,11 @@ var mParticle = (function () {
2145
2234
  reject(xhr);
2146
2235
  };
2147
2236
  xhr.open(method, url);
2237
+ Object.entries(headers).forEach(function (_a) {
2238
+ var key = _a[0],
2239
+ value = _a[1];
2240
+ xhr.setRequestHeader(key, value);
2241
+ });
2148
2242
  xhr.send(data);
2149
2243
  })];
2150
2244
  });
@@ -4217,7 +4311,8 @@ var mParticle = (function () {
4217
4311
  OfflineStorage = _a.OfflineStorage,
4218
4312
  DirectUrlRouting = _a.DirectUrlRouting,
4219
4313
  CacheIdentity = _a.CacheIdentity,
4220
- AudienceAPI = _a.AudienceAPI;
4314
+ AudienceAPI = _a.AudienceAPI,
4315
+ CaptureIntegrationSpecificIds = _a.CaptureIntegrationSpecificIds;
4221
4316
  if (!config.flags) {
4222
4317
  return {};
4223
4318
  }
@@ -4230,6 +4325,7 @@ var mParticle = (function () {
4230
4325
  flags[DirectUrlRouting] = config.flags[DirectUrlRouting] === 'True';
4231
4326
  flags[CacheIdentity] = config.flags[CacheIdentity] === 'True';
4232
4327
  flags[AudienceAPI] = config.flags[AudienceAPI] === 'True';
4328
+ flags[CaptureIntegrationSpecificIds] = config.flags[CaptureIntegrationSpecificIds] === 'True';
4233
4329
  return flags;
4234
4330
  }
4235
4331
  function processBaseUrls(config, flags, apiKey) {
@@ -6510,6 +6606,15 @@ var mParticle = (function () {
6510
6606
  var optOut = event.messageType === Types.MessageType.OptOut ? !mpInstance._Store.isEnabled : null;
6511
6607
  // TODO: Why is Webview Bridge Enabled or Opt Out necessary here?
6512
6608
  if (mpInstance._Store.sessionId || event.messageType === Types.MessageType.OptOut || mpInstance._Store.webviewBridgeEnabled) {
6609
+ var customFlags = __assign({}, event.customFlags);
6610
+ // https://go.mparticle.com/work/SQDSDKS-5053
6611
+ if (mpInstance._Helpers.getFeatureFlag && mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIds)) {
6612
+ // Attempt to recapture click IDs in case a third party integration
6613
+ // has added or updated new click IDs since the last event was sent.
6614
+ mpInstance._IntegrationCapture.capture();
6615
+ var transformedClickIDs = mpInstance._IntegrationCapture.getClickIdsAsCustomFlags();
6616
+ customFlags = __assign(__assign({}, transformedClickIDs), customFlags);
6617
+ }
6513
6618
  if (event.hasOwnProperty('toEventAPIObject')) {
6514
6619
  eventObject = event.toEventAPIObject();
6515
6620
  } else {
@@ -6522,7 +6627,7 @@ var mParticle = (function () {
6522
6627
  EventAttributes: mpInstance._Helpers.sanitizeAttributes(event.data, event.name),
6523
6628
  SourceMessageId: event.sourceMessageId || mpInstance._Helpers.generateUniqueId(),
6524
6629
  EventDataType: event.messageType,
6525
- CustomFlags: event.customFlags || {},
6630
+ CustomFlags: customFlags,
6526
6631
  UserAttributeChanges: event.userAttributeChanges,
6527
6632
  UserIdentityChanges: event.userIdentityChanges
6528
6633
  };
@@ -6722,23 +6827,6 @@ var mParticle = (function () {
6722
6827
  Login$1 = _a.Login,
6723
6828
  Logout$1 = _a.Logout;
6724
6829
  var CACHE_HEADER = 'x-mp-max-age';
6725
- // https://go.mparticle.com/work/SQDSDKS-6568
6726
- // Temporary adapter to convert the XMLHttpRequest response to the IIdentityResponse interface
6727
- var xhrIdentityResponseAdapter = function xhrIdentityResponseAdapter(possiblyXhr) {
6728
- if (possiblyXhr.hasOwnProperty('expireTimestamp')) {
6729
- // If there is an `expireTimestamp`, it is an IIdentityResponse object, so just return it. This indicates it was a previously cached value.
6730
- return possiblyXhr;
6731
- } else {
6732
- // If there is no `expireTimestamp`, then it is an XHR object and needs to be parsed.
6733
- return {
6734
- status: possiblyXhr.status,
6735
- // Sometimes responseText can be an empty string, such as a 404 response
6736
- responseText: possiblyXhr.responseText ? JSON.parse(possiblyXhr.responseText) : {},
6737
- cacheMaxAge: parseNumber((possiblyXhr === null || possiblyXhr === void 0 ? void 0 : possiblyXhr.getResponseHeader(CACHE_HEADER)) || ''),
6738
- expireTimestamp: 0
6739
- };
6740
- }
6741
- };
6742
6830
  var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, identityResponse, parsingCachedResponse) {
6743
6831
  // when parsing a response that has already been cached, simply return instead of attempting another cache
6744
6832
  if (parsingCachedResponse) {
@@ -7896,8 +7984,7 @@ var mParticle = (function () {
7896
7984
  }
7897
7985
  if (identityResponse.status === HTTP_OK) {
7898
7986
  if (getFeatureFlag(CacheIdentity)) {
7899
- var identityResponseForCache = xhrIdentityResponseAdapter(identityResponse);
7900
- cacheOrClearIdCache(method, knownIdentities, self.idCache, identityResponseForCache, parsingCachedResponse);
7987
+ cacheOrClearIdCache(method, knownIdentities, self.idCache, identityResponse, parsingCachedResponse);
7901
7988
  }
7902
7989
  var incomingUser = self.IdentityAPI.getUser(identityApiResult.mpid);
7903
7990
  var incomingUIByName = incomingUser ? incomingUser.getUserIdentities().userIdentities : {};
@@ -8934,7 +9021,6 @@ var mParticle = (function () {
8934
9021
  return [3 /*break*/, 8];
8935
9022
  case 7:
8936
9023
  xhrResponse = response;
8937
- // debugger;
8938
9024
  aliasResponseBody = xhrResponse.responseText ? JSON.parse(xhrResponse.responseText) : '';
8939
9025
  _b.label = 8;
8940
9026
  case 8:
@@ -8989,55 +9075,228 @@ var mParticle = (function () {
8989
9075
  return _ref.apply(this, arguments);
8990
9076
  };
8991
9077
  }();
8992
- this.sendIdentityRequest = function (identityApiRequest, method, callback, originalIdentityApiData, parseIdentityResponse, mpid, knownIdentities) {
8993
- var xhr,
8994
- previousMPID,
8995
- xhrCallback = function xhrCallback() {
8996
- if (xhr.readyState === 4) {
8997
- // https://go.mparticle.com/work/SQDSDKS-6368
8998
- mpInstance.Logger.verbose('Received ' + xhr.statusText + ' from server');
8999
-
9000
- // https://go.mparticle.com/work/SQDSDKS-6565
9001
- var identityResponse = xhrIdentityResponseAdapter(xhr);
9002
- parseIdentityResponse(identityResponse, previousMPID, callback, originalIdentityApiData, method, knownIdentities, false);
9078
+ this.sendIdentityRequest = /*#__PURE__*/function () {
9079
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(identityApiRequest, method, callback, originalIdentityApiData, parseIdentityResponse, mpid, knownIdentities) {
9080
+ var _mpInstance$Logger, verbose, error, invokeCallback, previousMPID, uploadUrl, uploader, fetchPayload, response, identityResponse, responseBody;
9081
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
9082
+ while (1) switch (_context2.prev = _context2.next) {
9083
+ case 0:
9084
+ _mpInstance$Logger = mpInstance.Logger, verbose = _mpInstance$Logger.verbose, error = _mpInstance$Logger.error;
9085
+ invokeCallback = mpInstance._Helpers.invokeCallback;
9086
+ verbose(Messages$1.InformationMessages.SendIdentityBegin);
9087
+ if (identityApiRequest) {
9088
+ _context2.next = 6;
9089
+ break;
9090
+ }
9091
+ error(Messages$1.ErrorMessages.APIRequestEmpty);
9092
+ return _context2.abrupt("return");
9093
+ case 6:
9094
+ verbose(Messages$1.InformationMessages.SendIdentityHttp);
9095
+ if (!mpInstance._Store.identityCallInFlight) {
9096
+ _context2.next = 10;
9097
+ break;
9098
+ }
9099
+ invokeCallback(callback, HTTPCodes$1.activeIdentityRequest, 'There is currently an Identity request processing. Please wait for this to return before requesting again');
9100
+ return _context2.abrupt("return");
9101
+ case 10:
9102
+ previousMPID = mpid || null;
9103
+ uploadUrl = this.getUploadUrl(method, mpid);
9104
+ uploader = window.fetch ? new FetchUploader(uploadUrl) : new XHRUploader(uploadUrl);
9105
+ fetchPayload = {
9106
+ method: 'post',
9107
+ headers: {
9108
+ Accept: 'text/plain;charset=UTF-8',
9109
+ 'Content-Type': 'application/json',
9110
+ 'x-mp-key': mpInstance._Store.devToken
9111
+ },
9112
+ body: JSON.stringify(identityApiRequest)
9113
+ };
9114
+ _context2.prev = 14;
9115
+ mpInstance._Store.identityCallInFlight = true;
9116
+ _context2.next = 18;
9117
+ return uploader.upload(fetchPayload);
9118
+ case 18:
9119
+ response = _context2.sent;
9120
+ if (!response.json) {
9121
+ _context2.next = 26;
9122
+ break;
9123
+ }
9124
+ _context2.next = 22;
9125
+ return response.json();
9126
+ case 22:
9127
+ responseBody = _context2.sent;
9128
+ identityResponse = this.getIdentityResponseFromFetch(response, responseBody);
9129
+ _context2.next = 27;
9130
+ break;
9131
+ case 26:
9132
+ identityResponse = this.getIdentityResponseFromXHR(response);
9133
+ case 27:
9134
+ verbose('Received Identity Response from server: ' + JSON.stringify(identityResponse.responseText));
9135
+ parseIdentityResponse(identityResponse, previousMPID, callback, originalIdentityApiData, method, knownIdentities, false);
9136
+ _context2.next = 36;
9137
+ break;
9138
+ case 31:
9139
+ _context2.prev = 31;
9140
+ _context2.t0 = _context2["catch"](14);
9141
+ mpInstance._Store.identityCallInFlight = false;
9142
+ invokeCallback(callback, HTTPCodes$1.noHttpCoverage, _context2.t0);
9143
+ error('Error sending identity request to servers' + ' - ' + _context2.t0);
9144
+ case 36:
9145
+ case "end":
9146
+ return _context2.stop();
9003
9147
  }
9004
- };
9005
- mpInstance.Logger.verbose(Messages$1.InformationMessages.SendIdentityBegin);
9006
- if (!identityApiRequest) {
9007
- mpInstance.Logger.error(Messages$1.ErrorMessages.APIRequestEmpty);
9008
- return;
9148
+ }, _callee2, this, [[14, 31]]);
9149
+ }));
9150
+ return function (_x3, _x4, _x5, _x6, _x7, _x8, _x9) {
9151
+ return _ref2.apply(this, arguments);
9152
+ };
9153
+ }();
9154
+ this.getUploadUrl = function (method, mpid) {
9155
+ var uploadServiceUrl = mpInstance._Helpers.createServiceUrl(mpInstance._Store.SDKConfig.identityUrl);
9156
+ var uploadUrl = method === Modify ? uploadServiceUrl + mpid + '/' + method : uploadServiceUrl + method;
9157
+ return uploadUrl;
9158
+ };
9159
+ this.getIdentityResponseFromFetch = function (response, responseBody) {
9160
+ return {
9161
+ status: response.status,
9162
+ responseText: responseBody,
9163
+ cacheMaxAge: parseInt(response.headers.get(CACHE_HEADER)) || 0,
9164
+ expireTimestamp: 0
9165
+ };
9166
+ };
9167
+ this.getIdentityResponseFromXHR = function (response) {
9168
+ return {
9169
+ status: response.status,
9170
+ responseText: response.responseText ? JSON.parse(response.responseText) : {},
9171
+ cacheMaxAge: parseNumber(response.getResponseHeader(CACHE_HEADER) || ''),
9172
+ expireTimestamp: 0
9173
+ };
9174
+ };
9175
+ }
9176
+
9177
+ // Facebook Click ID has specific formatting rules
9178
+ // The formatted ClickID value must be of the form version.subdomainIndex.creationTime.<fbclid>, where:
9179
+ // - version is always this prefix: fb
9180
+ // - subdomainIndex is which domain the cookie is defined on ('com' = 0, 'example.com' = 1, 'www.example.com' = 2)
9181
+ // - creationTime is the UNIX time since epoch in milliseconds when the _fbc was stored. If you don't save the _fbc cookie, use the timestamp when you first observed or received this fbclid value
9182
+ // - <fbclid> is the value for the fbclid query parameter in the page URL.
9183
+ // https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/fbp-and-fbc
9184
+ var facebookClickIdProcessor = function facebookClickIdProcessor(clickId, url, timestamp) {
9185
+ if (!clickId || !url) {
9186
+ return '';
9187
+ }
9188
+ var urlSegments = url === null || url === void 0 ? void 0 : url.split('//');
9189
+ if (!urlSegments) {
9190
+ return '';
9191
+ }
9192
+ var urlParts = urlSegments[1].split('/');
9193
+ var domainParts = urlParts[0].split('.');
9194
+ var subdomainIndex = 1;
9195
+ // The rules for subdomainIndex are for parsing the domain portion
9196
+ // of the URL for cookies, but in this case we are parsing the URL
9197
+ // itself, so we can ignore the use of 0 for 'com'
9198
+ if (domainParts.length >= 3) {
9199
+ subdomainIndex = 2;
9200
+ }
9201
+ // If timestamp is not provided, use the current time
9202
+ var _timestamp = timestamp || Date.now();
9203
+ return "fb.".concat(subdomainIndex, ".").concat(_timestamp, ".").concat(clickId);
9204
+ };
9205
+ var integrationMapping = {
9206
+ fbclid: {
9207
+ mappedKey: 'Facebook.ClickId',
9208
+ processor: facebookClickIdProcessor
9209
+ },
9210
+ _fbp: {
9211
+ mappedKey: 'Facebook.BrowserId'
9212
+ },
9213
+ _fbc: {
9214
+ mappedKey: 'Facebook.ClickId'
9215
+ }
9216
+ };
9217
+ var IntegrationCapture = /** @class */function () {
9218
+ function IntegrationCapture() {
9219
+ this.initialTimestamp = Date.now();
9220
+ }
9221
+ /**
9222
+ * Captures Integration Ids from cookies and query params and stores them in clickIds object
9223
+ */
9224
+ IntegrationCapture.prototype.capture = function () {
9225
+ var queryParams = this.captureQueryParams() || {};
9226
+ var cookies = this.captureCookies() || {};
9227
+ // Exclude _fbc if fbclid is present
9228
+ // https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/fbp-and-fbc#retrieve-from-fbclid-url-query-parameter
9229
+ if (queryParams['fbclid'] && cookies['_fbc']) {
9230
+ delete cookies['_fbc'];
9009
9231
  }
9010
- mpInstance.Logger.verbose(Messages$1.InformationMessages.SendIdentityHttp);
9011
- xhr = mpInstance._Helpers.createXHR(xhrCallback);
9012
- if (xhr) {
9013
- try {
9014
- if (mpInstance._Store.identityCallInFlight) {
9015
- mpInstance._Helpers.invokeCallback(callback, HTTPCodes$1.activeIdentityRequest, 'There is currently an Identity request processing. Please wait for this to return before requesting again');
9016
- } else {
9017
- previousMPID = mpid || null;
9018
- if (method === Modify) {
9019
- xhr.open('post', mpInstance._Helpers.createServiceUrl(mpInstance._Store.SDKConfig.identityUrl) + mpid + '/' + method);
9020
- } else {
9021
- xhr.open('post', mpInstance._Helpers.createServiceUrl(mpInstance._Store.SDKConfig.identityUrl) + method);
9022
- }
9023
- xhr.setRequestHeader('Content-Type', 'application/json');
9024
- xhr.setRequestHeader('x-mp-key', mpInstance._Store.devToken);
9025
- mpInstance._Store.identityCallInFlight = true;
9026
- xhr.send(JSON.stringify(identityApiRequest));
9027
- }
9028
- } catch (e) {
9029
- mpInstance._Store.identityCallInFlight = false;
9030
- mpInstance._Helpers.invokeCallback(callback, HTTPCodes$1.noHttpCoverage, e);
9031
- mpInstance.Logger.error('Error sending identity request to servers with status code ' + xhr.status + ' - ' + e);
9232
+ this.clickIds = __assign(__assign(__assign({}, this.clickIds), queryParams), cookies);
9233
+ };
9234
+ /**
9235
+ * Captures cookies based on the integration ID mapping.
9236
+ */
9237
+ IntegrationCapture.prototype.captureCookies = function () {
9238
+ var cookies = getCookies(Object.keys(integrationMapping));
9239
+ return this.applyProcessors(cookies);
9240
+ };
9241
+ /**
9242
+ * Captures query parameters based on the integration ID mapping.
9243
+ */
9244
+ IntegrationCapture.prototype.captureQueryParams = function () {
9245
+ var queryParams = this.getQueryParams();
9246
+ return this.applyProcessors(queryParams, getHref(), this.initialTimestamp);
9247
+ };
9248
+ /**
9249
+ * Gets the query parameters based on the integration ID mapping.
9250
+ * @returns {Dictionary<string>} The query parameters.
9251
+ */
9252
+ IntegrationCapture.prototype.getQueryParams = function () {
9253
+ return queryStringParser(getHref(), Object.keys(integrationMapping));
9254
+ };
9255
+ /**
9256
+ * Converts captured click IDs to custom flags for SDK events.
9257
+ * @returns {SDKEventCustomFlags} The custom flags.
9258
+ */
9259
+ IntegrationCapture.prototype.getClickIdsAsCustomFlags = function () {
9260
+ var _a;
9261
+ var customFlags = {};
9262
+ if (!this.clickIds) {
9263
+ return customFlags;
9264
+ }
9265
+ for (var _i = 0, _b = Object.entries(this.clickIds); _i < _b.length; _i++) {
9266
+ var _c = _b[_i],
9267
+ key = _c[0],
9268
+ value = _c[1];
9269
+ var mappedKey = (_a = integrationMapping[key]) === null || _a === void 0 ? void 0 : _a.mappedKey;
9270
+ if (!isEmpty(mappedKey)) {
9271
+ customFlags[mappedKey] = value;
9032
9272
  }
9033
9273
  }
9274
+ return customFlags;
9034
9275
  };
9035
- }
9276
+ IntegrationCapture.prototype.applyProcessors = function (clickIds, url, timestamp) {
9277
+ var _a;
9278
+ var processedClickIds = {};
9279
+ for (var _i = 0, _b = Object.entries(clickIds); _i < _b.length; _i++) {
9280
+ var _c = _b[_i],
9281
+ key = _c[0],
9282
+ value = _c[1];
9283
+ var processor = (_a = integrationMapping[key]) === null || _a === void 0 ? void 0 : _a.processor;
9284
+ if (processor) {
9285
+ processedClickIds[key] = processor(value, url, timestamp);
9286
+ } else {
9287
+ processedClickIds[key] = value;
9288
+ }
9289
+ }
9290
+ return processedClickIds;
9291
+ };
9292
+ return IntegrationCapture;
9293
+ }();
9036
9294
 
9037
9295
  var Messages = Constants.Messages,
9038
9296
  HTTPCodes = Constants.HTTPCodes,
9039
9297
  FeatureFlags = Constants.FeatureFlags;
9040
- var ReportBatching = FeatureFlags.ReportBatching;
9298
+ var ReportBatching = FeatureFlags.ReportBatching,
9299
+ CaptureIntegrationSpecificIds = FeatureFlags.CaptureIntegrationSpecificIds;
9041
9300
  var StartingInitialization = Messages.InformationMessages.StartingInitialization;
9042
9301
 
9043
9302
  /**
@@ -9073,6 +9332,7 @@ var mParticle = (function () {
9073
9332
  integrationDelays: {},
9074
9333
  forwarderConstructors: []
9075
9334
  };
9335
+ this._IntegrationCapture = new IntegrationCapture();
9076
9336
 
9077
9337
  // required for forwarders once they reference the mparticle instance
9078
9338
  this.IdentityType = Types.IdentityType;
@@ -10013,6 +10273,9 @@ var mParticle = (function () {
10013
10273
  if (mpInstance._Helpers.getFeatureFlag(ReportBatching)) {
10014
10274
  mpInstance._ForwardingStatsUploader.startForwardingStatsTimer();
10015
10275
  }
10276
+ if (mpInstance._Helpers.getFeatureFlag(CaptureIntegrationSpecificIds)) {
10277
+ mpInstance._IntegrationCapture.capture();
10278
+ }
10016
10279
  mpInstance._Forwarders.processForwarders(config, mpInstance._APIClient.prepareForwardingStats);
10017
10280
  mpInstance._Forwarders.processPixelConfigs(config);
10018
10281
 
@@ -10175,8 +10438,9 @@ var mParticle = (function () {
10175
10438
  processPreloadedItem(readyQueueItem);
10176
10439
  }
10177
10440
  });
10178
- return [];
10179
10441
  }
10442
+ // https://go.mparticle.com/work/SQDSDKS-6835
10443
+ return [];
10180
10444
  }
10181
10445
  function queueIfNotInitialized(func, self) {
10182
10446
  if (!self.isInitialized()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.28.3",
3
+ "version": "2.29.1",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -54,7 +54,7 @@ export async function sendAliasRequest (mpInstance: MParticleWebSDK, aliasReques
54
54
  // https://go.mparticle.com/work/SQDSDKS-6568
55
55
  // XHRUploader returns the response as a string that we need to parse
56
56
  const xhrResponse = response as unknown as XMLHttpRequest;
57
- // debugger;
57
+
58
58
  aliasResponseBody = xhrResponse.responseText
59
59
  ? JSON.parse(xhrResponse.responseText)
60
60
  : '';
package/src/constants.ts CHANGED
@@ -174,6 +174,7 @@ const Constants = {
174
174
  DirectUrlRouting: 'directURLRouting',
175
175
  CacheIdentity: 'cacheIdentity',
176
176
  AudienceAPI: 'audienceAPI',
177
+ CaptureIntegrationSpecificIds: 'captureIntegrationSpecificIds',
177
178
  },
178
179
  DefaultInstance: 'default_instance',
179
180
  CCPAPurpose: 'data_sale_opt_out',
@@ -14,7 +14,7 @@ import {
14
14
  } from './identity-user-interfaces';
15
15
 
16
16
  const { Identify, Modify, Login, Logout } = Constants.IdentityMethods;
17
- const CACHE_HEADER = 'x-mp-max-age' as const;
17
+ export const CACHE_HEADER = 'x-mp-max-age' as const;
18
18
 
19
19
  export type IdentityCache = BaseVault<Dictionary<ICachedIdentityCall>>;
20
20
 
@@ -40,33 +40,6 @@ export interface ICachedIdentityCall {
40
40
  expireTimestamp: number;
41
41
  }
42
42
 
43
- // https://go.mparticle.com/work/SQDSDKS-6568
44
- // Temporary adapter to convert the XMLHttpRequest response to the IIdentityResponse interface
45
- export const xhrIdentityResponseAdapter = (
46
- possiblyXhr: XMLHttpRequest | IIdentityResponse
47
- ): IIdentityResponse => {
48
- if (possiblyXhr.hasOwnProperty('expireTimestamp')) {
49
- // If there is an `expireTimestamp`, it is an IIdentityResponse object, so just return it. This indicates it was a previously cached value.
50
- return possiblyXhr as IIdentityResponse;
51
- } else {
52
- // If there is no `expireTimestamp`, then it is an XHR object and needs to be parsed.
53
- return {
54
- status: possiblyXhr.status,
55
-
56
- // Sometimes responseText can be an empty string, such as a 404 response
57
- responseText: (possiblyXhr as XMLHttpRequest).responseText
58
- ? JSON.parse((possiblyXhr as XMLHttpRequest).responseText)
59
- : {},
60
- cacheMaxAge: parseNumber(
61
- (possiblyXhr as XMLHttpRequest)?.getResponseHeader(
62
- CACHE_HEADER
63
- ) || ''
64
- ),
65
- expireTimestamp: 0,
66
- };
67
- }
68
- };
69
-
70
43
  export const cacheOrClearIdCache = (
71
44
  method: string,
72
45
  knownIdentities: IKnownIdentities,
@@ -55,7 +55,7 @@ export interface IIdentityAPIRequestData {
55
55
  context: string | null;
56
56
  environment: Environment;
57
57
  request_id: string;
58
- reqest_timestamp_unixtime_ms: number;
58
+ request_timestamp_unixtime_ms: number;
59
59
  previous_mpid: MPID | null;
60
60
  known_identities: IKnownIdentities;
61
61
  }
package/src/identity.js CHANGED
@@ -4,7 +4,6 @@ import {
4
4
  cacheOrClearIdCache,
5
5
  createKnownIdentities,
6
6
  tryCacheIdentity,
7
- xhrIdentityResponseAdapter,
8
7
  } from './identity-utils';
9
8
  import AudienceManager from './audienceManager';
10
9
  const { Messages, HTTPCodes, FeatureFlags, IdentityMethods } = Constants;
@@ -1514,14 +1513,11 @@ export default function Identity(mpInstance) {
1514
1513
 
1515
1514
  if (identityResponse.status === HTTP_OK) {
1516
1515
  if (getFeatureFlag(CacheIdentity)) {
1517
- const identityResponseForCache = xhrIdentityResponseAdapter(
1518
- identityResponse
1519
- );
1520
1516
  cacheOrClearIdCache(
1521
1517
  method,
1522
1518
  knownIdentities,
1523
1519
  self.idCache,
1524
- identityResponseForCache,
1520
+ identityResponse,
1525
1521
  parsingCachedResponse
1526
1522
  );
1527
1523
  }