@mparticle/web-mixpanel-kit 2.1.0 → 2.1.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/MixpanelEventForwarder.common.js +107 -6
- package/package.json +11 -8
- package/CHANGELOG.md +0 -6
|
@@ -14,6 +14,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
14
14
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
15
|
// See the License for the specific language governing permissions and
|
|
16
16
|
// limitations under the License.
|
|
17
|
+
|
|
18
|
+
// ** Glossary of terms
|
|
19
|
+
// Mixpanel Terms:
|
|
20
|
+
// user_id: A unique identifier used by the Mixpanel.identify method to identify a unique user. This will map to what an mParticle customer selects in the UI, which translates to the forwarderSettings.userIdentificationType.
|
|
21
|
+
// device_id: A unique identifier used by Mixpanel to identify an anonymous user, usually a guid. mParticle and Mixpnael generate their own device ids.
|
|
22
|
+
// distinct_id: A unique identifier that Mixpanel uses to bridge a user and a device. Usually the
|
|
23
|
+
// distinct_id has a prefix of $device:guid<device_id> to denote an anonymouse user
|
|
24
|
+
// and this will be replaced by the user_id once the user has been identified by
|
|
25
|
+
// a request to Mixpanel.identify
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line no-redeclare
|
|
17
28
|
var name = 'MixpanelEventForwarder',
|
|
18
29
|
moduleId = 10,
|
|
19
30
|
MessageType = {
|
|
@@ -34,7 +45,8 @@ var renderSnippet = function() {
|
|
|
34
45
|
};
|
|
35
46
|
/* eslint-enable */
|
|
36
47
|
|
|
37
|
-
|
|
48
|
+
// eslint-disable-next-line no-redeclare
|
|
49
|
+
var constructor = function () {
|
|
38
50
|
var self = this,
|
|
39
51
|
isInitialized = false,
|
|
40
52
|
forwarderSettings = null,
|
|
@@ -136,11 +148,89 @@ var constructor = function() {
|
|
|
136
148
|
}
|
|
137
149
|
}
|
|
138
150
|
|
|
139
|
-
function
|
|
140
|
-
|
|
141
|
-
var userIdentities = user.getUserIdentities()
|
|
151
|
+
function getUserIdentities(user) {
|
|
152
|
+
return user.getUserIdentities()
|
|
142
153
|
? user.getUserIdentities().userIdentities
|
|
143
154
|
: {};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function onLoginComplete(user) {
|
|
158
|
+
var userIdentities = getUserIdentities(user);
|
|
159
|
+
|
|
160
|
+
// When mParticle identifies a user, the user might
|
|
161
|
+
// actually be anonymous. We only want to send an
|
|
162
|
+
// identify request to Mixpanel if the user is
|
|
163
|
+
// actually known. Only known (logged in) users
|
|
164
|
+
// will have userIdentities.
|
|
165
|
+
if (!isEmpty(userIdentities)) {
|
|
166
|
+
sendIdentifyRequest(user, userIdentities);
|
|
167
|
+
} else {
|
|
168
|
+
return 'Logged in user does not have user identities and will not be sent to Mixpanel to Identify';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function onLogoutComplete() {
|
|
173
|
+
// For all Identity Requests, we run mixpanel.identify(<user_id>)
|
|
174
|
+
// as per Mixpanel's documentation https://docs.mixpanel.com/docs/tracking-methods/identifying-users
|
|
175
|
+
// except when a user logs out, where we run mixpanel.reset() to
|
|
176
|
+
// detach the Mixpanel distinct_id from the Mixpanel device_id
|
|
177
|
+
|
|
178
|
+
if (!isInitialized) {
|
|
179
|
+
return (
|
|
180
|
+
'Cannot call logout on forwarder: ' + name + ', not initialized'
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
mixpanel.mparticle.reset();
|
|
186
|
+
|
|
187
|
+
return 'Successfully called reset on forwarder: ' + name;
|
|
188
|
+
} catch (e) {
|
|
189
|
+
return 'Cannot call reset on forwarder: ' + name + ': ' + e;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function onIdentifyComplete(user) {
|
|
194
|
+
// Mixpanel considers any user with an identity to be a known user.
|
|
195
|
+
// In mParticle, a user will always have an MPID even if they are anonymous.
|
|
196
|
+
// When mParticle identifies a user, because the user might
|
|
197
|
+
// actually be anonymous, we only want to send an
|
|
198
|
+
// identify request to Mixpanel if the user is
|
|
199
|
+
// actually known. If a user has any user identities, they are
|
|
200
|
+
// considered to be "known" users.
|
|
201
|
+
var userIdentities = getUserIdentities(user);
|
|
202
|
+
|
|
203
|
+
if (!isEmpty(userIdentities)) {
|
|
204
|
+
sendIdentifyRequest(user, userIdentities);
|
|
205
|
+
} else {
|
|
206
|
+
return 'Identified user does not have user identities and will not be sent to Mixpanel to Identify';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function onModifyComplete(user) {
|
|
211
|
+
// Mixpanel does not have the concept of modifying a
|
|
212
|
+
// user's identity. For the time being, we will rely on
|
|
213
|
+
// doing a simple Mixpanel.identify request for backwards compatibility. However
|
|
214
|
+
// this method may be deprecated in a future release
|
|
215
|
+
var userIdentities = getUserIdentities(user);
|
|
216
|
+
|
|
217
|
+
if (!isEmpty(userIdentities)) {
|
|
218
|
+
sendIdentifyRequest(user, userIdentities);
|
|
219
|
+
} else {
|
|
220
|
+
return 'Modified user does not have user identities and will not be sent to Mixpanel to Identify';
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function sendIdentifyRequest(user, userIdentities) {
|
|
225
|
+
// We should only make Mixpanel.identify requests
|
|
226
|
+
// when a user has userIdentities and is therefore
|
|
227
|
+
// a known mParticle user and not anonymous
|
|
228
|
+
if (isEmpty(userIdentities)) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
var idForMixpanel;
|
|
233
|
+
|
|
144
234
|
switch (forwarderSettings.userIdentificationType) {
|
|
145
235
|
case 'CustomerId':
|
|
146
236
|
idForMixpanel = userIdentities.customerid;
|
|
@@ -231,7 +321,9 @@ var constructor = function() {
|
|
|
231
321
|
try {
|
|
232
322
|
mixpanel.mparticle.people.track_charge(
|
|
233
323
|
event.ProductAction.TotalAmount,
|
|
234
|
-
{
|
|
324
|
+
{
|
|
325
|
+
$time: new Date().toISOString(),
|
|
326
|
+
}
|
|
235
327
|
);
|
|
236
328
|
} catch (e) {
|
|
237
329
|
return 'Cannot log commerce event on forwarder: ' + name + ': ' + e;
|
|
@@ -242,8 +334,12 @@ var constructor = function() {
|
|
|
242
334
|
this.process = processEvent;
|
|
243
335
|
this.setUserAttribute = setUserAttribute;
|
|
244
336
|
this.setUserIdentity = setUserIdentity;
|
|
245
|
-
this.onUserIdentified = onUserIdentified;
|
|
246
337
|
this.removeUserAttribute = removeUserAttribute;
|
|
338
|
+
|
|
339
|
+
this.onIdentifyComplete = onIdentifyComplete;
|
|
340
|
+
this.onLoginComplete = onLoginComplete;
|
|
341
|
+
this.onLogoutComplete = onLogoutComplete;
|
|
342
|
+
this.onModifyComplete = onModifyComplete;
|
|
247
343
|
};
|
|
248
344
|
|
|
249
345
|
function getId() {
|
|
@@ -280,6 +376,10 @@ function register(config) {
|
|
|
280
376
|
);
|
|
281
377
|
}
|
|
282
378
|
|
|
379
|
+
function isEmpty(value) {
|
|
380
|
+
return value == null || !(Object.keys(value) || value).length;
|
|
381
|
+
}
|
|
382
|
+
|
|
283
383
|
function isObject(val) {
|
|
284
384
|
return (
|
|
285
385
|
val != null && typeof val === 'object' && Array.isArray(val) === false
|
|
@@ -296,6 +396,7 @@ if (typeof window !== 'undefined') {
|
|
|
296
396
|
}
|
|
297
397
|
}
|
|
298
398
|
|
|
399
|
+
// eslint-disable-next-line no-undef
|
|
299
400
|
var MixpanelEventForwarder = {
|
|
300
401
|
register: register,
|
|
301
402
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-mixpanel-kit",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
|
|
5
5
|
"description": "mParticle integration sdk for Mixpanel",
|
|
6
6
|
"browser": "dist/MixpanelEventForwarder.common.js",
|
|
@@ -11,20 +11,26 @@
|
|
|
11
11
|
"repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-mixpanel",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "rollup --config rollup.config.js",
|
|
14
|
+
"build:test": "rollup --config rollup.test.config.js",
|
|
14
15
|
"watch": "rollup --config rollup.config.js -w",
|
|
15
|
-
"test": "
|
|
16
|
+
"test": "npm run build && npm run build:test && DEBUG=false karma start test/karma.config.js",
|
|
17
|
+
"test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js"
|
|
16
18
|
},
|
|
17
19
|
"devDependencies": {
|
|
20
|
+
"@mparticle/web-sdk": "^2.23.7",
|
|
21
|
+
"@semantic-release/changelog": "^5.0.1",
|
|
22
|
+
"@semantic-release/exec": "^5.0.0",
|
|
23
|
+
"@semantic-release/git": "^9.0.0",
|
|
18
24
|
"chai": "^4.2.0",
|
|
19
|
-
"eslint-config-prettier": "
|
|
20
|
-
"eslint-plugin-prettier": "
|
|
25
|
+
"eslint-config-prettier": "9.0.0",
|
|
26
|
+
"eslint-plugin-prettier": "5.0.1",
|
|
21
27
|
"karma": "^5.1.0",
|
|
22
28
|
"karma-chai": "^0.1.0",
|
|
23
29
|
"karma-chrome-launcher": "^3.1.0",
|
|
24
30
|
"karma-firefox-launcher": "^1.3.0",
|
|
25
31
|
"karma-mocha": "^2.0.1",
|
|
26
32
|
"mocha": "^2.5.3",
|
|
27
|
-
"prettier": "^
|
|
33
|
+
"prettier": "^3.0.3",
|
|
28
34
|
"rollup": "^1.13.1",
|
|
29
35
|
"rollup-plugin-commonjs": "^10.0.0",
|
|
30
36
|
"rollup-plugin-node-resolve": "^5.0.1",
|
|
@@ -32,8 +38,5 @@
|
|
|
32
38
|
"should": "^7.1.0",
|
|
33
39
|
"watchify": "^3.11.1"
|
|
34
40
|
},
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"@mparticle/web-sdk": "^2.11.8"
|
|
37
|
-
},
|
|
38
41
|
"license": "Apache-2.0"
|
|
39
42
|
}
|