@mparticle/web-sdk 2.26.7 → 2.26.9

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.26.7";
396
+ var version = "2.26.9";
397
397
 
398
398
  var Constants = {
399
399
  sdkVersion: version,
@@ -3912,23 +3912,7 @@ var mParticle = (function () {
3912
3912
  },
3913
3913
  // Placeholder for in-memory persistence model
3914
3914
  persistenceData: {
3915
- cu: null,
3916
- gs: {
3917
- sid: null,
3918
- ie: null,
3919
- sa: null,
3920
- ss: null,
3921
- dt: null,
3922
- av: null,
3923
- cgid: null,
3924
- das: null,
3925
- ia: null,
3926
- c: null,
3927
- csm: null,
3928
- les: null,
3929
- ssd: null
3930
- },
3931
- l: null
3915
+ gs: {}
3932
3916
  }
3933
3917
  };
3934
3918
  for (var key in defaultStore) {
@@ -4072,10 +4056,56 @@ var mParticle = (function () {
4072
4056
  }
4073
4057
  }
4074
4058
  }
4059
+ this._getFromPersistence = function (mpid, key) {
4060
+ if (!mpid) {
4061
+ return null;
4062
+ }
4063
+ _this.syncPersistenceData();
4064
+ if (_this.persistenceData && _this.persistenceData[mpid] && _this.persistenceData[mpid][key]) {
4065
+ return _this.persistenceData[mpid][key];
4066
+ } else {
4067
+ return null;
4068
+ }
4069
+ };
4070
+ this._setPersistence = function (mpid, key, value) {
4071
+ var _a;
4072
+ if (!mpid) {
4073
+ return;
4074
+ }
4075
+ _this.syncPersistenceData();
4076
+ if (_this.persistenceData) {
4077
+ if (_this.persistenceData[mpid]) {
4078
+ _this.persistenceData[mpid][key] = value;
4079
+ } else {
4080
+ _this.persistenceData[mpid] = (_a = {}, _a[key] = value, _a);
4081
+ }
4082
+ // Clear out persistence attributes that are empty
4083
+ // so that we don't upload empty or undefined values
4084
+ if (isObject(_this.persistenceData[mpid][key]) && isEmpty(_this.persistenceData[mpid][key])) {
4085
+ delete _this.persistenceData[mpid][key];
4086
+ }
4087
+ mpInstance._Persistence.savePersistence(_this.persistenceData);
4088
+ }
4089
+ };
4075
4090
  this.hasInvalidIdentifyRequest = function () {
4076
4091
  var identifyRequest = _this.SDKConfig.identifyRequest;
4077
4092
  return isObject(identifyRequest) && isObject(identifyRequest.userIdentities) && isEmpty(identifyRequest.userIdentities) || !identifyRequest;
4078
4093
  };
4094
+ this.getConsentState = function (mpid) {
4095
+ var fromMinifiedJsonObject = mpInstance._Consent.ConsentSerialization.fromMinifiedJsonObject;
4096
+ var serializedConsentState = _this._getFromPersistence(mpid, 'con');
4097
+ if (!isEmpty(serializedConsentState)) {
4098
+ return fromMinifiedJsonObject(serializedConsentState);
4099
+ }
4100
+ return null;
4101
+ };
4102
+ this.setConsentState = function (mpid, consentState) {
4103
+ var toMinifiedJsonObject = mpInstance._Consent.ConsentSerialization.toMinifiedJsonObject;
4104
+ // If ConsentState is null, we assume the intent is to clear out the consent state
4105
+ if (consentState || consentState === null) {
4106
+ _this._setPersistence(mpid, 'con', toMinifiedJsonObject(consentState));
4107
+ }
4108
+ };
4079
4109
  this.getDeviceId = function () {
4080
4110
  return _this.deviceId;
4081
4111
  };
@@ -4084,69 +4114,53 @@ var mParticle = (function () {
4084
4114
  _this.persistenceData.gs.das = deviceId;
4085
4115
  mpInstance._Persistence.update();
4086
4116
  };
4087
- this.addMpidToSessionHistory = function (mpid, previousMPID) {
4088
- var indexOfMPID = _this.currentSessionMPIDs.indexOf(mpid);
4089
- if (mpid && previousMPID !== mpid && indexOfMPID < 0) {
4090
- _this.currentSessionMPIDs.push(mpid);
4091
- return;
4092
- }
4093
- if (indexOfMPID >= 0) {
4094
- _this.currentSessionMPIDs = moveElementToEnd(_this.currentSessionMPIDs, indexOfMPID);
4095
- }
4096
- };
4097
4117
  this.getFirstSeenTime = function (mpid) {
4098
- if (!mpid) {
4099
- return null;
4100
- }
4101
- if (_this.persistenceData && _this.persistenceData[mpid] && _this.persistenceData[mpid].fst) {
4102
- return _this.persistenceData[mpid].fst;
4103
- } else {
4104
- return null;
4105
- }
4118
+ return _this._getFromPersistence(mpid, 'fst');
4106
4119
  };
4107
4120
  this.setFirstSeenTime = function (mpid, _time) {
4108
4121
  if (!mpid) {
4109
4122
  return;
4110
4123
  }
4111
4124
  var time = _time || new Date().getTime();
4112
- if (_this.persistenceData) {
4113
- if (!_this.persistenceData[mpid]) {
4114
- _this.persistenceData[mpid] = {};
4115
- }
4116
- if (!_this.persistenceData[mpid].fst) {
4117
- _this.persistenceData[mpid].fst = time;
4118
- mpInstance._Persistence.savePersistence(_this.persistenceData);
4119
- }
4120
- }
4125
+ _this._setPersistence(mpid, 'fst', time);
4121
4126
  };
4122
4127
  this.getLastSeenTime = function (mpid) {
4123
4128
  if (!mpid) {
4124
4129
  return null;
4125
4130
  }
4126
- // // https://go.mparticle.com/work/SQDSDKS-6315
4131
+ // https://go.mparticle.com/work/SQDSDKS-6315
4127
4132
  var currentUser = mpInstance.Identity.getCurrentUser();
4128
4133
  if (mpid === (currentUser === null || currentUser === void 0 ? void 0 : currentUser.getMPID())) {
4129
4134
  // if the mpid is the current user, its last seen time is the current time
4130
4135
  return new Date().getTime();
4131
- } else if (_this.persistenceData && _this.persistenceData[mpid] && _this.persistenceData[mpid].lst) {
4132
- return _this.persistenceData[mpid].lst;
4133
- } else {
4134
- return null;
4135
4136
  }
4137
+ return _this._getFromPersistence(mpid, 'lst');
4136
4138
  };
4137
4139
  this.setLastSeenTime = function (mpid, _time) {
4138
4140
  if (!mpid) {
4139
4141
  return;
4140
4142
  }
4141
4143
  var time = _time || new Date().getTime();
4142
- if (_this.persistenceData) {
4143
- if (!_this.persistenceData[mpid]) {
4144
- _this.persistenceData[mpid] = {};
4145
- }
4146
- if (!_this.persistenceData[mpid].lst) {
4147
- _this.persistenceData[mpid].lst = time;
4148
- mpInstance._Persistence.savePersistence(_this.persistenceData);
4149
- }
4144
+ _this._setPersistence(mpid, 'lst', time);
4145
+ };
4146
+ this.syncPersistenceData = function () {
4147
+ var persistenceData = mpInstance._Persistence.getPersistence();
4148
+ _this.persistenceData = mpInstance._Helpers.extend({}, _this.persistenceData, persistenceData);
4149
+ };
4150
+ this.getUserAttributes = function (mpid) {
4151
+ return _this._getFromPersistence(mpid, 'ua') || {};
4152
+ };
4153
+ this.setUserAttributes = function (mpid, userAttributes) {
4154
+ return _this._setPersistence(mpid, 'ua', userAttributes);
4155
+ };
4156
+ this.addMpidToSessionHistory = function (mpid, previousMPID) {
4157
+ var indexOfMPID = _this.currentSessionMPIDs.indexOf(mpid);
4158
+ if (mpid && previousMPID !== mpid && indexOfMPID < 0) {
4159
+ _this.currentSessionMPIDs.push(mpid);
4160
+ return;
4161
+ }
4162
+ if (indexOfMPID >= 0) {
4163
+ _this.currentSessionMPIDs = moveElementToEnd(_this.currentSessionMPIDs, indexOfMPID);
4150
4164
  }
4151
4165
  };
4152
4166
  this.nullifySession = function () {
@@ -4937,14 +4951,6 @@ var mParticle = (function () {
4937
4951
  return {};
4938
4952
  }
4939
4953
  };
4940
- this.getAllUserAttributes = function (mpid) {
4941
- var persistence = self.getPersistence();
4942
- if (persistence && persistence[mpid] && persistence[mpid].ua) {
4943
- return persistence[mpid].ua;
4944
- } else {
4945
- return {};
4946
- }
4947
- };
4948
4954
  this.getCartProducts = function (mpid) {
4949
4955
  var allCartProducts,
4950
4956
  cartProductsString = localStorage.getItem(mpInstance._Store.prodStorageName);
@@ -4981,24 +4987,6 @@ var mParticle = (function () {
4981
4987
  }
4982
4988
  }
4983
4989
  };
4984
- this.saveUserAttributesToPersistence = function (mpid, userAttributes) {
4985
- var persistence = self.getPersistence();
4986
- if (userAttributes) {
4987
- if (persistence) {
4988
- if (persistence[mpid]) {
4989
- // TODO: Investigate why setting this to UI still shows up as UA
4990
- // when running `mParticle.getInstance()._Persistence.getLocalStorage()`
4991
- // https://go.mparticle.com/work/SQDSDKS-5195
4992
- persistence[mpid].ui = userAttributes;
4993
- } else {
4994
- persistence[mpid] = {
4995
- ui: userAttributes
4996
- };
4997
- }
4998
- }
4999
- self.savePersistence(persistence);
5000
- }
5001
- };
5002
4990
  this.saveUserCookieSyncDatesToPersistence = function (mpid, csd) {
5003
4991
  if (csd) {
5004
4992
  var persistence = self.getPersistence();
@@ -5014,23 +5002,6 @@ var mParticle = (function () {
5014
5002
  self.savePersistence(persistence);
5015
5003
  }
5016
5004
  };
5017
- this.saveUserConsentStateToCookies = function (mpid, consentState) {
5018
- //it's currently not supported to set persistence
5019
- //for any MPID that's not the current one.
5020
- if (consentState || consentState === null) {
5021
- var persistence = self.getPersistence();
5022
- if (persistence) {
5023
- if (persistence[mpid]) {
5024
- persistence[mpid].con = mpInstance._Consent.ConsentSerialization.toMinifiedJsonObject(consentState);
5025
- } else {
5026
- persistence[mpid] = {
5027
- con: mpInstance._Consent.ConsentSerialization.toMinifiedJsonObject(consentState)
5028
- };
5029
- }
5030
- self.savePersistence(persistence);
5031
- }
5032
- }
5033
- };
5034
5005
  this.swapCurrentUser = function (previousMPID, currentMPID, currentSessionMPIDs) {
5035
5006
  if (previousMPID && currentMPID && previousMPID !== currentMPID) {
5036
5007
  var persistence = self.getPersistence();
@@ -5068,14 +5039,6 @@ var mParticle = (function () {
5068
5039
  var persistence = this.useLocalStorage() ? this.getLocalStorage() : this.getCookie();
5069
5040
  return persistence;
5070
5041
  };
5071
- this.getConsentState = function (mpid) {
5072
- var persistence = self.getPersistence();
5073
- if (persistence && persistence[mpid] && persistence[mpid].con) {
5074
- return mpInstance._Consent.ConsentSerialization.fromMinifiedJsonObject(persistence[mpid].con);
5075
- } else {
5076
- return null;
5077
- }
5078
- };
5079
5042
  this.getFirstSeenTime = function (mpid) {
5080
5043
  if (!mpid) {
5081
5044
  return null;
@@ -5490,7 +5453,7 @@ var mParticle = (function () {
5490
5453
  },
5491
5454
  getAllUserAttributes: function getAllUserAttributes() {
5492
5455
  var userAttributesCopy = {};
5493
- var userAttributes = mpInstance._Persistence.getAllUserAttributes(mpid);
5456
+ var userAttributes = mpInstance._Store.getUserAttributes(mpid);
5494
5457
  if (userAttributes) {
5495
5458
  for (var prop in userAttributes) {
5496
5459
  if (userAttributes.hasOwnProperty(prop)) {
@@ -7071,8 +7034,9 @@ var mParticle = (function () {
7071
7034
  * @param {String} key
7072
7035
  * @param {String} value
7073
7036
  */
7037
+ // https://go.mparticle.com/work/SQDSDKS-4576
7038
+ // https://go.mparticle.com/work/SQDSDKS-6373
7074
7039
  setUserAttribute: function setUserAttribute(key, newValue) {
7075
- var cookies, userAttributes, previousUserAttributeValue, isNewAttribute;
7076
7040
  mpInstance._SessionManager.resetSessionTimer();
7077
7041
  if (mpInstance._Helpers.canLog()) {
7078
7042
  if (!mpInstance._Helpers.Validators.isValidAttributeValue(newValue)) {
@@ -7089,8 +7053,9 @@ var mParticle = (function () {
7089
7053
  value: newValue
7090
7054
  }));
7091
7055
  } else {
7092
- cookies = mpInstance._Persistence.getPersistence();
7093
- userAttributes = this.getAllUserAttributes();
7056
+ var userAttributes = this.getAllUserAttributes();
7057
+ var previousUserAttributeValue;
7058
+ var isNewAttribute;
7094
7059
  var existingProp = mpInstance._Helpers.findKeyInObject(userAttributes, key);
7095
7060
  if (existingProp) {
7096
7061
  isNewAttribute = false;
@@ -7100,10 +7065,7 @@ var mParticle = (function () {
7100
7065
  isNewAttribute = true;
7101
7066
  }
7102
7067
  userAttributes[key] = newValue;
7103
- if (cookies && cookies[mpid]) {
7104
- cookies[mpid].ua = userAttributes;
7105
- mpInstance._Persistence.savePersistence(cookies, mpid);
7106
- }
7068
+ mpInstance._Store.setUserAttributes(mpid, userAttributes);
7107
7069
  self.sendUserAttributeChangeEvent(key, newValue, previousUserAttributeValue, isNewAttribute, false, this);
7108
7070
  mpInstance._Forwarders.initForwarders(self.IdentityAPI.getCurrentUser().getUserIdentities(), mpInstance._APIClient.prepareForwardingStats);
7109
7071
  mpInstance._Forwarders.handleForwarderUserAttributes('setUserAttribute', key, newValue);
@@ -7115,6 +7077,7 @@ var mParticle = (function () {
7115
7077
  * @method setUserAttributes
7116
7078
  * @param {Object} user attribute object with keys of the attribute type, and value of the attribute value
7117
7079
  */
7080
+ // https://go.mparticle.com/work/SQDSDKS-6373
7118
7081
  setUserAttributes: function setUserAttributes(userAttributes) {
7119
7082
  mpInstance._SessionManager.resetSessionTimer();
7120
7083
  if (isObject(userAttributes)) {
@@ -7170,8 +7133,8 @@ var mParticle = (function () {
7170
7133
  * @param {String} key
7171
7134
  * @param {Array} value an array of values
7172
7135
  */
7136
+ // https://go.mparticle.com/work/SQDSDKS-6373
7173
7137
  setUserAttributeList: function setUserAttributeList(key, newValue) {
7174
- var cookies, userAttributes, previousUserAttributeValue, isNewAttribute, userAttributeChange;
7175
7138
  mpInstance._SessionManager.resetSessionTimer();
7176
7139
  if (!mpInstance._Helpers.Validators.isValidKeyValue(key)) {
7177
7140
  mpInstance.Logger.error(Messages$2.ErrorMessages.BadKey);
@@ -7188,8 +7151,10 @@ var mParticle = (function () {
7188
7151
  value: arrayCopy
7189
7152
  }));
7190
7153
  } else {
7191
- cookies = mpInstance._Persistence.getPersistence();
7192
- userAttributes = this.getAllUserAttributes();
7154
+ var userAttributes = this.getAllUserAttributes();
7155
+ var previousUserAttributeValue;
7156
+ var isNewAttribute;
7157
+ var userAttributeChange;
7193
7158
  var existingProp = mpInstance._Helpers.findKeyInObject(userAttributes, key);
7194
7159
  if (existingProp) {
7195
7160
  isNewAttribute = false;
@@ -7199,12 +7164,9 @@ var mParticle = (function () {
7199
7164
  isNewAttribute = true;
7200
7165
  }
7201
7166
  userAttributes[key] = arrayCopy;
7202
- if (cookies && cookies[mpid]) {
7203
- cookies[mpid].ua = userAttributes;
7204
- mpInstance._Persistence.savePersistence(cookies, mpid);
7205
- }
7167
+ mpInstance._Store.setUserAttributes(mpid, userAttributes);
7206
7168
 
7207
- // If the new attributeList length is different previous, then there is a change event.
7169
+ // If the new attributeList length is different than the previous, then there is a change event.
7208
7170
  // Loop through new attributes list, see if they are all in the same index as previous user attributes list
7209
7171
  // If there are any changes, break, and immediately send a userAttributeChangeEvent with full array as a value
7210
7172
  if (!previousUserAttributeValue || !Array.isArray(previousUserAttributeValue)) {
@@ -7270,8 +7232,9 @@ var mParticle = (function () {
7270
7232
  * @return {Object} an object of all user attributes. Example: { attr1: 'value1', attr2: ['a', 'b', 'c'] }
7271
7233
  */
7272
7234
  getAllUserAttributes: function getAllUserAttributes() {
7235
+ var getUserAttributes = mpInstance._Store.getUserAttributes;
7273
7236
  var userAttributesCopy = {};
7274
- var userAttributes = mpInstance._Persistence.getAllUserAttributes(mpid);
7237
+ var userAttributes = getUserAttributes(mpid);
7275
7238
  if (userAttributes) {
7276
7239
  for (var prop in userAttributes) {
7277
7240
  if (userAttributes.hasOwnProperty(prop)) {
@@ -7300,7 +7263,7 @@ var mParticle = (function () {
7300
7263
  * @return a ConsentState object
7301
7264
  */
7302
7265
  getConsentState: function getConsentState() {
7303
- return mpInstance._Persistence.getConsentState(mpid);
7266
+ return mpInstance._Store.getConsentState(mpid);
7304
7267
  },
7305
7268
  /**
7306
7269
  * Sets the Consent State stored locally for this user.
@@ -7308,7 +7271,7 @@ var mParticle = (function () {
7308
7271
  * @param {Object} consent state
7309
7272
  */
7310
7273
  setConsentState: function setConsentState(state) {
7311
- mpInstance._Persistence.saveUserConsentStateToCookies(mpid, state);
7274
+ mpInstance._Store.setConsentState(mpid, state);
7312
7275
  mpInstance._Forwarders.initForwarders(this.getUserIdentities().userIdentities, mpInstance._APIClient.prepareForwardingStats);
7313
7276
  mpInstance._CookieSyncManager.attemptCookieSync(null, this.getMPID());
7314
7277
  },
@@ -7516,6 +7479,7 @@ var mParticle = (function () {
7516
7479
  // https://go.mparticle.com/work/SQDSDKS-6041
7517
7480
  mpInstance._Persistence.saveUserIdentitiesToPersistence(identityApiResult.mpid, newIdentitiesByType);
7518
7481
  mpInstance._Persistence.update();
7482
+ mpInstance._Store.syncPersistenceData();
7519
7483
  mpInstance._Persistence.findPrevCookiesBasedOnUI(identityApiData);
7520
7484
 
7521
7485
  // https://go.mparticle.com/work/SQDSDKS-6357
@@ -9488,6 +9452,7 @@ var mParticle = (function () {
9488
9452
 
9489
9453
  // Load any settings/identities/attributes from cookie or localStorage
9490
9454
  mpInstance._Persistence.initializeStorage();
9455
+ mpInstance._Store.syncPersistenceData();
9491
9456
 
9492
9457
  // Set up user identitiy variables for later use
9493
9458
  var currentUser = mpInstance.Identity.getCurrentUser();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.26.7",
3
+ "version": "2.26.9",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -68,9 +68,7 @@ export default function filteredMparticleUser(
68
68
  },
69
69
  getAllUserAttributes: function() {
70
70
  var userAttributesCopy = {};
71
- var userAttributes = mpInstance._Persistence.getAllUserAttributes(
72
- mpid
73
- );
71
+ var userAttributes = mpInstance._Store.getUserAttributes(mpid);
74
72
 
75
73
  if (userAttributes) {
76
74
  for (var prop in userAttributes) {
@@ -62,6 +62,10 @@ export interface IUserIdentityChangeEvent extends BaseEvent {
62
62
  userIdentityChanges: ISDKUserIdentityChanges;
63
63
  }
64
64
 
65
+ export interface ISDKUserAttributes {
66
+ [key: string]: string | string[] | null;
67
+ }
68
+
65
69
  export interface ISDKUserAttributeChangeData {
66
70
  UserAttributeName: string;
67
71
  New: string;
package/src/identity.js CHANGED
@@ -866,12 +866,9 @@ export default function Identity(mpInstance) {
866
866
  * @param {String} key
867
867
  * @param {String} value
868
868
  */
869
+ // https://go.mparticle.com/work/SQDSDKS-4576
870
+ // https://go.mparticle.com/work/SQDSDKS-6373
869
871
  setUserAttribute: function(key, newValue) {
870
- var cookies,
871
- userAttributes,
872
- previousUserAttributeValue,
873
- isNewAttribute;
874
-
875
872
  mpInstance._SessionManager.resetSessionTimer();
876
873
 
877
874
  if (mpInstance._Helpers.canLog()) {
@@ -896,11 +893,11 @@ export default function Identity(mpInstance) {
896
893
  JSON.stringify({ key: key, value: newValue })
897
894
  );
898
895
  } else {
899
- cookies = mpInstance._Persistence.getPersistence();
900
-
901
- userAttributes = this.getAllUserAttributes();
896
+ const userAttributes = this.getAllUserAttributes();
897
+ let previousUserAttributeValue;
898
+ let isNewAttribute;
902
899
 
903
- var existingProp = mpInstance._Helpers.findKeyInObject(
900
+ const existingProp = mpInstance._Helpers.findKeyInObject(
904
901
  userAttributes,
905
902
  key
906
903
  );
@@ -915,13 +912,10 @@ export default function Identity(mpInstance) {
915
912
  }
916
913
 
917
914
  userAttributes[key] = newValue;
918
- if (cookies && cookies[mpid]) {
919
- cookies[mpid].ua = userAttributes;
920
- mpInstance._Persistence.savePersistence(
921
- cookies,
922
- mpid
923
- );
924
- }
915
+ mpInstance._Store.setUserAttributes(
916
+ mpid,
917
+ userAttributes
918
+ );
925
919
 
926
920
  self.sendUserAttributeChangeEvent(
927
921
  key,
@@ -949,6 +943,7 @@ export default function Identity(mpInstance) {
949
943
  * @method setUserAttributes
950
944
  * @param {Object} user attribute object with keys of the attribute type, and value of the attribute value
951
945
  */
946
+ // https://go.mparticle.com/work/SQDSDKS-6373
952
947
  setUserAttributes: function(userAttributes) {
953
948
  mpInstance._SessionManager.resetSessionTimer();
954
949
  if (isObject(userAttributes)) {
@@ -1036,13 +1031,8 @@ export default function Identity(mpInstance) {
1036
1031
  * @param {String} key
1037
1032
  * @param {Array} value an array of values
1038
1033
  */
1034
+ // https://go.mparticle.com/work/SQDSDKS-6373
1039
1035
  setUserAttributeList: function(key, newValue) {
1040
- var cookies,
1041
- userAttributes,
1042
- previousUserAttributeValue,
1043
- isNewAttribute,
1044
- userAttributeChange;
1045
-
1046
1036
  mpInstance._SessionManager.resetSessionTimer();
1047
1037
 
1048
1038
  if (!mpInstance._Helpers.Validators.isValidKeyValue(key)) {
@@ -1058,7 +1048,7 @@ export default function Identity(mpInstance) {
1058
1048
  return;
1059
1049
  }
1060
1050
 
1061
- var arrayCopy = newValue.slice();
1051
+ const arrayCopy = newValue.slice();
1062
1052
 
1063
1053
  if (mpInstance._Store.webviewBridgeEnabled) {
1064
1054
  mpInstance._NativeSdkHelpers.sendToNative(
@@ -1066,11 +1056,12 @@ export default function Identity(mpInstance) {
1066
1056
  JSON.stringify({ key: key, value: arrayCopy })
1067
1057
  );
1068
1058
  } else {
1069
- cookies = mpInstance._Persistence.getPersistence();
1070
-
1071
- userAttributes = this.getAllUserAttributes();
1059
+ const userAttributes = this.getAllUserAttributes();
1060
+ let previousUserAttributeValue;
1061
+ let isNewAttribute;
1062
+ let userAttributeChange;
1072
1063
 
1073
- var existingProp = mpInstance._Helpers.findKeyInObject(
1064
+ const existingProp = mpInstance._Helpers.findKeyInObject(
1074
1065
  userAttributes,
1075
1066
  key
1076
1067
  );
@@ -1085,12 +1076,9 @@ export default function Identity(mpInstance) {
1085
1076
  }
1086
1077
 
1087
1078
  userAttributes[key] = arrayCopy;
1088
- if (cookies && cookies[mpid]) {
1089
- cookies[mpid].ua = userAttributes;
1090
- mpInstance._Persistence.savePersistence(cookies, mpid);
1091
- }
1079
+ mpInstance._Store.setUserAttributes(mpid, userAttributes);
1092
1080
 
1093
- // If the new attributeList length is different previous, then there is a change event.
1081
+ // If the new attributeList length is different than the previous, then there is a change event.
1094
1082
  // Loop through new attributes list, see if they are all in the same index as previous user attributes list
1095
1083
  // If there are any changes, break, and immediately send a userAttributeChangeEvent with full array as a value
1096
1084
  if (
@@ -1194,13 +1182,12 @@ export default function Identity(mpInstance) {
1194
1182
  * @return {Object} an object of all user attributes. Example: { attr1: 'value1', attr2: ['a', 'b', 'c'] }
1195
1183
  */
1196
1184
  getAllUserAttributes: function() {
1197
- var userAttributesCopy = {};
1198
- var userAttributes = mpInstance._Persistence.getAllUserAttributes(
1199
- mpid
1200
- );
1185
+ const { getUserAttributes } = mpInstance._Store;
1186
+ const userAttributesCopy = {};
1187
+ const userAttributes = getUserAttributes(mpid);
1201
1188
 
1202
1189
  if (userAttributes) {
1203
- for (var prop in userAttributes) {
1190
+ for (const prop in userAttributes) {
1204
1191
  if (userAttributes.hasOwnProperty(prop)) {
1205
1192
  if (Array.isArray(userAttributes[prop])) {
1206
1193
  userAttributesCopy[prop] = userAttributes[
@@ -1233,7 +1220,7 @@ export default function Identity(mpInstance) {
1233
1220
  * @return a ConsentState object
1234
1221
  */
1235
1222
  getConsentState: function() {
1236
- return mpInstance._Persistence.getConsentState(mpid);
1223
+ return mpInstance._Store.getConsentState(mpid);
1237
1224
  },
1238
1225
  /**
1239
1226
  * Sets the Consent State stored locally for this user.
@@ -1241,10 +1228,7 @@ export default function Identity(mpInstance) {
1241
1228
  * @param {Object} consent state
1242
1229
  */
1243
1230
  setConsentState: function(state) {
1244
- mpInstance._Persistence.saveUserConsentStateToCookies(
1245
- mpid,
1246
- state
1247
- );
1231
+ mpInstance._Store.setConsentState(mpid, state);
1248
1232
  mpInstance._Forwarders.initForwarders(
1249
1233
  this.getUserIdentities().userIdentities,
1250
1234
  mpInstance._APIClient.prepareForwardingStats
@@ -1610,6 +1594,7 @@ export default function Identity(mpInstance) {
1610
1594
  newIdentitiesByType
1611
1595
  );
1612
1596
  mpInstance._Persistence.update();
1597
+ mpInstance._Store.syncPersistenceData();
1613
1598
 
1614
1599
  mpInstance._Persistence.findPrevCookiesBasedOnUI(
1615
1600
  identityApiData
@@ -1310,6 +1310,7 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1310
1310
 
1311
1311
  // Load any settings/identities/attributes from cookie or localStorage
1312
1312
  mpInstance._Persistence.initializeStorage();
1313
+ mpInstance._Store.syncPersistenceData();
1313
1314
 
1314
1315
  // Set up user identitiy variables for later use
1315
1316
  const currentUser = mpInstance.Identity.getCurrentUser();
@@ -1,7 +1,6 @@
1
1
  import { Context } from '@mparticle/event-models';
2
2
  import {
3
3
  AllUserAttributes,
4
- ConsentState,
5
4
  IdentityApiData,
6
5
  MPID,
7
6
  Product,
@@ -14,9 +13,9 @@ import {
14
13
  SessionAttributes,
15
14
  } from './store';
16
15
  import { Dictionary } from './utils';
16
+ import { IMinifiedConsentJSONObject } from './consent';
17
17
  import { UserAttributes } from './identity-user-interfaces';
18
18
 
19
- export type CookieSyncDate = Dictionary<string>;
20
19
  export type UploadsTable = Dictionary<any>;
21
20
  export interface iForwardingStatsBatches {
22
21
  uploadsTable: UploadsTable;
@@ -46,7 +45,7 @@ export interface IPersistenceMinified extends Dictionary {
46
45
 
47
46
  // Persistence Minified can also store optional dictionaries with
48
47
  // an idex of MPID
49
- // [mpid: MPID]: Dictionary<any>;
48
+ // [mpid: MPID]: Dictionary<IUserPersistenceMinified>;
50
49
 
51
50
  // For Example:
52
51
  // {
@@ -68,14 +67,34 @@ export interface IPersistenceMinified extends Dictionary {
68
67
  // },
69
68
  // l: false,
70
69
  // MPID1: {
71
- // csd: [],
70
+ // csd: {
71
+ // [moduleid]: 1234567890,
72
+ // },
72
73
  // ui: {
73
74
  // customerid: '12346',
74
75
  // },
76
+ // ua: {
77
+ // age '42',
78
+ // },
75
79
  // },
76
80
  // };
77
81
  }
78
82
 
83
+ export type CookieSyncDate = Dictionary<number>;
84
+
85
+ export interface IUserPersistenceMinified extends Dictionary {
86
+ csd: CookieSyncDate; // Cookie Sync Dates // list of timestamps for last cookie sync
87
+ con: IMinifiedConsentJSONObject; // Consent State
88
+ ui: UserIdentities; // User Identities
89
+ ua: UserAttributes; // User Attributes
90
+
91
+ // https://go.mparticle.com/work/SQDSDKS-6048
92
+ cp: Product[]; // Cart Products
93
+
94
+ fst: number; // First Seen Time
95
+ lst: number; // Last Seen Time
96
+ }
97
+
79
98
  export interface IPersistence {
80
99
  useLocalStorage(): boolean;
81
100
  initializeStorage(): void;
@@ -102,22 +121,15 @@ export interface IPersistence {
102
121
  getCookieDomain(): string;
103
122
  getDomain(doc: string, locationHostname: string): string;
104
123
  getUserIdentities(mpid: MPID): UserIdentities;
105
- getAllUserAttributes(mpid: MPID): AllUserAttributes;
106
124
  getCartProducts(mpid: MPID): Product[];
107
125
  setCartProducts(allProducts: Product[]): void;
108
126
  saveUserIdentitiesToPersistence(
109
127
  mpid: MPID,
110
128
  userIdentities: UserIdentities
111
129
  ): void;
112
- saveUserAttributesToPersistence(
113
- mpid: MPID,
114
- userAttributes: UserAttributes
115
- ): void;
116
130
  saveUserCookieSyncDatesToPersistence(mpid: MPID, csd: CookieSyncDate): void;
117
- saveUserConsentStateToCookies(mpid, consentState: ConsentState): void;
118
131
  savePersistence(persistance: IPersistenceMinified): void;
119
132
  getPersistence(): IPersistenceMinified;
120
- getConsentState(mpid: MPID): ConsentState | null;
121
133
  getFirstSeenTime(mpid: MPID): string | null;
122
134
  setFirstSeenTime(mpid: MPID, time: number): void;
123
135
  getLastSeenTime(mpid: MPID): number | null;