@mparticle/web-sdk 2.32.0 → 2.32.1
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 +18 -36
- package/dist/mparticle.esm.js +18 -36
- package/dist/mparticle.js +86 -117
- package/package.json +1 -1
- package/src/aliasRequestApiClient.ts +2 -1
- package/src/configAPIClient.ts +2 -12
- package/src/consent.ts +4 -0
- package/src/cookieSyncManager.ts +162 -0
- package/src/identity.js +1 -5
- package/src/identityApiClient.interfaces.ts +44 -0
- package/src/nativeSdkHelpers.interfaces.ts +13 -0
- package/src/persistence.interfaces.ts +3 -4
- package/src/sdkRuntimeModels.ts +5 -1
- package/src/store.ts +3 -3
- package/src/utils.ts +25 -0
- package/src/cookieSyncManager.js +0 -197
package/src/utils.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MPID } from '@mparticle/web-sdk';
|
|
1
2
|
import Constants from './constants';
|
|
2
3
|
|
|
3
4
|
const { Messages } = Constants;
|
|
@@ -175,6 +176,27 @@ const replaceApostrophesWithQuotes = (value: string): string =>
|
|
|
175
176
|
const replaceQuotesWithApostrophes = (value: string): string =>
|
|
176
177
|
value.replace(/\"/g, "'");
|
|
177
178
|
|
|
179
|
+
const replaceMPID = (value: string, mpid: MPID): string => value.replace('%%mpid%%', mpid);
|
|
180
|
+
|
|
181
|
+
const replaceAmpWithAmpersand = (value: string): string => value.replace(/&/g, '&');
|
|
182
|
+
|
|
183
|
+
const createCookieSyncUrl = (
|
|
184
|
+
mpid: MPID,
|
|
185
|
+
pixelUrl: string,
|
|
186
|
+
redirectUrl?: string
|
|
187
|
+
): string => {
|
|
188
|
+
const modifiedPixelUrl = replaceAmpWithAmpersand(pixelUrl);
|
|
189
|
+
const modifiedDirectUrl = redirectUrl
|
|
190
|
+
? replaceAmpWithAmpersand(redirectUrl)
|
|
191
|
+
: null;
|
|
192
|
+
|
|
193
|
+
const url = replaceMPID(modifiedPixelUrl, mpid);
|
|
194
|
+
const redirect = modifiedDirectUrl
|
|
195
|
+
? replaceMPID(modifiedDirectUrl, mpid)
|
|
196
|
+
: '';
|
|
197
|
+
return url + encodeURIComponent(redirect);
|
|
198
|
+
};
|
|
199
|
+
|
|
178
200
|
// FIXME: REFACTOR for V3
|
|
179
201
|
// only used in store.js to sanitize server-side formatting of
|
|
180
202
|
// booleans when checking for `isDevelopmentMode`
|
|
@@ -336,6 +358,7 @@ const getHref = (): string => {
|
|
|
336
358
|
export {
|
|
337
359
|
createCookieString,
|
|
338
360
|
revertCookieString,
|
|
361
|
+
createCookieSyncUrl,
|
|
339
362
|
valueof,
|
|
340
363
|
converted,
|
|
341
364
|
decoded,
|
|
@@ -366,4 +389,6 @@ export {
|
|
|
366
389
|
queryStringParser,
|
|
367
390
|
getCookies,
|
|
368
391
|
getHref,
|
|
392
|
+
replaceMPID,
|
|
393
|
+
replaceAmpWithAmpersand,
|
|
369
394
|
};
|
package/src/cookieSyncManager.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import Constants from './constants';
|
|
2
|
-
|
|
3
|
-
var Messages = Constants.Messages;
|
|
4
|
-
|
|
5
|
-
export default function cookieSyncManager(mpInstance) {
|
|
6
|
-
var self = this;
|
|
7
|
-
|
|
8
|
-
// Public
|
|
9
|
-
this.attemptCookieSync = function(previousMPID, mpid, mpidIsNotInCookies) {
|
|
10
|
-
// TODO: These should move inside the for loop
|
|
11
|
-
var pixelConfig,
|
|
12
|
-
lastSyncDateForModule,
|
|
13
|
-
url,
|
|
14
|
-
redirect,
|
|
15
|
-
urlWithRedirect,
|
|
16
|
-
requiresConsent;
|
|
17
|
-
|
|
18
|
-
// TODO: Make this exit quicker instead of nested
|
|
19
|
-
if (mpid && !mpInstance._Store.webviewBridgeEnabled) {
|
|
20
|
-
mpInstance._Store.pixelConfigurations.forEach(function(
|
|
21
|
-
pixelSettings
|
|
22
|
-
) {
|
|
23
|
-
// set requiresConsent to false to start each additional pixel configuration
|
|
24
|
-
// set to true only if filteringConsenRuleValues.values.length exists
|
|
25
|
-
requiresConsent = false;
|
|
26
|
-
|
|
27
|
-
// TODO: Replace with isEmpty
|
|
28
|
-
if (
|
|
29
|
-
pixelSettings.filteringConsentRuleValues &&
|
|
30
|
-
pixelSettings.filteringConsentRuleValues.values &&
|
|
31
|
-
pixelSettings.filteringConsentRuleValues.values.length
|
|
32
|
-
) {
|
|
33
|
-
requiresConsent = true;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
pixelConfig = {
|
|
37
|
-
// Kit Module ID
|
|
38
|
-
moduleId: pixelSettings.moduleId,
|
|
39
|
-
|
|
40
|
-
// Tells you how often we should do a cookie sync (in days)
|
|
41
|
-
frequencyCap: pixelSettings.frequencyCap,
|
|
42
|
-
|
|
43
|
-
// Url for cookie sync pixel
|
|
44
|
-
pixelUrl: self.replaceAmp(pixelSettings.pixelUrl),
|
|
45
|
-
|
|
46
|
-
// TODO: Document requirements for redirectUrl
|
|
47
|
-
redirectUrl: pixelSettings.redirectUrl
|
|
48
|
-
? self.replaceAmp(pixelSettings.redirectUrl)
|
|
49
|
-
: null,
|
|
50
|
-
|
|
51
|
-
// Filtering rules as defined in UI
|
|
52
|
-
filteringConsentRuleValues:
|
|
53
|
-
pixelSettings.filteringConsentRuleValues,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// TODO: combine replaceMPID and replaceAmp into sanitizeUrl function
|
|
57
|
-
url = self.replaceMPID(pixelConfig.pixelUrl, mpid);
|
|
58
|
-
redirect = pixelConfig.redirectUrl
|
|
59
|
-
? self.replaceMPID(pixelConfig.redirectUrl, mpid)
|
|
60
|
-
: '';
|
|
61
|
-
urlWithRedirect = url + encodeURIComponent(redirect);
|
|
62
|
-
|
|
63
|
-
// TODO: Refactor so that Persistence is only called once
|
|
64
|
-
// outside of the loop
|
|
65
|
-
var persistence = mpInstance._Persistence.getPersistence();
|
|
66
|
-
|
|
67
|
-
// TODO: Is there a historic reason for checking for previousMPID?
|
|
68
|
-
// it does not appear to be passed in anywhere
|
|
69
|
-
if (previousMPID && previousMPID !== mpid) {
|
|
70
|
-
if (persistence && persistence[mpid]) {
|
|
71
|
-
if (!persistence[mpid].csd) {
|
|
72
|
-
persistence[mpid].csd = {};
|
|
73
|
-
}
|
|
74
|
-
self.performCookieSync(
|
|
75
|
-
urlWithRedirect,
|
|
76
|
-
pixelConfig.moduleId,
|
|
77
|
-
mpid,
|
|
78
|
-
persistence[mpid].csd,
|
|
79
|
-
pixelConfig.filteringConsentRuleValues,
|
|
80
|
-
mpidIsNotInCookies,
|
|
81
|
-
requiresConsent
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return;
|
|
85
|
-
} else {
|
|
86
|
-
// TODO: Refactor to check for the inverse and exit early
|
|
87
|
-
// rather than nesting
|
|
88
|
-
if (persistence[mpid]) {
|
|
89
|
-
if (!persistence[mpid].csd) {
|
|
90
|
-
persistence[mpid].csd = {};
|
|
91
|
-
}
|
|
92
|
-
lastSyncDateForModule = persistence[mpid].csd[
|
|
93
|
-
pixelConfig.moduleId.toString()
|
|
94
|
-
]
|
|
95
|
-
? persistence[mpid].csd[
|
|
96
|
-
pixelConfig.moduleId.toString()
|
|
97
|
-
]
|
|
98
|
-
: null;
|
|
99
|
-
|
|
100
|
-
if (lastSyncDateForModule) {
|
|
101
|
-
// Check to see if we need to refresh cookieSync
|
|
102
|
-
if (
|
|
103
|
-
// TODO: Turn this into a convenience method for readability?
|
|
104
|
-
// We use similar comparisons elsewhere in the SDK,
|
|
105
|
-
// so perhaps we can make a time comparison convenience method
|
|
106
|
-
new Date().getTime() >
|
|
107
|
-
new Date(lastSyncDateForModule).getTime() +
|
|
108
|
-
pixelConfig.frequencyCap *
|
|
109
|
-
// TODO: Turn these numbers into a constant so
|
|
110
|
-
// we can remember what this number is for
|
|
111
|
-
60 *
|
|
112
|
-
1000 *
|
|
113
|
-
60 *
|
|
114
|
-
24
|
|
115
|
-
) {
|
|
116
|
-
self.performCookieSync(
|
|
117
|
-
urlWithRedirect,
|
|
118
|
-
pixelConfig.moduleId,
|
|
119
|
-
mpid,
|
|
120
|
-
persistence[mpid].csd,
|
|
121
|
-
pixelConfig.filteringConsentRuleValues,
|
|
122
|
-
mpidIsNotInCookies,
|
|
123
|
-
requiresConsent
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
self.performCookieSync(
|
|
128
|
-
urlWithRedirect,
|
|
129
|
-
pixelConfig.moduleId,
|
|
130
|
-
mpid,
|
|
131
|
-
persistence[mpid].csd,
|
|
132
|
-
pixelConfig.filteringConsentRuleValues,
|
|
133
|
-
mpidIsNotInCookies,
|
|
134
|
-
requiresConsent
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
// Private
|
|
144
|
-
this.replaceMPID = function(string, mpid) {
|
|
145
|
-
return string.replace('%%mpid%%', mpid);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// Private
|
|
149
|
-
// TODO: Rename function to replaceAmpWithAmpersand
|
|
150
|
-
this.replaceAmp = function(string) {
|
|
151
|
-
return string.replace(/&/g, '&');
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// Private
|
|
155
|
-
this.performCookieSync = function(
|
|
156
|
-
url,
|
|
157
|
-
moduleId,
|
|
158
|
-
mpid,
|
|
159
|
-
cookieSyncDates,
|
|
160
|
-
filteringConsentRuleValues,
|
|
161
|
-
mpidIsNotInCookies,
|
|
162
|
-
requiresConsent
|
|
163
|
-
) {
|
|
164
|
-
// if MPID is new to cookies, we should not try to perform the cookie sync
|
|
165
|
-
// because a cookie sync can only occur once a user either consents or doesn't
|
|
166
|
-
// we should not check if its enabled if the user has a blank consent
|
|
167
|
-
// TODO: We should do this check outside of this function
|
|
168
|
-
if (requiresConsent && mpidIsNotInCookies) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// TODO: Refactor so that check is made outside of the function.
|
|
173
|
-
// Cache or store the boolean so that it only gets called once per
|
|
174
|
-
// cookie sync attempt per module.
|
|
175
|
-
// Currently, attemptCookieSync is called as a loop and therefore this
|
|
176
|
-
// function polls the user object and consent multiple times.
|
|
177
|
-
if (
|
|
178
|
-
mpInstance._Consent.isEnabledForUserConsent(
|
|
179
|
-
filteringConsentRuleValues,
|
|
180
|
-
mpInstance.Identity.getCurrentUser()
|
|
181
|
-
)
|
|
182
|
-
) {
|
|
183
|
-
var img = document.createElement('img');
|
|
184
|
-
|
|
185
|
-
mpInstance.Logger.verbose(Messages.InformationMessages.CookieSync);
|
|
186
|
-
img.onload = function() {
|
|
187
|
-
// TODO: Break this out into a convenience method so we can unit test
|
|
188
|
-
cookieSyncDates[moduleId.toString()] = new Date().getTime();
|
|
189
|
-
mpInstance._Persistence.saveUserCookieSyncDatesToPersistence(
|
|
190
|
-
mpid,
|
|
191
|
-
cookieSyncDates
|
|
192
|
-
);
|
|
193
|
-
};
|
|
194
|
-
img.src = url;
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
}
|