-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.client.js
79 lines (70 loc) · 3 KB
/
index.client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var debug = require('debug')('MixpanelI13nPlugin');
var DEFAULT_CATEGORY = 'all';
var DEFAULT_ACTION = 'click';
var DEFAULT_LABEL = '';
/**
* @class ReactI13nMixpanel
* @param {String} token
* @param {Object} config
* @param {String} config.token (mandatory)
* @param {String} config.name (optional)
* @constructor
*/
var ReactI13nMixpanel = function (config) {
var _config = typeof(config) == 'object' ? config : {},
token = '';
token = typeof(config) == 'object' ? config.token : config;
if (!token) {
debug('token is mandatory');
}
(function(f,b){if(!b.__SV){var a,e,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 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(" ");for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=f.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";e=f.getElementsByTagName("script")[0];e.parentNode.insertBefore(a,e)}})(document,window.mixpanel||[]);
if (mixpanel.__loaded) return;
mixpanel.init(
token,
_config,
_config.name || undefined
);
};
/**
* get plugin object
* @method getPlugin
* @return {Object} plugin object
*/
ReactI13nMixpanel.prototype.getPlugin = function () {
return {
name: 'mixpanel',
eventHandlers: {
setUsername: function (properties) {
mixpanel.identify(properties.userId);
},
setSuperProperties: function (properties) {
mixpanel.register_once(properties);
},
setUserProperties: function (properties) {
mixpanel.people.set_once(properties);
},
setUserPropertiesOnce: function (properties) {
mixpanel.people.set(properties);
},
click: function (payload, callback) {
var i13nNode = payload.i13nNode;
if (i13nNode) {
var model = i13nNode.getMergedModel();
model.action = model.action || DEFAULT_ACTION,
model.category = model.category || DEFAULT_CATEGORY,
model.label = model.label || i13nNode.getText(payload.target) || DEFAULT_LABEL,
model.value = model.value || 0,
model.nonInteraction = model.nonInteraction || false
mixpanel.track(
model.action,
model,
callback
)
} else {
callback && callback();
}
}
}
};
}
module.exports = ReactI13nMixpanel;