@mparticle/web-sdk 2.26.5 → 2.26.7
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 +78 -54
- package/dist/mparticle.esm.js +78 -54
- package/dist/mparticle.js +1108 -1048
- package/package.json +1 -1
- package/src/identity.interfaces.ts +0 -5
- package/src/identity.js +156 -200
- package/src/identityApiClient.js +2 -0
- package/src/persistence.interfaces.ts +5 -0
- package/src/persistence.js +17 -0
- package/src/sdkRuntimeModels.ts +4 -0
- package/src/serverModel.ts +3 -0
- package/src/store.ts +18 -0
- 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
|
@@ -154,11 +154,6 @@ export interface IIdentity {
|
|
|
154
154
|
|
|
155
155
|
mParticleUser(mpid: MPID, IsLoggedIn: boolean): IMParticleUser;
|
|
156
156
|
|
|
157
|
-
checkIdentitySwap(
|
|
158
|
-
previousMPID: MPID,
|
|
159
|
-
currentMPID: MPID,
|
|
160
|
-
currentSessionMPIDs?: MPID[]
|
|
161
|
-
): void;
|
|
162
157
|
createUserAttributeChange(
|
|
163
158
|
key: string,
|
|
164
159
|
newValue: string,
|
package/src/identity.js
CHANGED
|
@@ -6,32 +6,27 @@ 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;
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
previousMPID,
|
|
22
|
-
currentMPID,
|
|
23
|
-
currentSessionMPIDs
|
|
24
|
-
) {
|
|
25
|
-
if (previousMPID && currentMPID && previousMPID !== currentMPID) {
|
|
26
|
-
var persistence = mpInstance._Persistence.getPersistence();
|
|
27
|
-
if (persistence) {
|
|
28
|
-
persistence.cu = currentMPID;
|
|
29
|
-
persistence.gs.csm = currentSessionMPIDs;
|
|
30
|
-
mpInstance._Persistence.savePersistence(persistence);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
29
|
+
// https://go.mparticle.com/work/SQDSDKS-6353
|
|
35
30
|
this.IdentityRequest = {
|
|
36
31
|
preProcessIdentityRequest: function(identityApiData, callback, method) {
|
|
37
32
|
mpInstance.Logger.verbose(
|
|
@@ -135,9 +130,9 @@ export default function Identity(mpInstance) {
|
|
|
135
130
|
var key;
|
|
136
131
|
if (
|
|
137
132
|
newIdentities &&
|
|
138
|
-
|
|
133
|
+
isObject(newIdentities) &&
|
|
139
134
|
previousIdentities &&
|
|
140
|
-
|
|
135
|
+
isObject(previousIdentities)
|
|
141
136
|
) {
|
|
142
137
|
for (key in newIdentities) {
|
|
143
138
|
identityChanges.push({
|
|
@@ -154,11 +149,7 @@ export default function Identity(mpInstance) {
|
|
|
154
149
|
// takes 2 UI objects keyed by name, combines them, returns them keyed by type
|
|
155
150
|
combineUserIdentities: function(previousUIByName, newUIByName) {
|
|
156
151
|
var combinedUIByType = {};
|
|
157
|
-
|
|
158
|
-
var combinedUIByName = mpInstance._Helpers.extend(
|
|
159
|
-
previousUIByName,
|
|
160
|
-
newUIByName
|
|
161
|
-
);
|
|
152
|
+
var combinedUIByName = extend({}, previousUIByName, newUIByName);
|
|
162
153
|
|
|
163
154
|
for (var key in combinedUIByName) {
|
|
164
155
|
var type = Types.IdentityType.getIdentityType(key);
|
|
@@ -232,6 +223,7 @@ export default function Identity(mpInstance) {
|
|
|
232
223
|
* @param {Function} [callback] A callback function that is called when the identify request completes
|
|
233
224
|
*/
|
|
234
225
|
identify: function(identityApiData, callback) {
|
|
226
|
+
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
235
227
|
var mpid,
|
|
236
228
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
237
229
|
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
@@ -325,6 +317,7 @@ export default function Identity(mpInstance) {
|
|
|
325
317
|
* @param {Function} [callback] A callback function that is called when the logout request completes
|
|
326
318
|
*/
|
|
327
319
|
logout: function(identityApiData, callback) {
|
|
320
|
+
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
328
321
|
var mpid,
|
|
329
322
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
330
323
|
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
@@ -414,6 +407,7 @@ export default function Identity(mpInstance) {
|
|
|
414
407
|
* @param {Function} [callback] A callback function that is called when the login request completes
|
|
415
408
|
*/
|
|
416
409
|
login: function(identityApiData, callback) {
|
|
410
|
+
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
417
411
|
var mpid,
|
|
418
412
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
419
413
|
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
@@ -509,6 +503,7 @@ export default function Identity(mpInstance) {
|
|
|
509
503
|
* @param {Function} [callback] A callback function that is called when the modify request completes
|
|
510
504
|
*/
|
|
511
505
|
modify: function(identityApiData, callback) {
|
|
506
|
+
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
512
507
|
var mpid,
|
|
513
508
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
514
509
|
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
@@ -796,6 +791,7 @@ export default function Identity(mpInstance) {
|
|
|
796
791
|
},
|
|
797
792
|
};
|
|
798
793
|
|
|
794
|
+
// https://go.mparticle.com/work/SQDSDKS-6354
|
|
799
795
|
/**
|
|
800
796
|
* Invoke these methods on the mParticle.Identity.getCurrentUser() object.
|
|
801
797
|
* Example: mParticle.Identity.getCurrentUser().getAllUserAttributes()
|
|
@@ -955,7 +951,7 @@ export default function Identity(mpInstance) {
|
|
|
955
951
|
*/
|
|
956
952
|
setUserAttributes: function(userAttributes) {
|
|
957
953
|
mpInstance._SessionManager.resetSessionTimer();
|
|
958
|
-
if (
|
|
954
|
+
if (isObject(userAttributes)) {
|
|
959
955
|
if (mpInstance._Helpers.canLog()) {
|
|
960
956
|
for (var key in userAttributes) {
|
|
961
957
|
if (userAttributes.hasOwnProperty(key)) {
|
|
@@ -1481,6 +1477,7 @@ export default function Identity(mpInstance) {
|
|
|
1481
1477
|
};
|
|
1482
1478
|
};
|
|
1483
1479
|
|
|
1480
|
+
// https://go.mparticle.com/work/SQDSDKS-6355
|
|
1484
1481
|
this.parseIdentityResponse = function(
|
|
1485
1482
|
xhr,
|
|
1486
1483
|
previousMPID,
|
|
@@ -1490,64 +1487,53 @@ export default function Identity(mpInstance) {
|
|
|
1490
1487
|
knownIdentities,
|
|
1491
1488
|
parsingCachedResponse
|
|
1492
1489
|
) {
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
previousUIByName
|
|
1505
|
-
);
|
|
1490
|
+
const prevUser = mpInstance.Identity.getUser(previousMPID);
|
|
1491
|
+
const prevUserMPID = prevUser ? prevUser.getMPID() : null;
|
|
1492
|
+
const previousUIByName = prevUser
|
|
1493
|
+
? prevUser.getUserIdentities().userIdentities
|
|
1494
|
+
: {};
|
|
1495
|
+
let mpidIsNotInCookies;
|
|
1496
|
+
let identityApiResult;
|
|
1497
|
+
|
|
1498
|
+
let newUser;
|
|
1499
|
+
let newIdentitiesByType = {};
|
|
1500
|
+
|
|
1506
1501
|
mpInstance._Store.identityCallInFlight = false;
|
|
1507
1502
|
|
|
1508
1503
|
try {
|
|
1509
1504
|
mpInstance.Logger.verbose(
|
|
1510
1505
|
'Parsing "' + method + '" identity response from server'
|
|
1511
1506
|
);
|
|
1512
|
-
if (xhr.responseText) {
|
|
1513
|
-
identityApiResult = JSON.parse(xhr.responseText);
|
|
1514
1507
|
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1508
|
+
identityApiResult = xhr.responseText
|
|
1509
|
+
? JSON.parse(xhr.responseText)
|
|
1510
|
+
: null;
|
|
1520
1511
|
|
|
1512
|
+
mpInstance._Store.isLoggedIn =
|
|
1513
|
+
identityApiResult?.is_logged_in || false;
|
|
1514
|
+
|
|
1515
|
+
// https://go.mparticle.com/work/SQDSDKS-6504
|
|
1521
1516
|
// set currentUser
|
|
1522
|
-
if (
|
|
1523
|
-
!prevUser ||
|
|
1524
|
-
(prevUser.getMPID() &&
|
|
1525
|
-
identityApiResult.mpid &&
|
|
1526
|
-
identityApiResult.mpid !== prevUser.getMPID())
|
|
1527
|
-
) {
|
|
1517
|
+
if (hasMPIDChanged(prevUser, identityApiResult)) {
|
|
1528
1518
|
mpInstance._Store.mpid = identityApiResult.mpid;
|
|
1529
1519
|
|
|
1530
1520
|
if (prevUser) {
|
|
1521
|
+
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1531
1522
|
mpInstance._Persistence.setLastSeenTime(previousMPID);
|
|
1532
1523
|
}
|
|
1533
1524
|
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
mpidIsNotInCookies = true;
|
|
1525
|
+
mpidIsNotInCookies = !mpInstance._Persistence.getFirstSeenTime(
|
|
1526
|
+
identityApiResult.mpid
|
|
1527
|
+
);
|
|
1528
|
+
|
|
1529
|
+
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1540
1530
|
mpInstance._Persistence.setFirstSeenTime(
|
|
1541
1531
|
identityApiResult.mpid
|
|
1542
1532
|
);
|
|
1543
1533
|
}
|
|
1544
1534
|
|
|
1545
1535
|
if (xhr.status === 200) {
|
|
1546
|
-
if (
|
|
1547
|
-
mpInstance._Helpers.getFeatureFlag(
|
|
1548
|
-
Constants.FeatureFlags.CacheIdentity
|
|
1549
|
-
)
|
|
1550
|
-
) {
|
|
1536
|
+
if (getFeatureFlag(CacheIdentity)) {
|
|
1551
1537
|
cacheOrClearIdCache(
|
|
1552
1538
|
method,
|
|
1553
1539
|
knownIdentities,
|
|
@@ -1557,6 +1543,14 @@ export default function Identity(mpInstance) {
|
|
|
1557
1543
|
);
|
|
1558
1544
|
}
|
|
1559
1545
|
|
|
1546
|
+
const incomingUser = self.IdentityAPI.getUser(
|
|
1547
|
+
identityApiResult.mpid
|
|
1548
|
+
);
|
|
1549
|
+
|
|
1550
|
+
const incomingUIByName = incomingUser
|
|
1551
|
+
? incomingUser.getUserIdentities().userIdentities
|
|
1552
|
+
: {};
|
|
1553
|
+
|
|
1560
1554
|
if (method === Modify) {
|
|
1561
1555
|
newIdentitiesByType = mpInstance._Identity.IdentityRequest.combineUserIdentities(
|
|
1562
1556
|
previousUIByName,
|
|
@@ -1568,71 +1562,33 @@ export default function Identity(mpInstance) {
|
|
|
1568
1562
|
newIdentitiesByType
|
|
1569
1563
|
);
|
|
1570
1564
|
} else {
|
|
1571
|
-
|
|
1572
|
-
identityApiResult.mpid
|
|
1573
|
-
);
|
|
1574
|
-
|
|
1575
|
-
var incomingMpidUIByName = incomingUser
|
|
1576
|
-
? incomingUser.getUserIdentities().userIdentities
|
|
1577
|
-
: {};
|
|
1578
|
-
|
|
1579
|
-
var incomingMpidUIByNameCopy = mpInstance._Helpers.extend(
|
|
1580
|
-
{},
|
|
1581
|
-
incomingMpidUIByName
|
|
1582
|
-
);
|
|
1583
|
-
mpInstance.Logger.verbose(
|
|
1584
|
-
'Successfully parsed Identity Response'
|
|
1585
|
-
);
|
|
1586
|
-
|
|
1565
|
+
// https://go.mparticle.com/work/SQDSDKS-6356
|
|
1587
1566
|
//this covers an edge case where, users stored before "firstSeenTime" was introduced
|
|
1588
1567
|
//will not have a value for "fst" until the current MPID changes, and in some cases,
|
|
1589
1568
|
//the current MPID will never change
|
|
1590
1569
|
if (
|
|
1591
1570
|
method === Identify &&
|
|
1592
1571
|
prevUser &&
|
|
1593
|
-
identityApiResult.mpid ===
|
|
1572
|
+
identityApiResult.mpid === prevUserMPID
|
|
1594
1573
|
) {
|
|
1574
|
+
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1595
1575
|
mpInstance._Persistence.setFirstSeenTime(
|
|
1596
1576
|
identityApiResult.mpid
|
|
1597
1577
|
);
|
|
1598
1578
|
}
|
|
1599
1579
|
|
|
1600
|
-
|
|
1601
|
-
identityApiResult.mpid
|
|
1580
|
+
mpInstance._Store.addMpidToSessionHistory(
|
|
1581
|
+
identityApiResult.mpid,
|
|
1582
|
+
previousMPID
|
|
1602
1583
|
);
|
|
1603
1584
|
|
|
1604
|
-
if (
|
|
1605
|
-
mpInstance._Store.sessionId &&
|
|
1606
|
-
identityApiResult.mpid &&
|
|
1607
|
-
previousMPID !== identityApiResult.mpid &&
|
|
1608
|
-
indexOfMPID < 0
|
|
1609
|
-
) {
|
|
1610
|
-
mpInstance._Store.currentSessionMPIDs.push(
|
|
1611
|
-
identityApiResult.mpid
|
|
1612
|
-
);
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
if (indexOfMPID > -1) {
|
|
1616
|
-
mpInstance._Store.currentSessionMPIDs = mpInstance._Store.currentSessionMPIDs
|
|
1617
|
-
.slice(0, indexOfMPID)
|
|
1618
|
-
.concat(
|
|
1619
|
-
mpInstance._Store.currentSessionMPIDs.slice(
|
|
1620
|
-
indexOfMPID + 1,
|
|
1621
|
-
mpInstance._Store.currentSessionMPIDs.length
|
|
1622
|
-
)
|
|
1623
|
-
);
|
|
1624
|
-
mpInstance._Store.currentSessionMPIDs.push(
|
|
1625
|
-
identityApiResult.mpid
|
|
1626
|
-
);
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
1585
|
mpInstance._CookieSyncManager.attemptCookieSync(
|
|
1630
1586
|
previousMPID,
|
|
1631
1587
|
identityApiResult.mpid,
|
|
1632
1588
|
mpidIsNotInCookies
|
|
1633
1589
|
);
|
|
1634
1590
|
|
|
1635
|
-
|
|
1591
|
+
mpInstance._Persistence.swapCurrentUser(
|
|
1636
1592
|
previousMPID,
|
|
1637
1593
|
identityApiResult.mpid,
|
|
1638
1594
|
mpInstance._Store.currentSessionMPIDs
|
|
@@ -1640,11 +1596,10 @@ export default function Identity(mpInstance) {
|
|
|
1640
1596
|
|
|
1641
1597
|
if (
|
|
1642
1598
|
identityApiData &&
|
|
1643
|
-
identityApiData.userIdentities
|
|
1644
|
-
Object.keys(identityApiData.userIdentities).length
|
|
1599
|
+
!isEmpty(identityApiData.userIdentities)
|
|
1645
1600
|
) {
|
|
1646
1601
|
newIdentitiesByType = self.IdentityRequest.combineUserIdentities(
|
|
1647
|
-
|
|
1602
|
+
incomingUIByName,
|
|
1648
1603
|
identityApiData.userIdentities
|
|
1649
1604
|
);
|
|
1650
1605
|
}
|
|
@@ -1660,112 +1615,74 @@ export default function Identity(mpInstance) {
|
|
|
1660
1615
|
identityApiData
|
|
1661
1616
|
);
|
|
1662
1617
|
|
|
1618
|
+
// https://go.mparticle.com/work/SQDSDKS-6357
|
|
1663
1619
|
mpInstance._Store.context =
|
|
1664
1620
|
identityApiResult.context || mpInstance._Store.context;
|
|
1665
1621
|
}
|
|
1666
1622
|
|
|
1667
1623
|
newUser = mpInstance.Identity.getCurrentUser();
|
|
1668
1624
|
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
)
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
'Deprecated function onUserAlias will be removed in future releases'
|
|
1679
|
-
);
|
|
1680
|
-
identityApiData.onUserAlias(prevUser, newUser);
|
|
1681
|
-
} catch (e) {
|
|
1682
|
-
mpInstance.Logger.error(
|
|
1683
|
-
'There was an error with your onUserAlias function - ' +
|
|
1684
|
-
e
|
|
1685
|
-
);
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
var persistence = mpInstance._Persistence.getPersistence();
|
|
1625
|
+
// https://go.mparticle.com/work/SQDSDKS-6359
|
|
1626
|
+
tryOnUserAlias(
|
|
1627
|
+
prevUser,
|
|
1628
|
+
newUser,
|
|
1629
|
+
identityApiData,
|
|
1630
|
+
mpInstance.Logger
|
|
1631
|
+
);
|
|
1632
|
+
|
|
1633
|
+
const persistence = mpInstance._Persistence.getPersistence();
|
|
1689
1634
|
|
|
1690
1635
|
if (newUser) {
|
|
1691
1636
|
mpInstance._Persistence.storeDataInMemory(
|
|
1692
1637
|
persistence,
|
|
1693
1638
|
newUser.getMPID()
|
|
1694
1639
|
);
|
|
1695
|
-
if (
|
|
1696
|
-
!prevUser ||
|
|
1697
|
-
newUser.getMPID() !== prevUser.getMPID() ||
|
|
1698
|
-
prevUser.isLoggedIn() !== newUser.isLoggedIn()
|
|
1699
|
-
) {
|
|
1700
|
-
mpInstance._Forwarders.initForwarders(
|
|
1701
|
-
newUser.getUserIdentities().userIdentities,
|
|
1702
|
-
mpInstance._APIClient.prepareForwardingStats
|
|
1703
|
-
);
|
|
1704
|
-
}
|
|
1705
1640
|
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
newUser.getUserIdentities().userIdentities
|
|
1709
|
-
);
|
|
1710
|
-
mpInstance._Forwarders.setForwarderOnIdentityComplete(
|
|
1711
|
-
newUser,
|
|
1712
|
-
method
|
|
1713
|
-
);
|
|
1714
|
-
mpInstance._Forwarders.setForwarderOnUserIdentified(
|
|
1715
|
-
newUser
|
|
1716
|
-
);
|
|
1641
|
+
self.reinitForwardersOnUserChange(prevUser, newUser);
|
|
1642
|
+
self.setForwarderCallbacks(newUser, method);
|
|
1717
1643
|
}
|
|
1718
|
-
var newIdentitiesByName = {};
|
|
1719
1644
|
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
mpInstance._Helpers.parseNumber(key)
|
|
1724
|
-
)
|
|
1725
|
-
] = newIdentitiesByType[key];
|
|
1726
|
-
}
|
|
1645
|
+
const newIdentitiesByName = getNewIdentitiesByName(
|
|
1646
|
+
newIdentitiesByType
|
|
1647
|
+
);
|
|
1727
1648
|
|
|
1649
|
+
const uiByName =
|
|
1650
|
+
method === Modify ? previousUIByName : incomingUIByName;
|
|
1651
|
+
|
|
1652
|
+
// https://go.mparticle.com/work/SQDSDKS-6501
|
|
1728
1653
|
self.sendUserIdentityChangeEvent(
|
|
1729
1654
|
newIdentitiesByName,
|
|
1730
1655
|
method,
|
|
1731
1656
|
identityApiResult.mpid,
|
|
1732
|
-
|
|
1733
|
-
? previousUIByNameCopy
|
|
1734
|
-
: incomingMpidUIByNameCopy
|
|
1657
|
+
uiByName
|
|
1735
1658
|
);
|
|
1736
1659
|
}
|
|
1737
1660
|
|
|
1738
1661
|
if (callback) {
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
) {
|
|
1760
|
-
mpInstance.Logger.error(
|
|
1761
|
-
'Received HTTP response code of ' +
|
|
1762
|
-
xhr.status +
|
|
1763
|
-
' - ' +
|
|
1764
|
-
identityApiResult.errors[0].message
|
|
1765
|
-
);
|
|
1766
|
-
}
|
|
1662
|
+
const callbackCode =
|
|
1663
|
+
xhr.status === 0 ? HTTPCodes.noHttpCoverage : xhr.status;
|
|
1664
|
+
|
|
1665
|
+
mpInstance._Helpers.invokeCallback(
|
|
1666
|
+
callback,
|
|
1667
|
+
callbackCode,
|
|
1668
|
+
identityApiResult || null,
|
|
1669
|
+
newUser
|
|
1670
|
+
);
|
|
1671
|
+
} else if (
|
|
1672
|
+
identityApiResult &&
|
|
1673
|
+
!isEmpty(identityApiResult.errors)
|
|
1674
|
+
) {
|
|
1675
|
+
// https://go.mparticle.com/work/SQDSDKS-6500
|
|
1676
|
+
mpInstance.Logger.error(
|
|
1677
|
+
'Received HTTP response code of ' +
|
|
1678
|
+
xhr.status +
|
|
1679
|
+
' - ' +
|
|
1680
|
+
identityApiResult.errors[0].message
|
|
1681
|
+
);
|
|
1767
1682
|
}
|
|
1768
1683
|
|
|
1684
|
+
mpInstance.Logger.verbose('Successfully parsed Identity Response');
|
|
1685
|
+
|
|
1769
1686
|
mpInstance._APIClient.processQueuedEvents();
|
|
1770
1687
|
} catch (e) {
|
|
1771
1688
|
if (callback) {
|
|
@@ -1784,30 +1701,33 @@ export default function Identity(mpInstance) {
|
|
|
1784
1701
|
// send a user identity change request on identify, login, logout, modify when any values change.
|
|
1785
1702
|
// compare what identities exist vs what is previously was for the specific user if they were in memory before.
|
|
1786
1703
|
// if it's the first time the user is logging in, send a user identity change request with
|
|
1787
|
-
|
|
1788
1704
|
this.sendUserIdentityChangeEvent = function(
|
|
1789
1705
|
newUserIdentities,
|
|
1790
1706
|
method,
|
|
1791
1707
|
mpid,
|
|
1792
1708
|
prevUserIdentities
|
|
1793
1709
|
) {
|
|
1794
|
-
var currentUserInMemory, userIdentityChangeEvent;
|
|
1795
|
-
|
|
1796
1710
|
if (!mpid) {
|
|
1711
|
+
// https://go.mparticle.com/work/SQDSDKS-6501
|
|
1797
1712
|
if (method !== Modify) {
|
|
1798
1713
|
return;
|
|
1799
1714
|
}
|
|
1800
1715
|
}
|
|
1801
1716
|
|
|
1802
|
-
|
|
1717
|
+
// https://go.mparticle.com/work/SQDSDKS-6354
|
|
1718
|
+
const currentUserInMemory = this.IdentityAPI.getUser(mpid);
|
|
1803
1719
|
|
|
1804
1720
|
for (var identityType in newUserIdentities) {
|
|
1721
|
+
// Verifies a change actually happened
|
|
1805
1722
|
if (
|
|
1806
1723
|
prevUserIdentities[identityType] !==
|
|
1807
1724
|
newUserIdentities[identityType]
|
|
1808
1725
|
) {
|
|
1809
|
-
|
|
1810
|
-
|
|
1726
|
+
// If a new identity type was introduced when the identity changes
|
|
1727
|
+
// we need to notify the server so that the user profile is updated in
|
|
1728
|
+
// the mParticle UI.
|
|
1729
|
+
const isNewUserIdentityType = !prevUserIdentities[identityType];
|
|
1730
|
+
const userIdentityChangeEvent = self.createUserIdentityChange(
|
|
1811
1731
|
identityType,
|
|
1812
1732
|
newUserIdentities[identityType],
|
|
1813
1733
|
prevUserIdentities[identityType],
|
|
@@ -1825,7 +1745,7 @@ export default function Identity(mpInstance) {
|
|
|
1825
1745
|
identityType,
|
|
1826
1746
|
newIdentity,
|
|
1827
1747
|
oldIdentity,
|
|
1828
|
-
|
|
1748
|
+
isIdentityTypeNewToBatch,
|
|
1829
1749
|
userInMemory
|
|
1830
1750
|
) {
|
|
1831
1751
|
var userIdentityChangeEvent;
|
|
@@ -1837,7 +1757,7 @@ export default function Identity(mpInstance) {
|
|
|
1837
1757
|
New: {
|
|
1838
1758
|
IdentityType: identityType,
|
|
1839
1759
|
Identity: newIdentity,
|
|
1840
|
-
CreatedThisBatch:
|
|
1760
|
+
CreatedThisBatch: isIdentityTypeNewToBatch,
|
|
1841
1761
|
},
|
|
1842
1762
|
Old: {
|
|
1843
1763
|
IdentityType: identityType,
|
|
@@ -1902,4 +1822,40 @@ export default function Identity(mpInstance) {
|
|
|
1902
1822
|
}
|
|
1903
1823
|
return userAttributeChangeEvent;
|
|
1904
1824
|
};
|
|
1825
|
+
|
|
1826
|
+
this.reinitForwardersOnUserChange = function(prevUser, newUser) {
|
|
1827
|
+
if (hasMPIDAndUserLoginChanged(prevUser, newUser)) {
|
|
1828
|
+
mpInstance._Forwarders.initForwarders(
|
|
1829
|
+
newUser.getUserIdentities().userIdentities,
|
|
1830
|
+
mpInstance._APIClient.prepareForwardingStats
|
|
1831
|
+
);
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
|
|
1835
|
+
this.setForwarderCallbacks = function(user, method) {
|
|
1836
|
+
// https://go.mparticle.com/work/SQDSDKS-6036
|
|
1837
|
+
mpInstance._Forwarders.setForwarderUserIdentities(
|
|
1838
|
+
user.getUserIdentities().userIdentities
|
|
1839
|
+
);
|
|
1840
|
+
mpInstance._Forwarders.setForwarderOnIdentityComplete(user, method);
|
|
1841
|
+
mpInstance._Forwarders.setForwarderOnUserIdentified(user);
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
// https://go.mparticle.com/work/SQDSDKS-6359
|
|
1846
|
+
function tryOnUserAlias(previousUser, newUser, identityApiData, logger) {
|
|
1847
|
+
if (
|
|
1848
|
+
identityApiData &&
|
|
1849
|
+
identityApiData.onUserAlias &&
|
|
1850
|
+
isFunction(identityApiData.onUserAlias)
|
|
1851
|
+
) {
|
|
1852
|
+
try {
|
|
1853
|
+
logger.warning(generateDeprecationMessage('onUserAlias'));
|
|
1854
|
+
identityApiData.onUserAlias(previousUser, newUser);
|
|
1855
|
+
} catch (e) {
|
|
1856
|
+
logger.error(
|
|
1857
|
+
'There was an error with your onUserAlias function - ' + e
|
|
1858
|
+
);
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1905
1861
|
}
|
package/src/identityApiClient.js
CHANGED
|
@@ -10,6 +10,7 @@ export default function IdentityAPIClient(mpInstance) {
|
|
|
10
10
|
var xhr,
|
|
11
11
|
xhrCallback = function() {
|
|
12
12
|
if (xhr.readyState === 4) {
|
|
13
|
+
// https://go.mparticle.com/work/SQDSDKS-6368
|
|
13
14
|
mpInstance.Logger.verbose(
|
|
14
15
|
'Received ' + xhr.statusText + ' from server'
|
|
15
16
|
);
|
|
@@ -73,6 +74,7 @@ export default function IdentityAPIClient(mpInstance) {
|
|
|
73
74
|
previousMPID,
|
|
74
75
|
xhrCallback = function() {
|
|
75
76
|
if (xhr.readyState === 4) {
|
|
77
|
+
// https://go.mparticle.com/work/SQDSDKS-6368
|
|
76
78
|
mpInstance.Logger.verbose(
|
|
77
79
|
'Received ' + xhr.statusText + ' from server'
|
|
78
80
|
);
|
|
@@ -125,5 +125,10 @@ export interface IPersistence {
|
|
|
125
125
|
getDeviceId(): string;
|
|
126
126
|
setDeviceId(guid: string): void;
|
|
127
127
|
resetPersistence(): void;
|
|
128
|
+
swapCurrentUser(
|
|
129
|
+
previousMPID: MPID,
|
|
130
|
+
currentMPID: MPID,
|
|
131
|
+
currentSessionMPIDs?: MPID[]
|
|
132
|
+
): void;
|
|
128
133
|
forwardingStatsBatches: iForwardingStatsBatches;
|
|
129
134
|
}
|
package/src/persistence.js
CHANGED
|
@@ -1012,6 +1012,21 @@ export default function _Persistence(mpInstance) {
|
|
|
1012
1012
|
}
|
|
1013
1013
|
};
|
|
1014
1014
|
|
|
1015
|
+
this.swapCurrentUser = function(
|
|
1016
|
+
previousMPID,
|
|
1017
|
+
currentMPID,
|
|
1018
|
+
currentSessionMPIDs
|
|
1019
|
+
) {
|
|
1020
|
+
if (previousMPID && currentMPID && previousMPID !== currentMPID) {
|
|
1021
|
+
var persistence = self.getPersistence();
|
|
1022
|
+
if (persistence) {
|
|
1023
|
+
persistence.cu = currentMPID;
|
|
1024
|
+
persistence.gs.csm = currentSessionMPIDs;
|
|
1025
|
+
self.savePersistence(persistence);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1015
1030
|
// https://go.mparticle.com/work/SQDSDKS-6021
|
|
1016
1031
|
this.savePersistence = function(persistence) {
|
|
1017
1032
|
var encodedPersistence = self.encodePersistence(
|
|
@@ -1097,6 +1112,7 @@ export default function _Persistence(mpInstance) {
|
|
|
1097
1112
|
if (!mpid) {
|
|
1098
1113
|
return;
|
|
1099
1114
|
}
|
|
1115
|
+
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1100
1116
|
if (!time) {
|
|
1101
1117
|
time = new Date().getTime();
|
|
1102
1118
|
}
|
|
@@ -1137,6 +1153,7 @@ export default function _Persistence(mpInstance) {
|
|
|
1137
1153
|
if (!mpid) {
|
|
1138
1154
|
return;
|
|
1139
1155
|
}
|
|
1156
|
+
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1140
1157
|
if (!time) {
|
|
1141
1158
|
time = new Date().getTime();
|
|
1142
1159
|
}
|