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