mixpanel-browser 2.48.1 → 2.50.0
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/.eslintignore +2 -0
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/bower.json +1 -1
- package/build.sh +14 -9
- package/dist/mixpanel-js-wrapper.js +247 -0
- package/dist/mixpanel-js-wrapper.min.js +5 -0
- package/dist/mixpanel-recorder.js +5940 -0
- package/dist/mixpanel-recorder.min.js +24 -0
- package/dist/mixpanel.amd.js +231 -66
- package/dist/mixpanel.cjs.js +230 -65
- package/dist/mixpanel.globals.js +231 -66
- package/dist/mixpanel.min.js +108 -103
- package/dist/mixpanel.umd.js +232 -67
- package/doc/readme.io/javascript-full-api-reference.md +107 -1
- package/package.json +7 -2
- package/src/config.js +1 -1
- package/src/loaders/loader-globals.js +4 -0
- package/src/{loader-module.js → loaders/loader-module.js} +1 -1
- package/src/loaders/mixpanel-js-wrapper.js +143 -0
- package/src/loaders/mixpanel-js-wrapper.md +114 -0
- package/src/mixpanel-core.js +146 -15
- package/src/mixpanel-people.js +0 -1
- package/src/recorder/index.js +153 -0
- package/src/recorder/rollup.config.js +19 -0
- package/src/utils.js +15 -3
- package/src/loader-globals.js +0 -4
- /package/{mixpanel-jslib-snippet.js → src/loaders/mixpanel-jslib-snippet.js} +0 -0
package/.eslintignore
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
**2.49.0** (5 Feb 2024)
|
|
2
|
+
- SPA support in pageview-tracking
|
|
3
|
+
- Support for configurable UTM parameter persistence
|
|
4
|
+
- Initial-referrer profile properties are now stored with `set_once` instead of `set`
|
|
5
|
+
- Ignore AhrefsSiteAudit crawler
|
|
6
|
+
|
|
1
7
|
**2.48.1** (14 Nov 2023)
|
|
2
8
|
- UTM campaign properties will always be persisted super properties (fixes discrepancy between
|
|
3
9
|
minified and unminified package)
|
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ or
|
|
|
50
50
|
|
|
51
51
|
2) Recompile the snippet with a custom `MIXPANEL_LIB_URL` using [Closure Compiler](https://developers.google.com/closure/compiler/):
|
|
52
52
|
```sh
|
|
53
|
-
java -jar compiler.jar --js mixpanel-jslib-snippet.js --js_output_file mixpanel-jslib-snippet.min.js --compilation_level ADVANCED_OPTIMIZATIONS --define='MIXPANEL_LIB_URL="bower_components/mixpanel/mixpanel.js"'
|
|
53
|
+
java -jar compiler.jar --js src/loaders/mixpanel-jslib-snippet.js --js_output_file mixpanel-jslib-snippet.min.js --compilation_level ADVANCED_OPTIMIZATIONS --define='MIXPANEL_LIB_URL="bower_components/mixpanel/mixpanel.js"'
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
### Upgrading from mixpanel-bower v2.2.0 or v2.0.0
|
package/bower.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "mixpanel",
|
|
3
3
|
"homepage": "https://github.com/mixpanel/mixpanel-js",
|
|
4
4
|
"description": "Mixpanel JavaScript Library",
|
|
5
|
-
"main": "mixpanel-jslib-snippet.js",
|
|
5
|
+
"main": "src/loaders/mixpanel-jslib-snippet.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git@github.com:mixpanel/mixpanel-js.git"
|
package/build.sh
CHANGED
|
@@ -7,8 +7,9 @@ if [ ! -z "$DIST" ]; then
|
|
|
7
7
|
export FULL=1
|
|
8
8
|
fi
|
|
9
9
|
|
|
10
|
-
echo 'Building main
|
|
11
|
-
|
|
10
|
+
echo 'Building main bundles'
|
|
11
|
+
npx rollup -i src/loaders/loader-globals.js -f iife -o build/mixpanel.globals.js -n mixpanel -c rollup.config.js
|
|
12
|
+
npx rollup -i src/recorder/index.js -f iife -n mixpanel -c src/recorder/rollup.config.js
|
|
12
13
|
ln -sf mixpanel.globals.js build/mixpanel.js
|
|
13
14
|
|
|
14
15
|
if [ ! -z "$FULL" ]; then
|
|
@@ -16,17 +17,21 @@ if [ ! -z "$FULL" ]; then
|
|
|
16
17
|
java -jar vendor/closure-compiler/compiler.jar --js build/mixpanel.js --js_output_file build/mixpanel.min.js --compilation_level ADVANCED_OPTIMIZATIONS --output_wrapper "(function() {
|
|
17
18
|
%output%
|
|
18
19
|
})();"
|
|
19
|
-
java -jar vendor/closure-compiler/compiler.jar --js mixpanel-jslib-snippet.js --js_output_file build/mixpanel-jslib-snippet.min.js --compilation_level ADVANCED_OPTIMIZATIONS
|
|
20
|
-
java -jar vendor/closure-compiler/compiler.jar --js mixpanel-jslib-snippet.js --js_output_file build/mixpanel-jslib-snippet.min.test.js --compilation_level ADVANCED_OPTIMIZATIONS --define='MIXPANEL_LIB_URL="../build/mixpanel.min.js"'
|
|
20
|
+
java -jar vendor/closure-compiler/compiler.jar --js src/loaders/mixpanel-jslib-snippet.js --js_output_file build/mixpanel-jslib-snippet.min.js --compilation_level ADVANCED_OPTIMIZATIONS
|
|
21
|
+
java -jar vendor/closure-compiler/compiler.jar --js src/loaders/mixpanel-jslib-snippet.js --js_output_file build/mixpanel-jslib-snippet.min.test.js --compilation_level ADVANCED_OPTIMIZATIONS --define='MIXPANEL_LIB_URL="../build/mixpanel.min.js"'
|
|
22
|
+
|
|
23
|
+
echo 'Building mixpanel-js-wrapper'
|
|
24
|
+
npx rollup src/loaders/mixpanel-js-wrapper.js -o build/mixpanel-js-wrapper.js -c rollup.config.js
|
|
25
|
+
java -jar vendor/closure-compiler/compiler.jar --js build/mixpanel-js-wrapper.js --js_output_file build/mixpanel-js-wrapper.min.js --compilation_level ADVANCED_OPTIMIZATIONS
|
|
21
26
|
|
|
22
27
|
echo 'Building module bundles'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
npx rollup -i src/loaders/loader-module.js -f amd -o build/mixpanel.amd.js -c rollup.config.js
|
|
29
|
+
npx rollup -i src/loaders/loader-module.js -f cjs -o build/mixpanel.cjs.js -c rollup.config.js
|
|
30
|
+
npx rollup -i src/loaders/loader-module.js -f umd -o build/mixpanel.umd.js -n mixpanel -c rollup.config.js
|
|
26
31
|
|
|
27
32
|
echo 'Bundling module-loader test runners'
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
npx webpack tests/module-cjs.js tests/module-cjs.bundle.js
|
|
34
|
+
npx browserify tests/module-es2015.js -t [ babelify --compact false ] --outfile tests/module-es2015.bundle.js
|
|
30
35
|
|
|
31
36
|
echo 'Bundling module-loader examples'
|
|
32
37
|
pushd examples/commonjs-browserify; npm install && npm run build; popd
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// ==ClosureCompiler==
|
|
2
|
+
// @compilation_level SIMPLE_OPTIMIZATIONS
|
|
3
|
+
// @output_file_name mixpanel-jslib-2.2-snippet.min.js
|
|
4
|
+
// ==/ClosureCompiler==
|
|
5
|
+
|
|
6
|
+
/** @define {string} */
|
|
7
|
+
var MIXPANEL_LIB_URL = '//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js';
|
|
8
|
+
|
|
9
|
+
(function(document, mixpanel) {
|
|
10
|
+
// Only stub out if this is the first time running the snippet.
|
|
11
|
+
if (!mixpanel['__SV']) {
|
|
12
|
+
var script, first_script, functions, i, lib_name = "mixpanel";
|
|
13
|
+
window[lib_name] = mixpanel;
|
|
14
|
+
|
|
15
|
+
mixpanel['_i'] = [];
|
|
16
|
+
|
|
17
|
+
mixpanel['init'] = function (token, config, name) {
|
|
18
|
+
// support multiple mixpanel instances
|
|
19
|
+
var target = mixpanel;
|
|
20
|
+
if (typeof(name) !== 'undefined') {
|
|
21
|
+
target = mixpanel[name] = [];
|
|
22
|
+
} else {
|
|
23
|
+
name = lib_name;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Pass in current people object if it exists
|
|
27
|
+
target['people'] = target['people'] || [];
|
|
28
|
+
target['toString'] = function(no_stub) {
|
|
29
|
+
var str = lib_name;
|
|
30
|
+
if (name !== lib_name) {
|
|
31
|
+
str += "." + name;
|
|
32
|
+
}
|
|
33
|
+
if (!no_stub) {
|
|
34
|
+
str += " (stub)";
|
|
35
|
+
}
|
|
36
|
+
return str;
|
|
37
|
+
};
|
|
38
|
+
target['people']['toString'] = function() {
|
|
39
|
+
// 1 instead of true for minifying
|
|
40
|
+
return target.toString(1) + ".people (stub)";
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function _set_and_defer(target, fn) {
|
|
44
|
+
var split = fn.split(".");
|
|
45
|
+
if (split.length == 2) {
|
|
46
|
+
target = target[split[0]];
|
|
47
|
+
fn = split[1];
|
|
48
|
+
}
|
|
49
|
+
target[fn] = function() {
|
|
50
|
+
target.push([fn].concat(Array.prototype.slice.call(arguments, 0)));
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// create shallow clone of the public mixpanel interface
|
|
55
|
+
// Note: only supports 1 additional level atm, e.g. mixpanel.people.set, not mixpanel.people.set.do_something_else.
|
|
56
|
+
functions = "disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(' ');
|
|
57
|
+
for (i = 0; i < functions.length; i++) {
|
|
58
|
+
_set_and_defer(target, functions[i]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// special case for get_group(): chain method calls like mixpanel.get_group('foo', 'bar').unset('baz')
|
|
62
|
+
var group_functions = "set set_once union unset remove delete".split(' ');
|
|
63
|
+
target['get_group'] = function() {
|
|
64
|
+
var mock_group = {};
|
|
65
|
+
|
|
66
|
+
var call1_args = arguments;
|
|
67
|
+
var call1 = ['get_group'].concat(Array.prototype.slice.call(call1_args, 0));
|
|
68
|
+
|
|
69
|
+
function _set_and_defer_chained(fn_name) {
|
|
70
|
+
mock_group[fn_name] = function() {
|
|
71
|
+
var call2_args = arguments;
|
|
72
|
+
var call2 = [fn_name].concat(Array.prototype.slice.call(call2_args, 0));
|
|
73
|
+
target.push([call1, call2]);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
for (var i = 0; i < group_functions.length; i++) {
|
|
77
|
+
_set_and_defer_chained(group_functions[i]);
|
|
78
|
+
}
|
|
79
|
+
return mock_group;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// register mixpanel instance
|
|
83
|
+
mixpanel['_i'].push([token, config, name]);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Snippet version, used to fail on new features w/ old snippet
|
|
87
|
+
mixpanel['__SV'] = 1.2;
|
|
88
|
+
|
|
89
|
+
script = document.createElement("script");
|
|
90
|
+
script.type = "text/javascript";
|
|
91
|
+
script.async = true;
|
|
92
|
+
|
|
93
|
+
if (typeof MIXPANEL_CUSTOM_LIB_URL !== 'undefined') {
|
|
94
|
+
script.src = MIXPANEL_CUSTOM_LIB_URL;
|
|
95
|
+
} else if (document.location.protocol === 'file:' && MIXPANEL_LIB_URL.match(/^\/\//)) {
|
|
96
|
+
script.src = 'https:' + MIXPANEL_LIB_URL;
|
|
97
|
+
} else {
|
|
98
|
+
script.src = MIXPANEL_LIB_URL;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
first_script = document.getElementsByTagName("script")[0];
|
|
102
|
+
first_script.parentNode.insertBefore(script, first_script);
|
|
103
|
+
}
|
|
104
|
+
// Pass in current Mixpanel object if it exists (for ppl like Optimizely)
|
|
105
|
+
})(document, window['mixpanel'] || []);
|
|
106
|
+
|
|
107
|
+
/*
|
|
108
|
+
* @see src/loaders/mixpanel-js-wrapper.md
|
|
109
|
+
*/
|
|
110
|
+
(function (win, wrapper) {
|
|
111
|
+
|
|
112
|
+
// If window.mixpanel doesn't exist, return
|
|
113
|
+
if (!win['mixpanel'] || typeof win['mixpanel']['init'] !== 'function') return;
|
|
114
|
+
|
|
115
|
+
// Enumerate available commands
|
|
116
|
+
var commandEnum = [
|
|
117
|
+
'add_group',
|
|
118
|
+
'alias',
|
|
119
|
+
'clear_opt_in_out_tracking',
|
|
120
|
+
'disable',
|
|
121
|
+
/* Ignore getters
|
|
122
|
+
'get_config',
|
|
123
|
+
'get_distinct_id',
|
|
124
|
+
'get_group',
|
|
125
|
+
'get_property',
|
|
126
|
+
'has_opted_in_tracking',
|
|
127
|
+
'has_opted_out_tracking',
|
|
128
|
+
*/
|
|
129
|
+
/* Ignore init
|
|
130
|
+
'init'
|
|
131
|
+
*/
|
|
132
|
+
'identify',
|
|
133
|
+
'opt_in_tracking',
|
|
134
|
+
'opt_out_tracking',
|
|
135
|
+
/* Ignore push
|
|
136
|
+
'push',
|
|
137
|
+
*/
|
|
138
|
+
'register',
|
|
139
|
+
'register_once',
|
|
140
|
+
'remove_group',
|
|
141
|
+
'reset',
|
|
142
|
+
'set_config',
|
|
143
|
+
'set_group',
|
|
144
|
+
'time_event',
|
|
145
|
+
'track',
|
|
146
|
+
'track_forms',
|
|
147
|
+
'track_links',
|
|
148
|
+
'track_pageview',
|
|
149
|
+
'track_with_groups',
|
|
150
|
+
'unregister',
|
|
151
|
+
'people.append',
|
|
152
|
+
'people.clear_charges',
|
|
153
|
+
'people.delete_user',
|
|
154
|
+
'people.increment',
|
|
155
|
+
'people.remove',
|
|
156
|
+
'people.set',
|
|
157
|
+
'people.set_once',
|
|
158
|
+
'people.track_charge',
|
|
159
|
+
'people.union',
|
|
160
|
+
'people.unset',
|
|
161
|
+
'group.remove',
|
|
162
|
+
'group.set',
|
|
163
|
+
'group.set_once',
|
|
164
|
+
'group.union',
|
|
165
|
+
'group.unset'
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
/* The people API can't be used with the .push() interface, so it requires its
|
|
169
|
+
* own helper method. To interact with it, simply use the _mixpanel interface
|
|
170
|
+
* as before.
|
|
171
|
+
*
|
|
172
|
+
* window._mixpanel('<libraryName.>people.set', 'gender', 'm');
|
|
173
|
+
*
|
|
174
|
+
*/
|
|
175
|
+
var people = function (mp, cmd, args) {
|
|
176
|
+
// Extract the command
|
|
177
|
+
var peopleCmd = cmd.split('.').pop();
|
|
178
|
+
|
|
179
|
+
// Call the respective mixpanel method
|
|
180
|
+
mp['people'][peopleCmd].apply(mp['people'], args);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/* To utilize the group API, the command must include the group key and ID as
|
|
184
|
+
* an array in the second argument.
|
|
185
|
+
*
|
|
186
|
+
* window._mixpanel('<libraryName.>.group.set', ['group_key', 'group_id'], {
|
|
187
|
+
* someGroupProperty: 'someGroupValue'
|
|
188
|
+
* });
|
|
189
|
+
*
|
|
190
|
+
*/
|
|
191
|
+
var group = function (mp, cmd, args) {
|
|
192
|
+
// Extract the command
|
|
193
|
+
var groupCmd = cmd.split('.').pop();
|
|
194
|
+
|
|
195
|
+
// Extract the group info
|
|
196
|
+
var groupInfo = args.shift();
|
|
197
|
+
|
|
198
|
+
// Validate the group array
|
|
199
|
+
if (!Array.isArray(groupInfo) || groupInfo.length !== 2) return;
|
|
200
|
+
|
|
201
|
+
// Get group reference
|
|
202
|
+
var group = mp['get_group'].apply(mp, groupInfo);
|
|
203
|
+
|
|
204
|
+
// Call the respective group method
|
|
205
|
+
group[groupCmd].apply(group, args);
|
|
206
|
+
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// Build the command wrapper logic
|
|
210
|
+
win[wrapper] = win[wrapper] || function () {
|
|
211
|
+
|
|
212
|
+
// Build array out of arguments
|
|
213
|
+
var args = [].slice.call(arguments, 0);
|
|
214
|
+
|
|
215
|
+
// Pick the first argument as the command
|
|
216
|
+
var cmd = args.shift();
|
|
217
|
+
|
|
218
|
+
/* Commands can be passed to different namespaces with syntax:
|
|
219
|
+
* window._mixpanel('libraryName.command', arguments)
|
|
220
|
+
*/
|
|
221
|
+
var libraryName = null;
|
|
222
|
+
var cmdParts = cmd.match(/^([^.]+)\.(.+)$/);
|
|
223
|
+
if (cmdParts && cmdParts.length === 3 && !/people|group/.test(cmdParts[1])) {
|
|
224
|
+
libraryName = cmdParts[1];
|
|
225
|
+
cmd = cmdParts[2];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// If libraryName is set, use that as the mixpanel interface
|
|
229
|
+
var mp = libraryName ? window['mixpanel'][libraryName] : window['mixpanel'];
|
|
230
|
+
|
|
231
|
+
// Return if namespace not found
|
|
232
|
+
if (!mp) return;
|
|
233
|
+
|
|
234
|
+
// If cmd is not one of the available ones, return
|
|
235
|
+
if (commandEnum.indexOf(cmd) === -1) return;
|
|
236
|
+
|
|
237
|
+
// Handle people command
|
|
238
|
+
if (/^people\./.test(cmd)) return people(mp, cmd, args);
|
|
239
|
+
|
|
240
|
+
// Handle group command
|
|
241
|
+
if (/^group\./.test(cmd)) return group(mp, cmd, args);
|
|
242
|
+
|
|
243
|
+
// Push the command to mixpanel
|
|
244
|
+
return mp.push.apply(mp, [[cmd].concat(args)]);
|
|
245
|
+
|
|
246
|
+
};
|
|
247
|
+
})(window, '_mixpanel');
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
(function(d,c){if(!c.__SV){var e,g,b,a;window.mixpanel=c;c._i=[];c.init=function(i,g,d){function e(b,a){var d=a.split(".");2==d.length&&(b=b[d[0]],a=d[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,0)))}}var f=c;"undefined"!==typeof d?f=c[d]=[]:d="mixpanel";f.people=f.people||[];f.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};f.people.toString=function(){return f.toString(1)+".people (stub)"};b="disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(" ");
|
|
2
|
+
for(a=0;a<b.length;a++)e(f,b[a]);var h="set set_once union unset remove delete".split(" ");f.get_group=function(){function a(c){b[c]=function(){var a=[c].concat(Array.prototype.slice.call(arguments,0));f.push([d,a])}}for(var b={},d=["get_group"].concat(Array.prototype.slice.call(arguments,0)),c=0;c<h.length;c++)a(h[c]);return b};c._i.push([i,g,d])};c.__SV=1.2;e=d.createElement("script");e.type="text/javascript";e.async=!0;e.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:
|
|
3
|
+
"file:"===d.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";g=d.getElementsByTagName("script")[0];g.parentNode.insertBefore(e,g)}})(document,window.mixpanel||[]);
|
|
4
|
+
(function(d,c){if(d.mixpanel&&"function"===typeof d.mixpanel.init){var e="add_group,alias,clear_opt_in_out_tracking,disable,identify,opt_in_tracking,opt_out_tracking,register,register_once,remove_group,reset,set_config,set_group,time_event,track,track_forms,track_links,track_pageview,track_with_groups,unregister,people.append,people.clear_charges,people.delete_user,people.increment,people.remove,people.set,people.set_once,people.track_charge,people.union,people.unset,group.remove,group.set,group.set_once,group.union,group.unset".split(",");d[c]=
|
|
5
|
+
d[c]||function(){var d=[].slice.call(arguments,0),b=d.shift(),a=null,c=b.match(/^([^.]+)\.(.+)$/);c&&3===c.length&&!/people|group/.test(c[1])&&(a=c[1],b=c[2]);if((a=a?window.mixpanel[a]:window.mixpanel)&&-1!==e.indexOf(b))return/^people\./.test(b)?(b=b.split(".").pop(),a.people[b].apply(a.people,d),b=void 0):/^group\./.test(b)?(b=b.split(".").pop(),c=d.shift(),Array.isArray(c)&&2===c.length&&(a=a.get_group.apply(a,c),a[b].apply(a,d)),b=void 0):b=a.push.apply(a,[[b].concat(d)]),b}}})(window,"_mixpanel");
|