@mparticle/web-sdk 2.26.6 → 2.26.8
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.common.js +75 -63
- package/dist/mparticle.esm.js +75 -63
- package/dist/mparticle.js +1094 -1071
- package/package.json +1 -1
- package/src/identity.js +145 -189
- package/src/mp-instance.js +1 -0
- package/src/persistence.interfaces.ts +23 -5
- package/src/persistence.js +1 -36
- package/src/store.ts +130 -63
- package/src/type-utils.ts +66 -0
- package/src/types.js +3 -44
- package/src/user-utils.ts +25 -0
- package/src/utils.ts +4 -0
package/package.json
CHANGED
package/src/identity.js
CHANGED
|
@@ -6,13 +6,22 @@ import {
|
|
|
6
6
|
tryCacheIdentity,
|
|
7
7
|
} from './identity-utils';
|
|
8
8
|
import AudienceManager from './audienceManager';
|
|
9
|
-
|
|
10
|
-
const { Messages, HTTPCodes, FeatureFlags } = Constants;
|
|
9
|
+
const { Messages, HTTPCodes, FeatureFlags, IdentityMethods } = Constants;
|
|
11
10
|
const { ErrorMessages } = Messages;
|
|
12
|
-
|
|
13
|
-
const { Identify, Modify, Login, Logout } =
|
|
11
|
+
const { CacheIdentity } = FeatureFlags;
|
|
12
|
+
const { Identify, Modify, Login, Logout } = IdentityMethods;
|
|
13
|
+
import {
|
|
14
|
+
generateDeprecationMessage,
|
|
15
|
+
isEmpty,
|
|
16
|
+
isFunction,
|
|
17
|
+
isObject,
|
|
18
|
+
} from './utils';
|
|
19
|
+
import { hasMPIDAndUserLoginChanged, hasMPIDChanged } from './user-utils';
|
|
20
|
+
import { getNewIdentitiesByName } from './type-utils';
|
|
14
21
|
|
|
15
22
|
export default function Identity(mpInstance) {
|
|
23
|
+
const { getFeatureFlag, extend } = mpInstance._Helpers;
|
|
24
|
+
|
|
16
25
|
var self = this;
|
|
17
26
|
this.idCache = null;
|
|
18
27
|
this.audienceManager = null;
|
|
@@ -121,9 +130,9 @@ export default function Identity(mpInstance) {
|
|
|
121
130
|
var key;
|
|
122
131
|
if (
|
|
123
132
|
newIdentities &&
|
|
124
|
-
|
|
133
|
+
isObject(newIdentities) &&
|
|
125
134
|
previousIdentities &&
|
|
126
|
-
|
|
135
|
+
isObject(previousIdentities)
|
|
127
136
|
) {
|
|
128
137
|
for (key in newIdentities) {
|
|
129
138
|
identityChanges.push({
|
|
@@ -140,11 +149,7 @@ export default function Identity(mpInstance) {
|
|
|
140
149
|
// takes 2 UI objects keyed by name, combines them, returns them keyed by type
|
|
141
150
|
combineUserIdentities: function(previousUIByName, newUIByName) {
|
|
142
151
|
var combinedUIByType = {};
|
|
143
|
-
|
|
144
|
-
var combinedUIByName = mpInstance._Helpers.extend(
|
|
145
|
-
previousUIByName,
|
|
146
|
-
newUIByName
|
|
147
|
-
);
|
|
152
|
+
var combinedUIByName = extend({}, previousUIByName, newUIByName);
|
|
148
153
|
|
|
149
154
|
for (var key in combinedUIByName) {
|
|
150
155
|
var type = Types.IdentityType.getIdentityType(key);
|
|
@@ -946,7 +951,7 @@ export default function Identity(mpInstance) {
|
|
|
946
951
|
*/
|
|
947
952
|
setUserAttributes: function(userAttributes) {
|
|
948
953
|
mpInstance._SessionManager.resetSessionTimer();
|
|
949
|
-
if (
|
|
954
|
+
if (isObject(userAttributes)) {
|
|
950
955
|
if (mpInstance._Helpers.canLog()) {
|
|
951
956
|
for (var key in userAttributes) {
|
|
952
957
|
if (userAttributes.hasOwnProperty(key)) {
|
|
@@ -1228,7 +1233,7 @@ export default function Identity(mpInstance) {
|
|
|
1228
1233
|
* @return a ConsentState object
|
|
1229
1234
|
*/
|
|
1230
1235
|
getConsentState: function() {
|
|
1231
|
-
return mpInstance.
|
|
1236
|
+
return mpInstance._Store.getConsentState(mpid);
|
|
1232
1237
|
},
|
|
1233
1238
|
/**
|
|
1234
1239
|
* Sets the Consent State stored locally for this user.
|
|
@@ -1236,10 +1241,7 @@ export default function Identity(mpInstance) {
|
|
|
1236
1241
|
* @param {Object} consent state
|
|
1237
1242
|
*/
|
|
1238
1243
|
setConsentState: function(state) {
|
|
1239
|
-
mpInstance.
|
|
1240
|
-
mpid,
|
|
1241
|
-
state
|
|
1242
|
-
);
|
|
1244
|
+
mpInstance._Store.setConsentState(mpid, state);
|
|
1243
1245
|
mpInstance._Forwarders.initForwarders(
|
|
1244
1246
|
this.getUserIdentities().userIdentities,
|
|
1245
1247
|
mpInstance._APIClient.prepareForwardingStats
|
|
@@ -1482,41 +1484,34 @@ export default function Identity(mpInstance) {
|
|
|
1482
1484
|
knownIdentities,
|
|
1483
1485
|
parsingCachedResponse
|
|
1484
1486
|
) {
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
previousUIByName
|
|
1497
|
-
);
|
|
1487
|
+
const prevUser = mpInstance.Identity.getUser(previousMPID);
|
|
1488
|
+
const prevUserMPID = prevUser ? prevUser.getMPID() : null;
|
|
1489
|
+
const previousUIByName = prevUser
|
|
1490
|
+
? prevUser.getUserIdentities().userIdentities
|
|
1491
|
+
: {};
|
|
1492
|
+
let mpidIsNotInCookies;
|
|
1493
|
+
let identityApiResult;
|
|
1494
|
+
|
|
1495
|
+
let newUser;
|
|
1496
|
+
let newIdentitiesByType = {};
|
|
1497
|
+
|
|
1498
1498
|
mpInstance._Store.identityCallInFlight = false;
|
|
1499
1499
|
|
|
1500
1500
|
try {
|
|
1501
1501
|
mpInstance.Logger.verbose(
|
|
1502
1502
|
'Parsing "' + method + '" identity response from server'
|
|
1503
1503
|
);
|
|
1504
|
-
if (xhr.responseText) {
|
|
1505
|
-
identityApiResult = JSON.parse(xhr.responseText);
|
|
1506
1504
|
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1505
|
+
identityApiResult = xhr.responseText
|
|
1506
|
+
? JSON.parse(xhr.responseText)
|
|
1507
|
+
: null;
|
|
1512
1508
|
|
|
1509
|
+
mpInstance._Store.isLoggedIn =
|
|
1510
|
+
identityApiResult?.is_logged_in || false;
|
|
1511
|
+
|
|
1512
|
+
// https://go.mparticle.com/work/SQDSDKS-6504
|
|
1513
1513
|
// set currentUser
|
|
1514
|
-
if (
|
|
1515
|
-
!prevUser ||
|
|
1516
|
-
(prevUser.getMPID() &&
|
|
1517
|
-
identityApiResult.mpid &&
|
|
1518
|
-
identityApiResult.mpid !== prevUser.getMPID())
|
|
1519
|
-
) {
|
|
1514
|
+
if (hasMPIDChanged(prevUser, identityApiResult)) {
|
|
1520
1515
|
mpInstance._Store.mpid = identityApiResult.mpid;
|
|
1521
1516
|
|
|
1522
1517
|
if (prevUser) {
|
|
@@ -1524,23 +1519,18 @@ export default function Identity(mpInstance) {
|
|
|
1524
1519
|
mpInstance._Persistence.setLastSeenTime(previousMPID);
|
|
1525
1520
|
}
|
|
1526
1521
|
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
mpidIsNotInCookies = true;
|
|
1522
|
+
mpidIsNotInCookies = !mpInstance._Persistence.getFirstSeenTime(
|
|
1523
|
+
identityApiResult.mpid
|
|
1524
|
+
);
|
|
1525
|
+
|
|
1526
|
+
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1533
1527
|
mpInstance._Persistence.setFirstSeenTime(
|
|
1534
1528
|
identityApiResult.mpid
|
|
1535
1529
|
);
|
|
1536
1530
|
}
|
|
1537
1531
|
|
|
1538
1532
|
if (xhr.status === 200) {
|
|
1539
|
-
if (
|
|
1540
|
-
mpInstance._Helpers.getFeatureFlag(
|
|
1541
|
-
Constants.FeatureFlags.CacheIdentity
|
|
1542
|
-
)
|
|
1543
|
-
) {
|
|
1533
|
+
if (getFeatureFlag(CacheIdentity)) {
|
|
1544
1534
|
cacheOrClearIdCache(
|
|
1545
1535
|
method,
|
|
1546
1536
|
knownIdentities,
|
|
@@ -1550,6 +1540,14 @@ export default function Identity(mpInstance) {
|
|
|
1550
1540
|
);
|
|
1551
1541
|
}
|
|
1552
1542
|
|
|
1543
|
+
const incomingUser = self.IdentityAPI.getUser(
|
|
1544
|
+
identityApiResult.mpid
|
|
1545
|
+
);
|
|
1546
|
+
|
|
1547
|
+
const incomingUIByName = incomingUser
|
|
1548
|
+
? incomingUser.getUserIdentities().userIdentities
|
|
1549
|
+
: {};
|
|
1550
|
+
|
|
1553
1551
|
if (method === Modify) {
|
|
1554
1552
|
newIdentitiesByType = mpInstance._Identity.IdentityRequest.combineUserIdentities(
|
|
1555
1553
|
previousUIByName,
|
|
@@ -1561,22 +1559,6 @@ export default function Identity(mpInstance) {
|
|
|
1561
1559
|
newIdentitiesByType
|
|
1562
1560
|
);
|
|
1563
1561
|
} else {
|
|
1564
|
-
var incomingUser = self.IdentityAPI.getUser(
|
|
1565
|
-
identityApiResult.mpid
|
|
1566
|
-
);
|
|
1567
|
-
|
|
1568
|
-
var incomingMpidUIByName = incomingUser
|
|
1569
|
-
? incomingUser.getUserIdentities().userIdentities
|
|
1570
|
-
: {};
|
|
1571
|
-
|
|
1572
|
-
var incomingMpidUIByNameCopy = mpInstance._Helpers.extend(
|
|
1573
|
-
{},
|
|
1574
|
-
incomingMpidUIByName
|
|
1575
|
-
);
|
|
1576
|
-
mpInstance.Logger.verbose(
|
|
1577
|
-
'Successfully parsed Identity Response'
|
|
1578
|
-
);
|
|
1579
|
-
|
|
1580
1562
|
// https://go.mparticle.com/work/SQDSDKS-6356
|
|
1581
1563
|
//this covers an edge case where, users stored before "firstSeenTime" was introduced
|
|
1582
1564
|
//will not have a value for "fst" until the current MPID changes, and in some cases,
|
|
@@ -1584,7 +1566,7 @@ export default function Identity(mpInstance) {
|
|
|
1584
1566
|
if (
|
|
1585
1567
|
method === Identify &&
|
|
1586
1568
|
prevUser &&
|
|
1587
|
-
identityApiResult.mpid ===
|
|
1569
|
+
identityApiResult.mpid === prevUserMPID
|
|
1588
1570
|
) {
|
|
1589
1571
|
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1590
1572
|
mpInstance._Persistence.setFirstSeenTime(
|
|
@@ -1592,35 +1574,11 @@ export default function Identity(mpInstance) {
|
|
|
1592
1574
|
);
|
|
1593
1575
|
}
|
|
1594
1576
|
|
|
1595
|
-
|
|
1596
|
-
identityApiResult.mpid
|
|
1577
|
+
mpInstance._Store.addMpidToSessionHistory(
|
|
1578
|
+
identityApiResult.mpid,
|
|
1579
|
+
previousMPID
|
|
1597
1580
|
);
|
|
1598
1581
|
|
|
1599
|
-
if (
|
|
1600
|
-
mpInstance._Store.sessionId &&
|
|
1601
|
-
identityApiResult.mpid &&
|
|
1602
|
-
previousMPID !== identityApiResult.mpid &&
|
|
1603
|
-
indexOfMPID < 0
|
|
1604
|
-
) {
|
|
1605
|
-
mpInstance._Store.currentSessionMPIDs.push(
|
|
1606
|
-
identityApiResult.mpid
|
|
1607
|
-
);
|
|
1608
|
-
}
|
|
1609
|
-
|
|
1610
|
-
if (indexOfMPID > -1) {
|
|
1611
|
-
mpInstance._Store.currentSessionMPIDs = mpInstance._Store.currentSessionMPIDs
|
|
1612
|
-
.slice(0, indexOfMPID)
|
|
1613
|
-
.concat(
|
|
1614
|
-
mpInstance._Store.currentSessionMPIDs.slice(
|
|
1615
|
-
indexOfMPID + 1,
|
|
1616
|
-
mpInstance._Store.currentSessionMPIDs.length
|
|
1617
|
-
)
|
|
1618
|
-
);
|
|
1619
|
-
mpInstance._Store.currentSessionMPIDs.push(
|
|
1620
|
-
identityApiResult.mpid
|
|
1621
|
-
);
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
1582
|
mpInstance._CookieSyncManager.attemptCookieSync(
|
|
1625
1583
|
previousMPID,
|
|
1626
1584
|
identityApiResult.mpid,
|
|
@@ -1635,11 +1593,10 @@ export default function Identity(mpInstance) {
|
|
|
1635
1593
|
|
|
1636
1594
|
if (
|
|
1637
1595
|
identityApiData &&
|
|
1638
|
-
identityApiData.userIdentities
|
|
1639
|
-
Object.keys(identityApiData.userIdentities).length
|
|
1596
|
+
!isEmpty(identityApiData.userIdentities)
|
|
1640
1597
|
) {
|
|
1641
1598
|
newIdentitiesByType = self.IdentityRequest.combineUserIdentities(
|
|
1642
|
-
|
|
1599
|
+
incomingUIByName,
|
|
1643
1600
|
identityApiData.userIdentities
|
|
1644
1601
|
);
|
|
1645
1602
|
}
|
|
@@ -1650,6 +1607,7 @@ export default function Identity(mpInstance) {
|
|
|
1650
1607
|
newIdentitiesByType
|
|
1651
1608
|
);
|
|
1652
1609
|
mpInstance._Persistence.update();
|
|
1610
|
+
mpInstance._Store.syncPersistenceData();
|
|
1653
1611
|
|
|
1654
1612
|
mpInstance._Persistence.findPrevCookiesBasedOnUI(
|
|
1655
1613
|
identityApiData
|
|
@@ -1663,106 +1621,66 @@ export default function Identity(mpInstance) {
|
|
|
1663
1621
|
newUser = mpInstance.Identity.getCurrentUser();
|
|
1664
1622
|
|
|
1665
1623
|
// https://go.mparticle.com/work/SQDSDKS-6359
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
mpInstance.Logger.warning(
|
|
1675
|
-
'Deprecated function onUserAlias will be removed in future releases'
|
|
1676
|
-
);
|
|
1677
|
-
identityApiData.onUserAlias(prevUser, newUser);
|
|
1678
|
-
} catch (e) {
|
|
1679
|
-
mpInstance.Logger.error(
|
|
1680
|
-
'There was an error with your onUserAlias function - ' +
|
|
1681
|
-
e
|
|
1682
|
-
);
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
var persistence = mpInstance._Persistence.getPersistence();
|
|
1624
|
+
tryOnUserAlias(
|
|
1625
|
+
prevUser,
|
|
1626
|
+
newUser,
|
|
1627
|
+
identityApiData,
|
|
1628
|
+
mpInstance.Logger
|
|
1629
|
+
);
|
|
1630
|
+
|
|
1631
|
+
const persistence = mpInstance._Persistence.getPersistence();
|
|
1686
1632
|
|
|
1687
1633
|
if (newUser) {
|
|
1688
1634
|
mpInstance._Persistence.storeDataInMemory(
|
|
1689
1635
|
persistence,
|
|
1690
1636
|
newUser.getMPID()
|
|
1691
1637
|
);
|
|
1692
|
-
if (
|
|
1693
|
-
!prevUser ||
|
|
1694
|
-
newUser.getMPID() !== prevUser.getMPID() ||
|
|
1695
|
-
prevUser.isLoggedIn() !== newUser.isLoggedIn()
|
|
1696
|
-
) {
|
|
1697
|
-
mpInstance._Forwarders.initForwarders(
|
|
1698
|
-
newUser.getUserIdentities().userIdentities,
|
|
1699
|
-
mpInstance._APIClient.prepareForwardingStats
|
|
1700
|
-
);
|
|
1701
|
-
}
|
|
1702
1638
|
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
newUser.getUserIdentities().userIdentities
|
|
1706
|
-
);
|
|
1707
|
-
mpInstance._Forwarders.setForwarderOnIdentityComplete(
|
|
1708
|
-
newUser,
|
|
1709
|
-
method
|
|
1710
|
-
);
|
|
1711
|
-
mpInstance._Forwarders.setForwarderOnUserIdentified(
|
|
1712
|
-
newUser
|
|
1713
|
-
);
|
|
1639
|
+
self.reinitForwardersOnUserChange(prevUser, newUser);
|
|
1640
|
+
self.setForwarderCallbacks(newUser, method);
|
|
1714
1641
|
}
|
|
1715
|
-
var newIdentitiesByName = {};
|
|
1716
1642
|
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
}
|
|
1643
|
+
const newIdentitiesByName = getNewIdentitiesByName(
|
|
1644
|
+
newIdentitiesByType
|
|
1645
|
+
);
|
|
1646
|
+
|
|
1647
|
+
const uiByName =
|
|
1648
|
+
method === Modify ? previousUIByName : incomingUIByName;
|
|
1724
1649
|
|
|
1650
|
+
// https://go.mparticle.com/work/SQDSDKS-6501
|
|
1725
1651
|
self.sendUserIdentityChangeEvent(
|
|
1726
1652
|
newIdentitiesByName,
|
|
1727
1653
|
method,
|
|
1728
1654
|
identityApiResult.mpid,
|
|
1729
|
-
|
|
1730
|
-
? previousUIByNameCopy
|
|
1731
|
-
: incomingMpidUIByNameCopy
|
|
1655
|
+
uiByName
|
|
1732
1656
|
);
|
|
1733
1657
|
}
|
|
1734
1658
|
|
|
1735
1659
|
if (callback) {
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
) {
|
|
1757
|
-
mpInstance.Logger.error(
|
|
1758
|
-
'Received HTTP response code of ' +
|
|
1759
|
-
xhr.status +
|
|
1760
|
-
' - ' +
|
|
1761
|
-
identityApiResult.errors[0].message
|
|
1762
|
-
);
|
|
1763
|
-
}
|
|
1660
|
+
const callbackCode =
|
|
1661
|
+
xhr.status === 0 ? HTTPCodes.noHttpCoverage : xhr.status;
|
|
1662
|
+
|
|
1663
|
+
mpInstance._Helpers.invokeCallback(
|
|
1664
|
+
callback,
|
|
1665
|
+
callbackCode,
|
|
1666
|
+
identityApiResult || null,
|
|
1667
|
+
newUser
|
|
1668
|
+
);
|
|
1669
|
+
} else if (
|
|
1670
|
+
identityApiResult &&
|
|
1671
|
+
!isEmpty(identityApiResult.errors)
|
|
1672
|
+
) {
|
|
1673
|
+
// https://go.mparticle.com/work/SQDSDKS-6500
|
|
1674
|
+
mpInstance.Logger.error(
|
|
1675
|
+
'Received HTTP response code of ' +
|
|
1676
|
+
xhr.status +
|
|
1677
|
+
' - ' +
|
|
1678
|
+
identityApiResult.errors[0].message
|
|
1679
|
+
);
|
|
1764
1680
|
}
|
|
1765
1681
|
|
|
1682
|
+
mpInstance.Logger.verbose('Successfully parsed Identity Response');
|
|
1683
|
+
|
|
1766
1684
|
mpInstance._APIClient.processQueuedEvents();
|
|
1767
1685
|
} catch (e) {
|
|
1768
1686
|
if (callback) {
|
|
@@ -1781,31 +1699,33 @@ export default function Identity(mpInstance) {
|
|
|
1781
1699
|
// send a user identity change request on identify, login, logout, modify when any values change.
|
|
1782
1700
|
// compare what identities exist vs what is previously was for the specific user if they were in memory before.
|
|
1783
1701
|
// if it's the first time the user is logging in, send a user identity change request with
|
|
1784
|
-
|
|
1785
1702
|
this.sendUserIdentityChangeEvent = function(
|
|
1786
1703
|
newUserIdentities,
|
|
1787
1704
|
method,
|
|
1788
1705
|
mpid,
|
|
1789
1706
|
prevUserIdentities
|
|
1790
1707
|
) {
|
|
1791
|
-
var currentUserInMemory, userIdentityChangeEvent;
|
|
1792
|
-
|
|
1793
1708
|
if (!mpid) {
|
|
1709
|
+
// https://go.mparticle.com/work/SQDSDKS-6501
|
|
1794
1710
|
if (method !== Modify) {
|
|
1795
1711
|
return;
|
|
1796
1712
|
}
|
|
1797
1713
|
}
|
|
1798
1714
|
|
|
1799
1715
|
// https://go.mparticle.com/work/SQDSDKS-6354
|
|
1800
|
-
currentUserInMemory = this.IdentityAPI.getUser(mpid);
|
|
1716
|
+
const currentUserInMemory = this.IdentityAPI.getUser(mpid);
|
|
1801
1717
|
|
|
1802
1718
|
for (var identityType in newUserIdentities) {
|
|
1719
|
+
// Verifies a change actually happened
|
|
1803
1720
|
if (
|
|
1804
1721
|
prevUserIdentities[identityType] !==
|
|
1805
1722
|
newUserIdentities[identityType]
|
|
1806
1723
|
) {
|
|
1807
|
-
|
|
1808
|
-
|
|
1724
|
+
// If a new identity type was introduced when the identity changes
|
|
1725
|
+
// we need to notify the server so that the user profile is updated in
|
|
1726
|
+
// the mParticle UI.
|
|
1727
|
+
const isNewUserIdentityType = !prevUserIdentities[identityType];
|
|
1728
|
+
const userIdentityChangeEvent = self.createUserIdentityChange(
|
|
1809
1729
|
identityType,
|
|
1810
1730
|
newUserIdentities[identityType],
|
|
1811
1731
|
prevUserIdentities[identityType],
|
|
@@ -1823,7 +1743,7 @@ export default function Identity(mpInstance) {
|
|
|
1823
1743
|
identityType,
|
|
1824
1744
|
newIdentity,
|
|
1825
1745
|
oldIdentity,
|
|
1826
|
-
|
|
1746
|
+
isIdentityTypeNewToBatch,
|
|
1827
1747
|
userInMemory
|
|
1828
1748
|
) {
|
|
1829
1749
|
var userIdentityChangeEvent;
|
|
@@ -1835,7 +1755,7 @@ export default function Identity(mpInstance) {
|
|
|
1835
1755
|
New: {
|
|
1836
1756
|
IdentityType: identityType,
|
|
1837
1757
|
Identity: newIdentity,
|
|
1838
|
-
CreatedThisBatch:
|
|
1758
|
+
CreatedThisBatch: isIdentityTypeNewToBatch,
|
|
1839
1759
|
},
|
|
1840
1760
|
Old: {
|
|
1841
1761
|
IdentityType: identityType,
|
|
@@ -1900,4 +1820,40 @@ export default function Identity(mpInstance) {
|
|
|
1900
1820
|
}
|
|
1901
1821
|
return userAttributeChangeEvent;
|
|
1902
1822
|
};
|
|
1823
|
+
|
|
1824
|
+
this.reinitForwardersOnUserChange = function(prevUser, newUser) {
|
|
1825
|
+
if (hasMPIDAndUserLoginChanged(prevUser, newUser)) {
|
|
1826
|
+
mpInstance._Forwarders.initForwarders(
|
|
1827
|
+
newUser.getUserIdentities().userIdentities,
|
|
1828
|
+
mpInstance._APIClient.prepareForwardingStats
|
|
1829
|
+
);
|
|
1830
|
+
}
|
|
1831
|
+
};
|
|
1832
|
+
|
|
1833
|
+
this.setForwarderCallbacks = function(user, method) {
|
|
1834
|
+
// https://go.mparticle.com/work/SQDSDKS-6036
|
|
1835
|
+
mpInstance._Forwarders.setForwarderUserIdentities(
|
|
1836
|
+
user.getUserIdentities().userIdentities
|
|
1837
|
+
);
|
|
1838
|
+
mpInstance._Forwarders.setForwarderOnIdentityComplete(user, method);
|
|
1839
|
+
mpInstance._Forwarders.setForwarderOnUserIdentified(user);
|
|
1840
|
+
};
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// https://go.mparticle.com/work/SQDSDKS-6359
|
|
1844
|
+
function tryOnUserAlias(previousUser, newUser, identityApiData, logger) {
|
|
1845
|
+
if (
|
|
1846
|
+
identityApiData &&
|
|
1847
|
+
identityApiData.onUserAlias &&
|
|
1848
|
+
isFunction(identityApiData.onUserAlias)
|
|
1849
|
+
) {
|
|
1850
|
+
try {
|
|
1851
|
+
logger.warning(generateDeprecationMessage('onUserAlias'));
|
|
1852
|
+
identityApiData.onUserAlias(previousUser, newUser);
|
|
1853
|
+
} catch (e) {
|
|
1854
|
+
logger.error(
|
|
1855
|
+
'There was an error with your onUserAlias function - ' + e
|
|
1856
|
+
);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1903
1859
|
}
|
package/src/mp-instance.js
CHANGED
|
@@ -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();
|
|
@@ -14,9 +14,9 @@ import {
|
|
|
14
14
|
SessionAttributes,
|
|
15
15
|
} from './store';
|
|
16
16
|
import { Dictionary } from './utils';
|
|
17
|
+
import { IMinifiedConsentJSONObject } from './consent';
|
|
17
18
|
import { UserAttributes } from './identity-user-interfaces';
|
|
18
19
|
|
|
19
|
-
export type CookieSyncDate = Dictionary<string>;
|
|
20
20
|
export type UploadsTable = Dictionary<any>;
|
|
21
21
|
export interface iForwardingStatsBatches {
|
|
22
22
|
uploadsTable: UploadsTable;
|
|
@@ -46,7 +46,7 @@ export interface IPersistenceMinified extends Dictionary {
|
|
|
46
46
|
|
|
47
47
|
// Persistence Minified can also store optional dictionaries with
|
|
48
48
|
// an idex of MPID
|
|
49
|
-
// [mpid: MPID]: Dictionary<
|
|
49
|
+
// [mpid: MPID]: Dictionary<IUserPersistenceMinified>;
|
|
50
50
|
|
|
51
51
|
// For Example:
|
|
52
52
|
// {
|
|
@@ -68,14 +68,34 @@ export interface IPersistenceMinified extends Dictionary {
|
|
|
68
68
|
// },
|
|
69
69
|
// l: false,
|
|
70
70
|
// MPID1: {
|
|
71
|
-
// csd:
|
|
71
|
+
// csd: {
|
|
72
|
+
// [moduleid]: 1234567890,
|
|
73
|
+
// },
|
|
72
74
|
// ui: {
|
|
73
75
|
// customerid: '12346',
|
|
74
76
|
// },
|
|
77
|
+
// ua: {
|
|
78
|
+
// age '42',
|
|
79
|
+
// },
|
|
75
80
|
// },
|
|
76
81
|
// };
|
|
77
82
|
}
|
|
78
83
|
|
|
84
|
+
export type CookieSyncDate = Dictionary<number>;
|
|
85
|
+
|
|
86
|
+
export interface IUserPersistenceMinified extends Dictionary {
|
|
87
|
+
csd: CookieSyncDate; // Cookie Sync Dates // list of timestamps for last cookie sync
|
|
88
|
+
con: IMinifiedConsentJSONObject; // Consent State
|
|
89
|
+
ui: UserIdentities; // User Identities
|
|
90
|
+
ua: UserAttributes; // User Attributes
|
|
91
|
+
|
|
92
|
+
// https://go.mparticle.com/work/SQDSDKS-6048
|
|
93
|
+
cp: Product[]; // Cart Products
|
|
94
|
+
|
|
95
|
+
fst: number; // First Seen Time
|
|
96
|
+
lst: number; // Last Seen Time
|
|
97
|
+
}
|
|
98
|
+
|
|
79
99
|
export interface IPersistence {
|
|
80
100
|
useLocalStorage(): boolean;
|
|
81
101
|
initializeStorage(): void;
|
|
@@ -114,10 +134,8 @@ export interface IPersistence {
|
|
|
114
134
|
userAttributes: UserAttributes
|
|
115
135
|
): void;
|
|
116
136
|
saveUserCookieSyncDatesToPersistence(mpid: MPID, csd: CookieSyncDate): void;
|
|
117
|
-
saveUserConsentStateToCookies(mpid, consentState: ConsentState): void;
|
|
118
137
|
savePersistence(persistance: IPersistenceMinified): void;
|
|
119
138
|
getPersistence(): IPersistenceMinified;
|
|
120
|
-
getConsentState(mpid: MPID): ConsentState | null;
|
|
121
139
|
getFirstSeenTime(mpid: MPID): string | null;
|
|
122
140
|
setFirstSeenTime(mpid: MPID, time: number): void;
|
|
123
141
|
getLastSeenTime(mpid: MPID): number | null;
|
package/src/persistence.js
CHANGED
|
@@ -937,6 +937,7 @@ export default function _Persistence(mpInstance) {
|
|
|
937
937
|
);
|
|
938
938
|
}
|
|
939
939
|
};
|
|
940
|
+
|
|
940
941
|
this.saveUserIdentitiesToPersistence = function(mpid, userIdentities) {
|
|
941
942
|
if (userIdentities) {
|
|
942
943
|
var persistence = self.getPersistence();
|
|
@@ -988,30 +989,6 @@ export default function _Persistence(mpInstance) {
|
|
|
988
989
|
}
|
|
989
990
|
};
|
|
990
991
|
|
|
991
|
-
this.saveUserConsentStateToCookies = function(mpid, consentState) {
|
|
992
|
-
//it's currently not supported to set persistence
|
|
993
|
-
//for any MPID that's not the current one.
|
|
994
|
-
if (consentState || consentState === null) {
|
|
995
|
-
var persistence = self.getPersistence();
|
|
996
|
-
if (persistence) {
|
|
997
|
-
if (persistence[mpid]) {
|
|
998
|
-
persistence[
|
|
999
|
-
mpid
|
|
1000
|
-
].con = mpInstance._Consent.ConsentSerialization.toMinifiedJsonObject(
|
|
1001
|
-
consentState
|
|
1002
|
-
);
|
|
1003
|
-
} else {
|
|
1004
|
-
persistence[mpid] = {
|
|
1005
|
-
con: mpInstance._Consent.ConsentSerialization.toMinifiedJsonObject(
|
|
1006
|
-
consentState
|
|
1007
|
-
),
|
|
1008
|
-
};
|
|
1009
|
-
}
|
|
1010
|
-
self.savePersistence(persistence);
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
};
|
|
1014
|
-
|
|
1015
992
|
this.swapCurrentUser = function(
|
|
1016
993
|
previousMPID,
|
|
1017
994
|
currentMPID,
|
|
@@ -1080,18 +1057,6 @@ export default function _Persistence(mpInstance) {
|
|
|
1080
1057
|
return persistence;
|
|
1081
1058
|
};
|
|
1082
1059
|
|
|
1083
|
-
this.getConsentState = function(mpid) {
|
|
1084
|
-
var persistence = self.getPersistence();
|
|
1085
|
-
|
|
1086
|
-
if (persistence && persistence[mpid] && persistence[mpid].con) {
|
|
1087
|
-
return mpInstance._Consent.ConsentSerialization.fromMinifiedJsonObject(
|
|
1088
|
-
persistence[mpid].con
|
|
1089
|
-
);
|
|
1090
|
-
} else {
|
|
1091
|
-
return null;
|
|
1092
|
-
}
|
|
1093
|
-
};
|
|
1094
|
-
|
|
1095
1060
|
this.getFirstSeenTime = function(mpid) {
|
|
1096
1061
|
if (!mpid) {
|
|
1097
1062
|
return null;
|