forked from belisarius222/meteor-mixpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mixpanel-client.js
69 lines (58 loc) · 2 KB
/
mixpanel-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
(function (document, mixpanel) {
window.mixpanel = mixpanel;
var loadScript = function() {
var script, firstScript;
script = document.createElement("script");
script.type = "text/javascript";
script.async = !0;
script.src = ("https:" === document.location.protocol ? "https:" : "http:") +
'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';
firstScript = document.getElementsByTagName("script")[0];
firstScript.parentNode.insertBefore(script, firstScript);
};
mixpanel._i = [];
var createCommands = function(mixpanelTracker) {
var commands = [
'disable',
'track',
'track_pageview',
'track_links',
'track_forms',
'register',
'register_once',
'unregister',
'identify',
'alias',
'name_tag',
'set_config'
];
var peopleCommands = ['set','increment','track_charge','append'];
var addCommand = function(tracker,command) {
tracker[command] = function() {
var commandArray = [command].concat(_.toArray(arguments));
tracker.push(commandArray);
};
};
_.each(commands,function(command){
addCommand(mixpanelTracker,command);
});
_.each(peopleCommands,function(command){
addCommand(mixpanelTracker.people,command);
});
};
mixpanel.init = function(token, config, name) {
var proxy = mixpanel;
loadScript();
if ('undefined' !== typeof name) {
proxy = mixpanel[name] = [];
createCommands(proxy); // this was originally run unconditionally
}
else
name = 'mixpanel';
proxy.people = proxy.people || [];
mixpanel._i.push([token, config, name]);
};
mixpanel.__SV = 1.2;
mixpanel.people = [];
createCommands(mixpanel);
})(document, window.mixpanel || []);