@mparticle/web-mixpanel-kit 2.0.3 → 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 +329 -198
- package/package.json +11 -5
|
@@ -14,261 +14,392 @@ 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
|
-
var name = 'MixpanelEventForwarder',
|
|
18
|
-
moduleId = 10,
|
|
19
|
-
MessageType = {
|
|
20
|
-
SessionStart: 1,
|
|
21
|
-
SessionEnd : 2,
|
|
22
|
-
PageView : 3,
|
|
23
|
-
PageEvent : 4,
|
|
24
|
-
CrashReport : 5,
|
|
25
|
-
OptOut : 6,
|
|
26
|
-
Commerce : 16
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var constructor = function () {
|
|
31
|
-
var self = this,
|
|
32
|
-
isInitialized = false,
|
|
33
|
-
forwarderSettings = null,
|
|
34
|
-
reportingService = null;
|
|
35
17
|
|
|
36
|
-
|
|
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
|
|
28
|
+
var name = 'MixpanelEventForwarder',
|
|
29
|
+
moduleId = 10,
|
|
30
|
+
MessageType = {
|
|
31
|
+
SessionStart: 1,
|
|
32
|
+
SessionEnd: 2,
|
|
33
|
+
PageView: 3,
|
|
34
|
+
PageEvent: 4,
|
|
35
|
+
CrashReport: 5,
|
|
36
|
+
OptOut: 6,
|
|
37
|
+
Commerce: 16,
|
|
38
|
+
};
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
/* eslint-disable */
|
|
41
|
+
// prettier-ignore
|
|
42
|
+
var renderSnippet = function() {
|
|
43
|
+
(function(e,b){if (!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)));};}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
|
44
|
+
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d]);};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f);}})(document,window.mixpanel||[]);
|
|
45
|
+
};
|
|
46
|
+
/* eslint-enable */
|
|
47
|
+
|
|
48
|
+
// eslint-disable-next-line no-redeclare
|
|
49
|
+
var constructor = function () {
|
|
50
|
+
var self = this,
|
|
51
|
+
isInitialized = false,
|
|
52
|
+
forwarderSettings = null,
|
|
53
|
+
reportingService = null,
|
|
54
|
+
useMixpanelPeople = false;
|
|
55
|
+
|
|
56
|
+
self.name = name;
|
|
57
|
+
|
|
58
|
+
function initForwarder(settings, service, testMode) {
|
|
59
|
+
forwarderSettings = settings;
|
|
60
|
+
useMixpanelPeople = forwarderSettings.useMixpanelPeople === 'True';
|
|
61
|
+
reportingService = service;
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
if (!testMode) {
|
|
65
|
+
renderSnippet();
|
|
66
|
+
}
|
|
67
|
+
mixpanel.init(
|
|
68
|
+
settings.token,
|
|
69
|
+
{
|
|
70
|
+
api_host: forwarderSettings.baseUrl,
|
|
71
|
+
},
|
|
72
|
+
'mparticle'
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
isInitialized = true;
|
|
76
|
+
|
|
77
|
+
return 'Successfully initialized: ' + name;
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return 'Cannot initialize forwarder: ' + name + ': ' + e;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
41
82
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/* eslint-disable */
|
|
45
|
-
(function(e,b){if (!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)));};}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
|
46
|
-
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d]);};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f);}})(document,window.mixpanel||[]);
|
|
47
|
-
/* eslint-enable */
|
|
48
|
-
mixpanel.init(settings.token, {}, 'mparticle');
|
|
49
|
-
}
|
|
83
|
+
function processEvent(event) {
|
|
84
|
+
var reportEvent = false;
|
|
50
85
|
|
|
51
|
-
|
|
86
|
+
if (!isInitialized) {
|
|
87
|
+
return 'Cannot send to forwarder: ' + name + ', not initialized';
|
|
88
|
+
}
|
|
52
89
|
|
|
53
|
-
|
|
90
|
+
try {
|
|
91
|
+
if (event.EventDataType == MessageType.PageEvent) {
|
|
92
|
+
reportEvent = true;
|
|
93
|
+
logEvent(event);
|
|
94
|
+
} else if (event.EventDataType == MessageType.PageView) {
|
|
95
|
+
event.EventName = 'Viewed ' + event.EventName;
|
|
96
|
+
reportEvent = true;
|
|
97
|
+
logEvent(event);
|
|
98
|
+
} else if (
|
|
99
|
+
event.EventDataType == MessageType.Commerce &&
|
|
100
|
+
event.ProductAction &&
|
|
101
|
+
event.ProductAction.ProductActionType ==
|
|
102
|
+
window.mParticle.ProductActionType.Purchase
|
|
103
|
+
) {
|
|
104
|
+
reportEvent = true;
|
|
105
|
+
logCommerceEvent(event);
|
|
54
106
|
}
|
|
55
|
-
|
|
56
|
-
|
|
107
|
+
|
|
108
|
+
if (reportEvent && reportingService) {
|
|
109
|
+
reportingService(self, event);
|
|
57
110
|
}
|
|
111
|
+
|
|
112
|
+
return 'Successfully sent to forwarder: ' + name;
|
|
113
|
+
} catch (e) {
|
|
114
|
+
return 'Cannot send to forwarder: ' + name + ' ' + e;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function setUserIdentity(id, type) {
|
|
119
|
+
if (window.mParticle.getVersion()[0] !== '1') {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!id) {
|
|
123
|
+
return (
|
|
124
|
+
'Cannot call setUserIdentity on forwarder: ' +
|
|
125
|
+
name +
|
|
126
|
+
' without ID'
|
|
127
|
+
);
|
|
58
128
|
}
|
|
59
129
|
|
|
60
|
-
|
|
61
|
-
|
|
130
|
+
if (!isInitialized) {
|
|
131
|
+
return (
|
|
132
|
+
'Cannot call setUserIdentity on forwarder: ' +
|
|
133
|
+
name +
|
|
134
|
+
', not initialized'
|
|
135
|
+
);
|
|
136
|
+
}
|
|
62
137
|
|
|
63
|
-
|
|
64
|
-
|
|
138
|
+
try {
|
|
139
|
+
if (window.mParticle.IdentityType.Alias == type) {
|
|
140
|
+
mixpanel.mparticle.alias(id.toString());
|
|
141
|
+
} else {
|
|
142
|
+
mixpanel.mparticle.identify(id.toString());
|
|
65
143
|
}
|
|
66
144
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
else if (event.EventDataType == MessageType.PageView) {
|
|
73
|
-
event.EventName = 'Viewed ' + event.EventName;
|
|
74
|
-
reportEvent = true;
|
|
75
|
-
logEvent(event);
|
|
76
|
-
}
|
|
77
|
-
else if (event.EventDataType == MessageType.Commerce &&
|
|
78
|
-
event.ProductAction &&
|
|
79
|
-
event.ProductAction.ProductActionType == window.mParticle.ProductActionType.Purchase) {
|
|
80
|
-
|
|
81
|
-
reportEvent = true;
|
|
82
|
-
logCommerceEvent(event);
|
|
83
|
-
}
|
|
145
|
+
return 'Successfully called identify on forwarder: ' + name;
|
|
146
|
+
} catch (e) {
|
|
147
|
+
return 'Cannot call identify on forwarder: ' + name + ': ' + e;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
84
150
|
|
|
85
|
-
|
|
86
|
-
|
|
151
|
+
function getUserIdentities(user) {
|
|
152
|
+
return user.getUserIdentities()
|
|
153
|
+
? user.getUserIdentities().userIdentities
|
|
154
|
+
: {};
|
|
155
|
+
}
|
|
87
156
|
|
|
88
|
-
|
|
89
|
-
|
|
157
|
+
function onLoginComplete(user) {
|
|
158
|
+
var userIdentities = getUserIdentities(user);
|
|
90
159
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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';
|
|
96
169
|
}
|
|
170
|
+
}
|
|
97
171
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return 'Can\'t call setUserIdentity on forwarder: ' + name + ' without ID';
|
|
104
|
-
}
|
|
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
|
|
105
177
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
178
|
+
if (!isInitialized) {
|
|
179
|
+
return (
|
|
180
|
+
'Cannot call logout on forwarder: ' + name + ', not initialized'
|
|
181
|
+
);
|
|
182
|
+
}
|
|
109
183
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
mixpanel.mparticle.alias(id.toString());
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
mixpanel.mparticle.identify(id.toString());
|
|
116
|
-
}
|
|
184
|
+
try {
|
|
185
|
+
mixpanel.mparticle.reset();
|
|
117
186
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return 'Can\'t call identify on forwarder: ' + name + ': ' + e;
|
|
122
|
-
}
|
|
187
|
+
return 'Successfully called reset on forwarder: ' + name;
|
|
188
|
+
} catch (e) {
|
|
189
|
+
return 'Cannot call reset on forwarder: ' + name + ': ' + e;
|
|
123
190
|
}
|
|
191
|
+
}
|
|
124
192
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
case 'Other3':
|
|
142
|
-
idForMixpanel = userIdentities.other3;
|
|
143
|
-
break;
|
|
144
|
-
case 'Other4':
|
|
145
|
-
idForMixpanel = userIdentities.other4;
|
|
146
|
-
break;
|
|
147
|
-
default:
|
|
148
|
-
idForMixpanel = userIdentities.customerid;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (!isInitialized) {
|
|
153
|
-
return 'Can\'t call identify on forwarder: ' + name + ', not initialized';
|
|
154
|
-
}
|
|
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
|
+
}
|
|
155
209
|
|
|
156
|
-
|
|
157
|
-
|
|
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);
|
|
158
216
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
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';
|
|
164
221
|
}
|
|
222
|
+
}
|
|
165
223
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
+
}
|
|
169
231
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
232
|
+
var idForMixpanel;
|
|
233
|
+
|
|
234
|
+
switch (forwarderSettings.userIdentificationType) {
|
|
235
|
+
case 'CustomerId':
|
|
236
|
+
idForMixpanel = userIdentities.customerid;
|
|
237
|
+
break;
|
|
238
|
+
case 'MPID':
|
|
239
|
+
idForMixpanel = user.getMPID();
|
|
240
|
+
break;
|
|
241
|
+
case 'Other':
|
|
242
|
+
idForMixpanel = userIdentities.other;
|
|
243
|
+
break;
|
|
244
|
+
case 'Other2':
|
|
245
|
+
idForMixpanel = userIdentities.other2;
|
|
246
|
+
break;
|
|
247
|
+
case 'Other3':
|
|
248
|
+
idForMixpanel = userIdentities.other3;
|
|
249
|
+
break;
|
|
250
|
+
case 'Other4':
|
|
251
|
+
idForMixpanel = userIdentities.other4;
|
|
252
|
+
break;
|
|
253
|
+
default:
|
|
254
|
+
idForMixpanel = userIdentities.customerid;
|
|
255
|
+
break;
|
|
180
256
|
}
|
|
181
257
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
catch(e) {
|
|
191
|
-
return 'Can\'t call unregister on forwarder: ' + name + ': ' + e;
|
|
192
|
-
}
|
|
258
|
+
if (!isInitialized) {
|
|
259
|
+
return (
|
|
260
|
+
'Cannot call identify on forwarder: ' +
|
|
261
|
+
name +
|
|
262
|
+
', not initialized'
|
|
263
|
+
);
|
|
193
264
|
}
|
|
194
265
|
|
|
195
|
-
|
|
196
|
-
|
|
266
|
+
try {
|
|
267
|
+
mixpanel.mparticle.identify(idForMixpanel);
|
|
197
268
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
event.EventAttributes);
|
|
202
|
-
}
|
|
203
|
-
catch(e) {
|
|
204
|
-
return 'Can\'t log event on forwarder: ' + name + ': ' + e;
|
|
205
|
-
}
|
|
269
|
+
return 'Successfully called identify on forwarder: ' + name;
|
|
270
|
+
} catch (e) {
|
|
271
|
+
return 'Cannot call identify on forwarder: ' + name + ': ' + e;
|
|
206
272
|
}
|
|
273
|
+
}
|
|
207
274
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
275
|
+
function setUserAttribute(key, value) {
|
|
276
|
+
var attr = {};
|
|
277
|
+
attr[key] = value;
|
|
212
278
|
|
|
213
|
-
|
|
214
|
-
|
|
279
|
+
try {
|
|
280
|
+
if (useMixpanelPeople) {
|
|
281
|
+
mixpanel.mparticle.people.set(attr);
|
|
282
|
+
} else {
|
|
283
|
+
mixpanel.mparticle.register(attr);
|
|
215
284
|
}
|
|
216
|
-
|
|
217
|
-
|
|
285
|
+
} catch (e) {
|
|
286
|
+
return 'Cannot call register on forwarder: ' + name + ': ' + e;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function removeUserAttribute(attribute) {
|
|
291
|
+
try {
|
|
292
|
+
if (useMixpanelPeople) {
|
|
293
|
+
mixpanel.mparticle.people.unset(attribute);
|
|
294
|
+
} else {
|
|
295
|
+
mixpanel.mparticle.unregister(attribute);
|
|
218
296
|
}
|
|
297
|
+
} catch (e) {
|
|
298
|
+
return 'Cannot call unregister on forwarder: ' + name + ': ' + e;
|
|
219
299
|
}
|
|
300
|
+
}
|
|
220
301
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.setUserAttribute = setUserAttribute;
|
|
224
|
-
this.setUserIdentity = setUserIdentity;
|
|
225
|
-
this.onUserIdentified = onUserIdentified;
|
|
226
|
-
this.removeUserAttribute = removeUserAttribute;
|
|
227
|
-
};
|
|
302
|
+
function logEvent(event) {
|
|
303
|
+
event.EventAttributes = event.EventAttributes || {};
|
|
228
304
|
|
|
229
|
-
|
|
230
|
-
|
|
305
|
+
try {
|
|
306
|
+
mixpanel.mparticle.track(event.EventName, event.EventAttributes);
|
|
307
|
+
} catch (e) {
|
|
308
|
+
return 'Cannot log event on forwarder: ' + name + ': ' + e;
|
|
309
|
+
}
|
|
231
310
|
}
|
|
232
311
|
|
|
233
|
-
function
|
|
234
|
-
if (!
|
|
235
|
-
|
|
236
|
-
|
|
312
|
+
function logCommerceEvent(event) {
|
|
313
|
+
if (!useMixpanelPeople) {
|
|
314
|
+
return (
|
|
315
|
+
'Cannot log commerce event on forwarder: ' +
|
|
316
|
+
name +
|
|
317
|
+
', useMixpanelPeople flag is not set'
|
|
318
|
+
);
|
|
237
319
|
}
|
|
238
320
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
321
|
+
try {
|
|
322
|
+
mixpanel.mparticle.people.track_charge(
|
|
323
|
+
event.ProductAction.TotalAmount,
|
|
324
|
+
{
|
|
325
|
+
$time: new Date().toISOString(),
|
|
326
|
+
}
|
|
327
|
+
);
|
|
328
|
+
} catch (e) {
|
|
329
|
+
return 'Cannot log commerce event on forwarder: ' + name + ': ' + e;
|
|
242
330
|
}
|
|
331
|
+
}
|
|
243
332
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
333
|
+
this.init = initForwarder;
|
|
334
|
+
this.process = processEvent;
|
|
335
|
+
this.setUserAttribute = setUserAttribute;
|
|
336
|
+
this.setUserIdentity = setUserIdentity;
|
|
337
|
+
this.removeUserAttribute = removeUserAttribute;
|
|
338
|
+
|
|
339
|
+
this.onIdentifyComplete = onIdentifyComplete;
|
|
340
|
+
this.onLoginComplete = onLoginComplete;
|
|
341
|
+
this.onLogoutComplete = onLogoutComplete;
|
|
342
|
+
this.onModifyComplete = onModifyComplete;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
function getId() {
|
|
346
|
+
return moduleId;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function register(config) {
|
|
350
|
+
if (!config) {
|
|
351
|
+
console.log(
|
|
352
|
+
'You must pass a config object to register the kit ' + name
|
|
353
|
+
);
|
|
354
|
+
return;
|
|
255
355
|
}
|
|
256
356
|
|
|
257
|
-
|
|
258
|
-
|
|
357
|
+
if (!isObject(config)) {
|
|
358
|
+
console.log(
|
|
359
|
+
'"config" must be an object. You passed in a ' + typeof config
|
|
360
|
+
);
|
|
361
|
+
return;
|
|
259
362
|
}
|
|
260
363
|
|
|
364
|
+
if (isObject(config.kits)) {
|
|
365
|
+
config.kits[name] = {
|
|
366
|
+
constructor: constructor,
|
|
367
|
+
};
|
|
368
|
+
} else {
|
|
369
|
+
config.kits = {};
|
|
370
|
+
config.kits[name] = {
|
|
371
|
+
constructor: constructor,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
console.log(
|
|
375
|
+
'Successfully registered ' + name + ' to your mParticle configuration'
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function isEmpty(value) {
|
|
380
|
+
return value == null || !(Object.keys(value) || value).length;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function isObject(val) {
|
|
384
|
+
return (
|
|
385
|
+
val != null && typeof val === 'object' && Array.isArray(val) === false
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (typeof window !== 'undefined') {
|
|
261
390
|
if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
262
391
|
window.mParticle.addForwarder({
|
|
263
392
|
name: name,
|
|
264
393
|
constructor: constructor,
|
|
265
|
-
getId: getId
|
|
394
|
+
getId: getId,
|
|
266
395
|
});
|
|
267
396
|
}
|
|
397
|
+
}
|
|
268
398
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
399
|
+
// eslint-disable-next-line no-undef
|
|
400
|
+
var MixpanelEventForwarder = {
|
|
401
|
+
register: register,
|
|
402
|
+
};
|
|
272
403
|
var MixpanelEventForwarder_1 = MixpanelEventForwarder.register;
|
|
273
404
|
|
|
274
405
|
exports.default = MixpanelEventForwarder;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-mixpanel-kit",
|
|
3
|
-
"version": "2.
|
|
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,17 +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",
|
|
25
|
+
"eslint-config-prettier": "9.0.0",
|
|
26
|
+
"eslint-plugin-prettier": "5.0.1",
|
|
19
27
|
"karma": "^5.1.0",
|
|
20
28
|
"karma-chai": "^0.1.0",
|
|
21
29
|
"karma-chrome-launcher": "^3.1.0",
|
|
22
30
|
"karma-firefox-launcher": "^1.3.0",
|
|
23
31
|
"karma-mocha": "^2.0.1",
|
|
24
32
|
"mocha": "^2.5.3",
|
|
33
|
+
"prettier": "^3.0.3",
|
|
25
34
|
"rollup": "^1.13.1",
|
|
26
35
|
"rollup-plugin-commonjs": "^10.0.0",
|
|
27
36
|
"rollup-plugin-node-resolve": "^5.0.1",
|
|
@@ -29,8 +38,5 @@
|
|
|
29
38
|
"should": "^7.1.0",
|
|
30
39
|
"watchify": "^3.11.1"
|
|
31
40
|
},
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"@mparticle/web-sdk": "^2.11.8"
|
|
34
|
-
},
|
|
35
41
|
"license": "Apache-2.0"
|
|
36
42
|
}
|