@mparticle/web-sdk 2.26.6 → 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 +69 -56
- package/dist/mparticle.esm.js +69 -56
- package/dist/mparticle.js +933 -895
- package/package.json +1 -1
- package/src/identity.js +142 -184
- 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
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)) {
|
|
@@ -1482,41 +1487,34 @@ export default function Identity(mpInstance) {
|
|
|
1482
1487
|
knownIdentities,
|
|
1483
1488
|
parsingCachedResponse
|
|
1484
1489
|
) {
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
previousUIByName
|
|
1497
|
-
);
|
|
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
|
+
|
|
1498
1501
|
mpInstance._Store.identityCallInFlight = false;
|
|
1499
1502
|
|
|
1500
1503
|
try {
|
|
1501
1504
|
mpInstance.Logger.verbose(
|
|
1502
1505
|
'Parsing "' + method + '" identity response from server'
|
|
1503
1506
|
);
|
|
1504
|
-
if (xhr.responseText) {
|
|
1505
|
-
identityApiResult = JSON.parse(xhr.responseText);
|
|
1506
1507
|
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1508
|
+
identityApiResult = xhr.responseText
|
|
1509
|
+
? JSON.parse(xhr.responseText)
|
|
1510
|
+
: null;
|
|
1512
1511
|
|
|
1512
|
+
mpInstance._Store.isLoggedIn =
|
|
1513
|
+
identityApiResult?.is_logged_in || false;
|
|
1514
|
+
|
|
1515
|
+
// https://go.mparticle.com/work/SQDSDKS-6504
|
|
1513
1516
|
// set currentUser
|
|
1514
|
-
if (
|
|
1515
|
-
!prevUser ||
|
|
1516
|
-
(prevUser.getMPID() &&
|
|
1517
|
-
identityApiResult.mpid &&
|
|
1518
|
-
identityApiResult.mpid !== prevUser.getMPID())
|
|
1519
|
-
) {
|
|
1517
|
+
if (hasMPIDChanged(prevUser, identityApiResult)) {
|
|
1520
1518
|
mpInstance._Store.mpid = identityApiResult.mpid;
|
|
1521
1519
|
|
|
1522
1520
|
if (prevUser) {
|
|
@@ -1524,23 +1522,18 @@ export default function Identity(mpInstance) {
|
|
|
1524
1522
|
mpInstance._Persistence.setLastSeenTime(previousMPID);
|
|
1525
1523
|
}
|
|
1526
1524
|
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
mpidIsNotInCookies = true;
|
|
1525
|
+
mpidIsNotInCookies = !mpInstance._Persistence.getFirstSeenTime(
|
|
1526
|
+
identityApiResult.mpid
|
|
1527
|
+
);
|
|
1528
|
+
|
|
1529
|
+
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1533
1530
|
mpInstance._Persistence.setFirstSeenTime(
|
|
1534
1531
|
identityApiResult.mpid
|
|
1535
1532
|
);
|
|
1536
1533
|
}
|
|
1537
1534
|
|
|
1538
1535
|
if (xhr.status === 200) {
|
|
1539
|
-
if (
|
|
1540
|
-
mpInstance._Helpers.getFeatureFlag(
|
|
1541
|
-
Constants.FeatureFlags.CacheIdentity
|
|
1542
|
-
)
|
|
1543
|
-
) {
|
|
1536
|
+
if (getFeatureFlag(CacheIdentity)) {
|
|
1544
1537
|
cacheOrClearIdCache(
|
|
1545
1538
|
method,
|
|
1546
1539
|
knownIdentities,
|
|
@@ -1550,6 +1543,14 @@ export default function Identity(mpInstance) {
|
|
|
1550
1543
|
);
|
|
1551
1544
|
}
|
|
1552
1545
|
|
|
1546
|
+
const incomingUser = self.IdentityAPI.getUser(
|
|
1547
|
+
identityApiResult.mpid
|
|
1548
|
+
);
|
|
1549
|
+
|
|
1550
|
+
const incomingUIByName = incomingUser
|
|
1551
|
+
? incomingUser.getUserIdentities().userIdentities
|
|
1552
|
+
: {};
|
|
1553
|
+
|
|
1553
1554
|
if (method === Modify) {
|
|
1554
1555
|
newIdentitiesByType = mpInstance._Identity.IdentityRequest.combineUserIdentities(
|
|
1555
1556
|
previousUIByName,
|
|
@@ -1561,22 +1562,6 @@ export default function Identity(mpInstance) {
|
|
|
1561
1562
|
newIdentitiesByType
|
|
1562
1563
|
);
|
|
1563
1564
|
} 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
1565
|
// https://go.mparticle.com/work/SQDSDKS-6356
|
|
1581
1566
|
//this covers an edge case where, users stored before "firstSeenTime" was introduced
|
|
1582
1567
|
//will not have a value for "fst" until the current MPID changes, and in some cases,
|
|
@@ -1584,7 +1569,7 @@ export default function Identity(mpInstance) {
|
|
|
1584
1569
|
if (
|
|
1585
1570
|
method === Identify &&
|
|
1586
1571
|
prevUser &&
|
|
1587
|
-
identityApiResult.mpid ===
|
|
1572
|
+
identityApiResult.mpid === prevUserMPID
|
|
1588
1573
|
) {
|
|
1589
1574
|
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1590
1575
|
mpInstance._Persistence.setFirstSeenTime(
|
|
@@ -1592,35 +1577,11 @@ export default function Identity(mpInstance) {
|
|
|
1592
1577
|
);
|
|
1593
1578
|
}
|
|
1594
1579
|
|
|
1595
|
-
|
|
1596
|
-
identityApiResult.mpid
|
|
1580
|
+
mpInstance._Store.addMpidToSessionHistory(
|
|
1581
|
+
identityApiResult.mpid,
|
|
1582
|
+
previousMPID
|
|
1597
1583
|
);
|
|
1598
1584
|
|
|
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
1585
|
mpInstance._CookieSyncManager.attemptCookieSync(
|
|
1625
1586
|
previousMPID,
|
|
1626
1587
|
identityApiResult.mpid,
|
|
@@ -1635,11 +1596,10 @@ export default function Identity(mpInstance) {
|
|
|
1635
1596
|
|
|
1636
1597
|
if (
|
|
1637
1598
|
identityApiData &&
|
|
1638
|
-
identityApiData.userIdentities
|
|
1639
|
-
Object.keys(identityApiData.userIdentities).length
|
|
1599
|
+
!isEmpty(identityApiData.userIdentities)
|
|
1640
1600
|
) {
|
|
1641
1601
|
newIdentitiesByType = self.IdentityRequest.combineUserIdentities(
|
|
1642
|
-
|
|
1602
|
+
incomingUIByName,
|
|
1643
1603
|
identityApiData.userIdentities
|
|
1644
1604
|
);
|
|
1645
1605
|
}
|
|
@@ -1663,106 +1623,66 @@ export default function Identity(mpInstance) {
|
|
|
1663
1623
|
newUser = mpInstance.Identity.getCurrentUser();
|
|
1664
1624
|
|
|
1665
1625
|
// 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();
|
|
1626
|
+
tryOnUserAlias(
|
|
1627
|
+
prevUser,
|
|
1628
|
+
newUser,
|
|
1629
|
+
identityApiData,
|
|
1630
|
+
mpInstance.Logger
|
|
1631
|
+
);
|
|
1632
|
+
|
|
1633
|
+
const persistence = mpInstance._Persistence.getPersistence();
|
|
1686
1634
|
|
|
1687
1635
|
if (newUser) {
|
|
1688
1636
|
mpInstance._Persistence.storeDataInMemory(
|
|
1689
1637
|
persistence,
|
|
1690
1638
|
newUser.getMPID()
|
|
1691
1639
|
);
|
|
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
1640
|
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
newUser.getUserIdentities().userIdentities
|
|
1706
|
-
);
|
|
1707
|
-
mpInstance._Forwarders.setForwarderOnIdentityComplete(
|
|
1708
|
-
newUser,
|
|
1709
|
-
method
|
|
1710
|
-
);
|
|
1711
|
-
mpInstance._Forwarders.setForwarderOnUserIdentified(
|
|
1712
|
-
newUser
|
|
1713
|
-
);
|
|
1641
|
+
self.reinitForwardersOnUserChange(prevUser, newUser);
|
|
1642
|
+
self.setForwarderCallbacks(newUser, method);
|
|
1714
1643
|
}
|
|
1715
|
-
var newIdentitiesByName = {};
|
|
1716
1644
|
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
}
|
|
1645
|
+
const newIdentitiesByName = getNewIdentitiesByName(
|
|
1646
|
+
newIdentitiesByType
|
|
1647
|
+
);
|
|
1648
|
+
|
|
1649
|
+
const uiByName =
|
|
1650
|
+
method === Modify ? previousUIByName : incomingUIByName;
|
|
1724
1651
|
|
|
1652
|
+
// https://go.mparticle.com/work/SQDSDKS-6501
|
|
1725
1653
|
self.sendUserIdentityChangeEvent(
|
|
1726
1654
|
newIdentitiesByName,
|
|
1727
1655
|
method,
|
|
1728
1656
|
identityApiResult.mpid,
|
|
1729
|
-
|
|
1730
|
-
? previousUIByNameCopy
|
|
1731
|
-
: incomingMpidUIByNameCopy
|
|
1657
|
+
uiByName
|
|
1732
1658
|
);
|
|
1733
1659
|
}
|
|
1734
1660
|
|
|
1735
1661
|
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
|
-
}
|
|
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
|
+
);
|
|
1764
1682
|
}
|
|
1765
1683
|
|
|
1684
|
+
mpInstance.Logger.verbose('Successfully parsed Identity Response');
|
|
1685
|
+
|
|
1766
1686
|
mpInstance._APIClient.processQueuedEvents();
|
|
1767
1687
|
} catch (e) {
|
|
1768
1688
|
if (callback) {
|
|
@@ -1781,31 +1701,33 @@ export default function Identity(mpInstance) {
|
|
|
1781
1701
|
// send a user identity change request on identify, login, logout, modify when any values change.
|
|
1782
1702
|
// compare what identities exist vs what is previously was for the specific user if they were in memory before.
|
|
1783
1703
|
// if it's the first time the user is logging in, send a user identity change request with
|
|
1784
|
-
|
|
1785
1704
|
this.sendUserIdentityChangeEvent = function(
|
|
1786
1705
|
newUserIdentities,
|
|
1787
1706
|
method,
|
|
1788
1707
|
mpid,
|
|
1789
1708
|
prevUserIdentities
|
|
1790
1709
|
) {
|
|
1791
|
-
var currentUserInMemory, userIdentityChangeEvent;
|
|
1792
|
-
|
|
1793
1710
|
if (!mpid) {
|
|
1711
|
+
// https://go.mparticle.com/work/SQDSDKS-6501
|
|
1794
1712
|
if (method !== Modify) {
|
|
1795
1713
|
return;
|
|
1796
1714
|
}
|
|
1797
1715
|
}
|
|
1798
1716
|
|
|
1799
1717
|
// https://go.mparticle.com/work/SQDSDKS-6354
|
|
1800
|
-
currentUserInMemory = this.IdentityAPI.getUser(mpid);
|
|
1718
|
+
const currentUserInMemory = this.IdentityAPI.getUser(mpid);
|
|
1801
1719
|
|
|
1802
1720
|
for (var identityType in newUserIdentities) {
|
|
1721
|
+
// Verifies a change actually happened
|
|
1803
1722
|
if (
|
|
1804
1723
|
prevUserIdentities[identityType] !==
|
|
1805
1724
|
newUserIdentities[identityType]
|
|
1806
1725
|
) {
|
|
1807
|
-
|
|
1808
|
-
|
|
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(
|
|
1809
1731
|
identityType,
|
|
1810
1732
|
newUserIdentities[identityType],
|
|
1811
1733
|
prevUserIdentities[identityType],
|
|
@@ -1823,7 +1745,7 @@ export default function Identity(mpInstance) {
|
|
|
1823
1745
|
identityType,
|
|
1824
1746
|
newIdentity,
|
|
1825
1747
|
oldIdentity,
|
|
1826
|
-
|
|
1748
|
+
isIdentityTypeNewToBatch,
|
|
1827
1749
|
userInMemory
|
|
1828
1750
|
) {
|
|
1829
1751
|
var userIdentityChangeEvent;
|
|
@@ -1835,7 +1757,7 @@ export default function Identity(mpInstance) {
|
|
|
1835
1757
|
New: {
|
|
1836
1758
|
IdentityType: identityType,
|
|
1837
1759
|
Identity: newIdentity,
|
|
1838
|
-
CreatedThisBatch:
|
|
1760
|
+
CreatedThisBatch: isIdentityTypeNewToBatch,
|
|
1839
1761
|
},
|
|
1840
1762
|
Old: {
|
|
1841
1763
|
IdentityType: identityType,
|
|
@@ -1900,4 +1822,40 @@ export default function Identity(mpInstance) {
|
|
|
1900
1822
|
}
|
|
1901
1823
|
return userAttributeChangeEvent;
|
|
1902
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
|
+
}
|
|
1903
1861
|
}
|
package/src/store.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
isEmpty,
|
|
26
26
|
isNumber,
|
|
27
27
|
isObject,
|
|
28
|
+
moveElementToEnd,
|
|
28
29
|
parseNumber,
|
|
29
30
|
returnConvertedBoolean,
|
|
30
31
|
} from './utils';
|
|
@@ -186,6 +187,7 @@ export interface IStore {
|
|
|
186
187
|
getLastSeenTime?(mpid: MPID): number;
|
|
187
188
|
setLastSeenTime?(mpid: MPID, time?: number): void;
|
|
188
189
|
|
|
190
|
+
addMpidToSessionHistory?(mpid: MPID, previousMpid?: MPID): void;
|
|
189
191
|
hasInvalidIdentifyRequest?: () => boolean;
|
|
190
192
|
nullifySession?: () => void;
|
|
191
193
|
processConfig(config: SDKInitConfig): void;
|
|
@@ -494,6 +496,22 @@ export default function Store(
|
|
|
494
496
|
mpInstance._Persistence.update();
|
|
495
497
|
};
|
|
496
498
|
|
|
499
|
+
this.addMpidToSessionHistory = (mpid: MPID, previousMPID?: MPID): void => {
|
|
500
|
+
const indexOfMPID = this.currentSessionMPIDs.indexOf(mpid);
|
|
501
|
+
|
|
502
|
+
if (mpid && previousMPID !== mpid && indexOfMPID < 0) {
|
|
503
|
+
this.currentSessionMPIDs.push(mpid);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (indexOfMPID >= 0) {
|
|
508
|
+
this.currentSessionMPIDs = moveElementToEnd(
|
|
509
|
+
this.currentSessionMPIDs,
|
|
510
|
+
indexOfMPID
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
497
515
|
this.getFirstSeenTime = (mpid: MPID) => {
|
|
498
516
|
if (!mpid) {
|
|
499
517
|
return null;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { IdentityType } from './types.interfaces';
|
|
2
|
+
import { parseNumber } from './utils';
|
|
3
|
+
|
|
4
|
+
export interface IIdentitiesByType {
|
|
5
|
+
[key: number]: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getNewIdentitiesByName(newIdentitiesByType: IIdentitiesByType) {
|
|
9
|
+
const newIdentitiesByName = {};
|
|
10
|
+
|
|
11
|
+
for (var key in newIdentitiesByType) {
|
|
12
|
+
const identityNameKey = getIdentityName(parseNumber(key));
|
|
13
|
+
newIdentitiesByName[identityNameKey] = newIdentitiesByType[key];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return newIdentitiesByName;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getIdentityName(identityType: IdentityType): string | null {
|
|
20
|
+
switch (identityType) {
|
|
21
|
+
case IdentityType.Other:
|
|
22
|
+
return 'other';
|
|
23
|
+
case IdentityType.CustomerId:
|
|
24
|
+
return 'customerid';
|
|
25
|
+
case IdentityType.Facebook:
|
|
26
|
+
return 'facebook';
|
|
27
|
+
case IdentityType.Twitter:
|
|
28
|
+
return 'twitter';
|
|
29
|
+
case IdentityType.Google:
|
|
30
|
+
return 'google';
|
|
31
|
+
case IdentityType.Microsoft:
|
|
32
|
+
return 'microsoft';
|
|
33
|
+
case IdentityType.Yahoo:
|
|
34
|
+
return 'yahoo';
|
|
35
|
+
case IdentityType.Email:
|
|
36
|
+
return 'email';
|
|
37
|
+
case IdentityType.FacebookCustomAudienceId:
|
|
38
|
+
return 'facebookcustomaudienceid';
|
|
39
|
+
case IdentityType.Other2:
|
|
40
|
+
return 'other2';
|
|
41
|
+
case IdentityType.Other3:
|
|
42
|
+
return 'other3';
|
|
43
|
+
case IdentityType.Other4:
|
|
44
|
+
return 'other4';
|
|
45
|
+
case IdentityType.Other5:
|
|
46
|
+
return 'other5';
|
|
47
|
+
case IdentityType.Other6:
|
|
48
|
+
return 'other6';
|
|
49
|
+
case IdentityType.Other7:
|
|
50
|
+
return 'other7';
|
|
51
|
+
case IdentityType.Other8:
|
|
52
|
+
return 'other8';
|
|
53
|
+
case IdentityType.Other9:
|
|
54
|
+
return 'other9';
|
|
55
|
+
case IdentityType.Other10:
|
|
56
|
+
return 'other10';
|
|
57
|
+
case IdentityType.MobileNumber:
|
|
58
|
+
return 'mobile_number';
|
|
59
|
+
case IdentityType.PhoneNumber2:
|
|
60
|
+
return 'phone_number_2';
|
|
61
|
+
case IdentityType.PhoneNumber3:
|
|
62
|
+
return 'phone_number_3';
|
|
63
|
+
default:
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/types.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getIdentityName } from './type-utils';
|
|
2
|
+
|
|
1
3
|
var MessageType = {
|
|
2
4
|
SessionStart: 1,
|
|
3
5
|
SessionEnd: 2,
|
|
@@ -209,50 +211,7 @@ IdentityType.getIdentityType = function(identityName) {
|
|
|
209
211
|
};
|
|
210
212
|
|
|
211
213
|
IdentityType.getIdentityName = function(identityType) {
|
|
212
|
-
|
|
213
|
-
case IdentityType.Other:
|
|
214
|
-
return 'other';
|
|
215
|
-
case IdentityType.CustomerId:
|
|
216
|
-
return 'customerid';
|
|
217
|
-
case IdentityType.Facebook:
|
|
218
|
-
return 'facebook';
|
|
219
|
-
case IdentityType.Twitter:
|
|
220
|
-
return 'twitter';
|
|
221
|
-
case IdentityType.Google:
|
|
222
|
-
return 'google';
|
|
223
|
-
case IdentityType.Microsoft:
|
|
224
|
-
return 'microsoft';
|
|
225
|
-
case IdentityType.Yahoo:
|
|
226
|
-
return 'yahoo';
|
|
227
|
-
case IdentityType.Email:
|
|
228
|
-
return 'email';
|
|
229
|
-
case IdentityType.FacebookCustomAudienceId:
|
|
230
|
-
return 'facebookcustomaudienceid';
|
|
231
|
-
case IdentityType.Other2:
|
|
232
|
-
return 'other2';
|
|
233
|
-
case IdentityType.Other3:
|
|
234
|
-
return 'other3';
|
|
235
|
-
case IdentityType.Other4:
|
|
236
|
-
return 'other4';
|
|
237
|
-
case IdentityType.Other5:
|
|
238
|
-
return 'other5';
|
|
239
|
-
case IdentityType.Other6:
|
|
240
|
-
return 'other6';
|
|
241
|
-
case IdentityType.Other7:
|
|
242
|
-
return 'other7';
|
|
243
|
-
case IdentityType.Other8:
|
|
244
|
-
return 'other8';
|
|
245
|
-
case IdentityType.Other9:
|
|
246
|
-
return 'other9';
|
|
247
|
-
case IdentityType.Other10:
|
|
248
|
-
return 'other10';
|
|
249
|
-
case IdentityType.MobileNumber:
|
|
250
|
-
return 'mobile_number';
|
|
251
|
-
case IdentityType.PhoneNumber2:
|
|
252
|
-
return 'phone_number_2';
|
|
253
|
-
case IdentityType.PhoneNumber3:
|
|
254
|
-
return 'phone_number_3';
|
|
255
|
-
}
|
|
214
|
+
return getIdentityName(identityType);
|
|
256
215
|
};
|
|
257
216
|
|
|
258
217
|
var ProductActionType = {
|