mixpanel-browser 2.48.0 → 2.49.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 ADDED
@@ -0,0 +1,2 @@
1
+ src/loaders/mixpanel.js
2
+ src/loaders/mixpanel-jslib-snippet.js
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
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
+
7
+ **2.48.1** (14 Nov 2023)
8
+ - UTM campaign properties will always be persisted super properties (fixes discrepancy between
9
+ minified and unminified package)
10
+
1
11
  **2.48.0** (7 Nov 2023)
2
12
  - API endpoint routes can now be configured individually (i.e. rename /track, /engage, /groups)
3
13
  - Event properties object passed to mixpanel.track() will no longer be mutated
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
@@ -8,7 +8,7 @@ if [ ! -z "$DIST" ]; then
8
8
  fi
9
9
 
10
10
  echo 'Building main bundle'
11
- ./node_modules/.bin/rollup -i src/loader-globals.js -f iife -o build/mixpanel.globals.js -n mixpanel -c rollup.config.js
11
+ npx rollup -i src/loaders/loader-globals.js -f iife -o build/mixpanel.globals.js -n mixpanel -c rollup.config.js
12
12
  ln -sf mixpanel.globals.js build/mixpanel.js
13
13
 
14
14
  if [ ! -z "$FULL" ]; then
@@ -16,17 +16,21 @@ if [ ! -z "$FULL" ]; then
16
16
  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
17
  %output%
18
18
  })();"
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"'
19
+ 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
20
+ 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"'
21
+
22
+ echo 'Building mixpanel-js-wrapper'
23
+ npx rollup src/loaders/mixpanel-js-wrapper.js -o build/mixpanel-js-wrapper.js -c rollup.config.js
24
+ 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
25
 
22
26
  echo 'Building module bundles'
23
- ./node_modules/.bin/rollup -i src/loader-module.js -f amd -o build/mixpanel.amd.js -c rollup.config.js
24
- ./node_modules/.bin/rollup -i src/loader-module.js -f cjs -o build/mixpanel.cjs.js -c rollup.config.js
25
- ./node_modules/.bin/rollup -i src/loader-module.js -f umd -o build/mixpanel.umd.js -n mixpanel -c rollup.config.js
27
+ npx rollup -i src/loaders/loader-module.js -f amd -o build/mixpanel.amd.js -c rollup.config.js
28
+ npx rollup -i src/loaders/loader-module.js -f cjs -o build/mixpanel.cjs.js -c rollup.config.js
29
+ npx rollup -i src/loaders/loader-module.js -f umd -o build/mixpanel.umd.js -n mixpanel -c rollup.config.js
26
30
 
27
31
  echo 'Bundling module-loader test runners'
28
- ./node_modules/.bin/webpack tests/module-cjs.js tests/module-cjs.bundle.js
29
- ./node_modules/.bin/browserify tests/module-es2015.js -t [ babelify --compact false ] --outfile tests/module-es2015.bundle.js
32
+ npx webpack tests/module-cjs.js tests/module-cjs.bundle.js
33
+ npx browserify tests/module-es2015.js -t [ babelify --compact false ] --outfile tests/module-es2015.bundle.js
30
34
 
31
35
  echo 'Bundling module-loader examples'
32
36
  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, gen_fn, 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");
@@ -2,7 +2,7 @@ define(function () { 'use strict';
2
2
 
3
3
  var Config = {
4
4
  DEBUG: false,
5
- LIB_VERSION: '2.48.0'
5
+ LIB_VERSION: '2.49.0'
6
6
  };
7
7
 
8
8
  // since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
@@ -901,6 +901,7 @@ define(function () { 'use strict';
901
901
  // sending false tracking data
902
902
  var BLOCKED_UA_STRS = [
903
903
  'ahrefsbot',
904
+ 'ahrefssiteaudit',
904
905
  'baiduspider',
905
906
  'bingbot',
906
907
  'bingpreview',
@@ -1621,7 +1622,14 @@ define(function () { 'use strict';
1621
1622
  return '';
1622
1623
  },
1623
1624
 
1624
- properties: function() {
1625
+ currentUrl: function() {
1626
+ return window$1.location.href;
1627
+ },
1628
+
1629
+ properties: function(extra_props) {
1630
+ if (typeof extra_props !== 'object') {
1631
+ extra_props = {};
1632
+ }
1625
1633
  return _.extend(_.strip_empty_properties({
1626
1634
  '$os': _.info.os(),
1627
1635
  '$browser': _.info.browser(userAgent, navigator.vendor, windowOpera),
@@ -1629,7 +1637,7 @@ define(function () { 'use strict';
1629
1637
  '$referring_domain': _.info.referringDomain(document$1.referrer),
1630
1638
  '$device': _.info.device(userAgent)
1631
1639
  }), {
1632
- '$current_url': window$1.location.href,
1640
+ '$current_url': _.info.currentUrl(),
1633
1641
  '$browser_version': _.info.browserVersion(userAgent, navigator.vendor, windowOpera),
1634
1642
  '$screen_height': screen.height,
1635
1643
  '$screen_width': screen.width,
@@ -1637,7 +1645,7 @@ define(function () { 'use strict';
1637
1645
  '$lib_version': Config.LIB_VERSION,
1638
1646
  '$insert_id': cheap_guid(),
1639
1647
  'time': _.timestamp() / 1000 // epoch time in seconds
1640
- });
1648
+ }, _.strip_empty_properties(extra_props));
1641
1649
  },
1642
1650
 
1643
1651
  people_properties: function() {
@@ -3203,7 +3211,6 @@ define(function () { 'use strict';
3203
3211
  data[SET_ACTION] = _.extend(
3204
3212
  {},
3205
3213
  _.info.people_properties(),
3206
- this._mixpanel['persistence'].get_referrer_info(),
3207
3214
  data[SET_ACTION]
3208
3215
  );
3209
3216
  return this._send_request(data, callback);
@@ -4163,10 +4170,12 @@ define(function () { 'use strict';
4163
4170
  'cookie_domain': '',
4164
4171
  'cookie_name': '',
4165
4172
  'loaded': NOOP_FUNC,
4173
+ 'mp_loader': null,
4166
4174
  'track_marketing': true,
4167
4175
  'track_pageview': false,
4168
4176
  'skip_first_touch_marketing': false,
4169
4177
  'store_google': true,
4178
+ 'stop_utm_persistence': false,
4170
4179
  'save_referrer': true,
4171
4180
  'test': false,
4172
4181
  'verbose': false,
@@ -4400,8 +4409,9 @@ define(function () { 'use strict';
4400
4409
  }, '');
4401
4410
  }
4402
4411
 
4403
- if (this.get_config('track_pageview')) {
4404
- this.track_pageview();
4412
+ var track_pageview_option = this.get_config('track_pageview');
4413
+ if (track_pageview_option) {
4414
+ this._init_url_change_tracking(track_pageview_option);
4405
4415
  }
4406
4416
  };
4407
4417
 
@@ -4410,13 +4420,26 @@ define(function () { 'use strict';
4410
4420
  MixpanelLib.prototype._loaded = function() {
4411
4421
  this.get_config('loaded')(this);
4412
4422
  this._set_default_superprops();
4423
+ this['people'].set_once(this['persistence'].get_referrer_info());
4424
+
4425
+ // The original 'store_google' functionality will be deprecated and the config will be
4426
+ // used to clear previously managed UTM parameters from persistence.
4427
+ // stop_utm_persistence is `false` by default now but will be default `true` in the future.
4428
+ if (this.get_config('store_google') && this.get_config('stop_utm_persistence')) {
4429
+ var utm_params = _.info.campaignParams(null);
4430
+ _.each(utm_params, function(_utm_value, utm_key) {
4431
+ // We need to unregister persisted UTM parameters so old values
4432
+ // are not mixed with the new UTM parameters
4433
+ this.unregister(utm_key);
4434
+ }.bind(this));
4435
+ }
4413
4436
  };
4414
4437
 
4415
4438
  // update persistence with info on referrer, UTM params, etc
4416
4439
  MixpanelLib.prototype._set_default_superprops = function() {
4417
4440
  this['persistence'].update_search_keyword(document$1.referrer);
4418
- if (this.get_config('store_google')) {
4419
- this.register(_.info.campaignParams(), {persistent: false});
4441
+ if (this.get_config('store_google') && !this.get_config('stop_utm_persistence')) {
4442
+ this.register(_.info.campaignParams());
4420
4443
  }
4421
4444
  if (this.get_config('save_referrer')) {
4422
4445
  this['persistence'].update_referrer_info(document$1.referrer);
@@ -4453,6 +4476,55 @@ define(function () { 'use strict';
4453
4476
  return dt.track.apply(dt, args);
4454
4477
  };
4455
4478
 
4479
+ MixpanelLib.prototype._init_url_change_tracking = function(track_pageview_option) {
4480
+ var previous_tracked_url = '';
4481
+ var tracked = this.track_pageview();
4482
+ if (tracked) {
4483
+ previous_tracked_url = _.info.currentUrl();
4484
+ }
4485
+
4486
+ if (_.include(['full-url', 'url-with-path-and-query-string', 'url-with-path'], track_pageview_option)) {
4487
+ window$1.addEventListener('popstate', function() {
4488
+ window$1.dispatchEvent(new Event('mp_locationchange'));
4489
+ });
4490
+ window$1.addEventListener('hashchange', function() {
4491
+ window$1.dispatchEvent(new Event('mp_locationchange'));
4492
+ });
4493
+ var nativePushState = window$1.history.pushState;
4494
+ if (typeof nativePushState === 'function') {
4495
+ window$1.history.pushState = function(state, unused, url) {
4496
+ nativePushState.call(window$1.history, state, unused, url);
4497
+ window$1.dispatchEvent(new Event('mp_locationchange'));
4498
+ };
4499
+ }
4500
+ var nativeReplaceState = window$1.history.replaceState;
4501
+ if (typeof nativeReplaceState === 'function') {
4502
+ window$1.history.replaceState = function(state, unused, url) {
4503
+ nativeReplaceState.call(window$1.history, state, unused, url);
4504
+ window$1.dispatchEvent(new Event('mp_locationchange'));
4505
+ };
4506
+ }
4507
+ window$1.addEventListener('mp_locationchange', function() {
4508
+ var current_url = _.info.currentUrl();
4509
+ var should_track = false;
4510
+ if (track_pageview_option === 'full-url') {
4511
+ should_track = current_url !== previous_tracked_url;
4512
+ } else if (track_pageview_option === 'url-with-path-and-query-string') {
4513
+ should_track = current_url.split('#')[0] !== previous_tracked_url.split('#')[0];
4514
+ } else if (track_pageview_option === 'url-with-path') {
4515
+ should_track = current_url.split('#')[0].split('?')[0] !== previous_tracked_url.split('#')[0].split('?')[0];
4516
+ }
4517
+
4518
+ if (should_track) {
4519
+ var tracked = this.track_pageview();
4520
+ if (tracked) {
4521
+ previous_tracked_url = current_url;
4522
+ }
4523
+ }
4524
+ }.bind(this));
4525
+ }
4526
+ };
4527
+
4456
4528
  /**
4457
4529
  * _prepare_callback() should be called by callers of _send_request for use
4458
4530
  * as the callback argument.
@@ -4921,7 +4993,7 @@ define(function () { 'use strict';
4921
4993
  // update properties with pageview info and super-properties
4922
4994
  properties = _.extend(
4923
4995
  {},
4924
- _.info.properties(),
4996
+ _.info.properties({'mp_loader': this.get_config('mp_loader')}),
4925
4997
  marketing_properties,
4926
4998
  this['persistence'].properties(),
4927
4999
  this.unpersisted_superprops,
@@ -5085,10 +5157,9 @@ define(function () { 'use strict';
5085
5157
 
5086
5158
  /**
5087
5159
  * Track a default Mixpanel page view event, which includes extra default event properties to
5088
- * improve page view data. The `config.track_pageview` option for <a href="#mixpanelinit">mixpanel.init()</a>
5089
- * may be turned on for tracking page loads automatically.
5160
+ * improve page view data.
5090
5161
  *
5091
- * ### Usage
5162
+ * ### Usage:
5092
5163
  *
5093
5164
  * // track a default $mp_web_page_view event
5094
5165
  * mixpanel.track_pageview();
@@ -5105,6 +5176,23 @@ define(function () { 'use strict';
5105
5176
  * // views on different products or internal applications that are considered completely separate
5106
5177
  * mixpanel.track_pageview({'page': 'customer-search'}, {'event_name': '[internal] Admin Page View'});
5107
5178
  *
5179
+ * ### Notes:
5180
+ *
5181
+ * The `config.track_pageview` option for <a href="#mixpanelinit">mixpanel.init()</a>
5182
+ * may be turned on for tracking page loads automatically.
5183
+ *
5184
+ * // track only page loads
5185
+ * mixpanel.init(PROJECT_TOKEN, {track_pageview: true});
5186
+ *
5187
+ * // track when the URL changes in any manner
5188
+ * mixpanel.init(PROJECT_TOKEN, {track_pageview: 'full-url'});
5189
+ *
5190
+ * // track when the URL changes, ignoring any changes in the hash part
5191
+ * mixpanel.init(PROJECT_TOKEN, {track_pageview: 'url-with-path-and-query-string'});
5192
+ *
5193
+ * // track when the path changes, ignoring any query parameter or hash changes
5194
+ * mixpanel.init(PROJECT_TOKEN, {track_pageview: 'url-with-path'});
5195
+ *
5108
5196
  * @param {Object} [properties] An optional set of additional properties to send with the page view event
5109
5197
  * @param {Object} [options] Page view tracking options
5110
5198
  * @param {String} [options.event_name] - Alternate name for the tracking event
@@ -5855,7 +5943,7 @@ define(function () { 'use strict';
5855
5943
  /**
5856
5944
  * Opt the user in to data tracking and cookies/localstorage for this Mixpanel instance
5857
5945
  *
5858
- * ### Usage
5946
+ * ### Usage:
5859
5947
  *
5860
5948
  * // opt user in
5861
5949
  * mixpanel.opt_in_tracking();
@@ -5895,7 +5983,7 @@ define(function () { 'use strict';
5895
5983
  /**
5896
5984
  * Opt the user out of data tracking and cookies/localstorage for this Mixpanel instance
5897
5985
  *
5898
- * ### Usage
5986
+ * ### Usage:
5899
5987
  *
5900
5988
  * // opt user out
5901
5989
  * mixpanel.opt_out_tracking();
@@ -5936,7 +6024,7 @@ define(function () { 'use strict';
5936
6024
  /**
5937
6025
  * Check whether the user has opted in to data tracking and cookies/localstorage for this Mixpanel instance
5938
6026
  *
5939
- * ### Usage
6027
+ * ### Usage:
5940
6028
  *
5941
6029
  * var has_opted_in = mixpanel.has_opted_in_tracking();
5942
6030
  * // use has_opted_in value
@@ -5953,7 +6041,7 @@ define(function () { 'use strict';
5953
6041
  /**
5954
6042
  * Check whether the user has opted out of data tracking and cookies/localstorage for this Mixpanel instance
5955
6043
  *
5956
- * ### Usage
6044
+ * ### Usage:
5957
6045
  *
5958
6046
  * var has_opted_out = mixpanel.has_opted_out_tracking();
5959
6047
  * // use has_opted_out value
@@ -5970,7 +6058,7 @@ define(function () { 'use strict';
5970
6058
  /**
5971
6059
  * Clear the user's opt in/out status of data tracking and cookies/localstorage for this Mixpanel instance
5972
6060
  *
5973
- * ### Usage
6061
+ * ### Usage:
5974
6062
  *
5975
6063
  * // clear user's opt-in/out status
5976
6064
  * mixpanel.clear_opt_in_out_tracking();