mixpanel-browser 2.46.0 → 2.47.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/.github/workflows/tests.yml +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/mixpanel.amd.js +137 -40
- package/dist/mixpanel.cjs.js +137 -40
- package/dist/mixpanel.globals.js +137 -40
- package/dist/mixpanel.min.js +104 -102
- package/dist/mixpanel.umd.js +137 -40
- package/package.json +1 -1
- package/src/config.js +1 -1
- package/src/mixpanel-core.js +89 -11
- package/src/mixpanel-persistence.js +0 -7
- package/src/utils.js +47 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
**2.47.0** (27 Apr 2023)
|
|
2
|
+
- Collect richer marketing attribution properties for multi-touch attribution
|
|
3
|
+
- New implementation of previously-deprecated track_pageview() method and init option to send automatically
|
|
4
|
+
- Use performance.now when available for time-based entropy component of UUID-generation (thanks @adrianherd)
|
|
5
|
+
- looser API Host check for default JSON-payload sending to mipxanel.com hosts
|
|
6
|
+
|
|
1
7
|
**2.46.0** (20 Mar 2023)
|
|
2
8
|
- Updates for new identity management system
|
|
3
9
|
- More aggressive deduplication within batch sender
|
package/dist/mixpanel.amd.js
CHANGED
|
@@ -2,7 +2,7 @@ define(function () { 'use strict';
|
|
|
2
2
|
|
|
3
3
|
var Config = {
|
|
4
4
|
DEBUG: false,
|
|
5
|
-
LIB_VERSION: '2.
|
|
5
|
+
LIB_VERSION: '2.47.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
|
|
@@ -832,20 +832,24 @@ define(function () { 'use strict';
|
|
|
832
832
|
|
|
833
833
|
_.UUID = (function() {
|
|
834
834
|
|
|
835
|
-
// Time
|
|
836
|
-
// 1*new Date() is a cross browser version of Date.now()
|
|
835
|
+
// Time-based entropy
|
|
837
836
|
var T = function() {
|
|
838
|
-
var
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
837
|
+
var time = 1 * new Date(); // cross-browser version of Date.now()
|
|
838
|
+
var ticks;
|
|
839
|
+
if (window$1.performance && window$1.performance.now) {
|
|
840
|
+
ticks = window$1.performance.now();
|
|
841
|
+
} else {
|
|
842
|
+
// fall back to busy loop
|
|
843
|
+
ticks = 0;
|
|
844
|
+
|
|
845
|
+
// this while loop figures how many browser ticks go by
|
|
846
|
+
// before 1*new Date() returns a new number, ie the amount
|
|
847
|
+
// of ticks that go by per millisecond
|
|
848
|
+
while (time == 1 * new Date()) {
|
|
849
|
+
ticks++;
|
|
850
|
+
}
|
|
846
851
|
}
|
|
847
|
-
|
|
848
|
-
return d.toString(16) + i.toString(16);
|
|
852
|
+
return time.toString(16) + Math.floor(ticks).toString(16);
|
|
849
853
|
};
|
|
850
854
|
|
|
851
855
|
// Math.Random entropy
|
|
@@ -1412,21 +1416,42 @@ define(function () { 'use strict';
|
|
|
1412
1416
|
};
|
|
1413
1417
|
})();
|
|
1414
1418
|
|
|
1419
|
+
var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'];
|
|
1420
|
+
var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid'];
|
|
1421
|
+
|
|
1415
1422
|
_.info = {
|
|
1416
|
-
campaignParams: function() {
|
|
1417
|
-
var
|
|
1418
|
-
kw = '',
|
|
1423
|
+
campaignParams: function(default_value) {
|
|
1424
|
+
var kw = '',
|
|
1419
1425
|
params = {};
|
|
1420
|
-
_.each(
|
|
1426
|
+
_.each(CAMPAIGN_KEYWORDS, function(kwkey) {
|
|
1421
1427
|
kw = _.getQueryParam(document$1.URL, kwkey);
|
|
1422
1428
|
if (kw.length) {
|
|
1423
1429
|
params[kwkey] = kw;
|
|
1430
|
+
} else if (default_value !== undefined) {
|
|
1431
|
+
params[kwkey] = default_value;
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
|
|
1435
|
+
return params;
|
|
1436
|
+
},
|
|
1437
|
+
|
|
1438
|
+
clickParams: function() {
|
|
1439
|
+
var id = '',
|
|
1440
|
+
params = {};
|
|
1441
|
+
_.each(CLICK_IDS, function(idkey) {
|
|
1442
|
+
id = _.getQueryParam(document$1.URL, idkey);
|
|
1443
|
+
if (id.length) {
|
|
1444
|
+
params[idkey] = id;
|
|
1424
1445
|
}
|
|
1425
1446
|
});
|
|
1426
1447
|
|
|
1427
1448
|
return params;
|
|
1428
1449
|
},
|
|
1429
1450
|
|
|
1451
|
+
marketingParams: function() {
|
|
1452
|
+
return _.extend(_.info.campaignParams(), _.info.clickParams());
|
|
1453
|
+
},
|
|
1454
|
+
|
|
1430
1455
|
searchEngine: function(referrer) {
|
|
1431
1456
|
if (referrer.search('https?://(.*)google.([^/?]*)') === 0) {
|
|
1432
1457
|
return 'google';
|
|
@@ -1623,12 +1648,13 @@ define(function () { 'use strict';
|
|
|
1623
1648
|
});
|
|
1624
1649
|
},
|
|
1625
1650
|
|
|
1626
|
-
|
|
1651
|
+
mpPageViewProperties: function() {
|
|
1627
1652
|
return _.strip_empty_properties({
|
|
1628
|
-
'
|
|
1629
|
-
'
|
|
1630
|
-
'
|
|
1631
|
-
'
|
|
1653
|
+
'current_page_title': document$1.title,
|
|
1654
|
+
'current_domain': window$1.location.hostname,
|
|
1655
|
+
'current_url_path': window$1.location.pathname,
|
|
1656
|
+
'current_url_protocol': window$1.location.protocol,
|
|
1657
|
+
'current_url_search': window$1.location.search
|
|
1632
1658
|
});
|
|
1633
1659
|
}
|
|
1634
1660
|
};
|
|
@@ -3806,13 +3832,6 @@ define(function () { 'use strict';
|
|
|
3806
3832
|
}
|
|
3807
3833
|
};
|
|
3808
3834
|
|
|
3809
|
-
MixpanelPersistence.prototype.update_campaign_params = function() {
|
|
3810
|
-
if (!this.campaign_params_saved) {
|
|
3811
|
-
this.register_once(_.info.campaignParams());
|
|
3812
|
-
this.campaign_params_saved = true;
|
|
3813
|
-
}
|
|
3814
|
-
};
|
|
3815
|
-
|
|
3816
3835
|
MixpanelPersistence.prototype.update_search_keyword = function(referrer) {
|
|
3817
3836
|
this.register(_.info.searchInfo(referrer));
|
|
3818
3837
|
};
|
|
@@ -4137,6 +4156,9 @@ define(function () { 'use strict';
|
|
|
4137
4156
|
'cookie_domain': '',
|
|
4138
4157
|
'cookie_name': '',
|
|
4139
4158
|
'loaded': NOOP_FUNC,
|
|
4159
|
+
'track_marketing': true,
|
|
4160
|
+
'track_pageview': false,
|
|
4161
|
+
'skip_first_touch_marketing': false,
|
|
4140
4162
|
'store_google': true,
|
|
4141
4163
|
'save_referrer': true,
|
|
4142
4164
|
'test': false,
|
|
@@ -4203,6 +4225,25 @@ define(function () { 'use strict';
|
|
|
4203
4225
|
instance['people'] = new MixpanelPeople();
|
|
4204
4226
|
instance['people']._init(instance);
|
|
4205
4227
|
|
|
4228
|
+
if (!instance.get_config('skip_first_touch_marketing')) {
|
|
4229
|
+
// We need null UTM params in the object because
|
|
4230
|
+
// UTM parameters act as a tuple. If any UTM param
|
|
4231
|
+
// is present, then we set all UTM params including
|
|
4232
|
+
// empty ones together
|
|
4233
|
+
var utm_params = _.info.campaignParams(null);
|
|
4234
|
+
var initial_utm_params = {};
|
|
4235
|
+
var has_utm = false;
|
|
4236
|
+
_.each(utm_params, function(utm_value, utm_key) {
|
|
4237
|
+
initial_utm_params['initial_' + utm_key] = utm_value;
|
|
4238
|
+
if (utm_value) {
|
|
4239
|
+
has_utm = true;
|
|
4240
|
+
}
|
|
4241
|
+
});
|
|
4242
|
+
if (has_utm) {
|
|
4243
|
+
instance['people'].set_once(initial_utm_params);
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
|
|
4206
4247
|
// if any instance on the page has debug = true, we set the
|
|
4207
4248
|
// global debug to be true
|
|
4208
4249
|
Config.DEBUG = Config.DEBUG || instance.get_config('debug');
|
|
@@ -4234,7 +4275,7 @@ define(function () { 'use strict';
|
|
|
4234
4275
|
* mixpanel.library_name.track(...);
|
|
4235
4276
|
*
|
|
4236
4277
|
* @param {String} token Your Mixpanel API token
|
|
4237
|
-
* @param {Object} [config] A dictionary of config options to override. <a href="https://github.com/mixpanel/mixpanel-js/blob/
|
|
4278
|
+
* @param {Object} [config] A dictionary of config options to override. <a href="https://github.com/mixpanel/mixpanel-js/blob/v2.46.0/src/mixpanel-core.js#L88-L127">See a list of default config options</a>.
|
|
4238
4279
|
* @param {String} [name] The name for the new mixpanel instance that you want created
|
|
4239
4280
|
*/
|
|
4240
4281
|
MixpanelLib.prototype.init = function (token, config, name) {
|
|
@@ -4272,7 +4313,7 @@ define(function () { 'use strict';
|
|
|
4272
4313
|
// default to JSON payload for standard mixpanel.com API hosts
|
|
4273
4314
|
if (!('api_payload_format' in config)) {
|
|
4274
4315
|
var api_host = config['api_host'] || DEFAULT_CONFIG['api_host'];
|
|
4275
|
-
if (api_host.match(/\.mixpanel\.com
|
|
4316
|
+
if (api_host.match(/\.mixpanel\.com/)) {
|
|
4276
4317
|
variable_features['api_payload_format'] = PAYLOAD_TYPE_JSON;
|
|
4277
4318
|
}
|
|
4278
4319
|
}
|
|
@@ -4347,6 +4388,10 @@ define(function () { 'use strict';
|
|
|
4347
4388
|
'$device_id': uuid
|
|
4348
4389
|
}, '');
|
|
4349
4390
|
}
|
|
4391
|
+
|
|
4392
|
+
if (this.get_config('track_pageview')) {
|
|
4393
|
+
this.track_pageview();
|
|
4394
|
+
}
|
|
4350
4395
|
};
|
|
4351
4396
|
|
|
4352
4397
|
// Private methods
|
|
@@ -4360,7 +4405,7 @@ define(function () { 'use strict';
|
|
|
4360
4405
|
MixpanelLib.prototype._set_default_superprops = function() {
|
|
4361
4406
|
this['persistence'].update_search_keyword(document$1.referrer);
|
|
4362
4407
|
if (this.get_config('store_google')) {
|
|
4363
|
-
this
|
|
4408
|
+
this.register(_.info.campaignParams(), {persistent: false});
|
|
4364
4409
|
}
|
|
4365
4410
|
if (this.get_config('save_referrer')) {
|
|
4366
4411
|
this['persistence'].update_referrer_info(document$1.referrer);
|
|
@@ -4842,6 +4887,10 @@ define(function () { 'use strict';
|
|
|
4842
4887
|
|
|
4843
4888
|
this._set_default_superprops();
|
|
4844
4889
|
|
|
4890
|
+
var marketing_properties = this.get_config('track_marketing')
|
|
4891
|
+
? _.info.marketingParams()
|
|
4892
|
+
: {};
|
|
4893
|
+
|
|
4845
4894
|
// note: extend writes to the first object, so lets make sure we
|
|
4846
4895
|
// don't write to the persistence properties object and info
|
|
4847
4896
|
// properties object by passing in a new object
|
|
@@ -4850,6 +4899,7 @@ define(function () { 'use strict';
|
|
|
4850
4899
|
properties = _.extend(
|
|
4851
4900
|
{},
|
|
4852
4901
|
_.info.properties(),
|
|
4902
|
+
marketing_properties,
|
|
4853
4903
|
this['persistence'].properties(),
|
|
4854
4904
|
this.unpersisted_superprops,
|
|
4855
4905
|
properties
|
|
@@ -5010,17 +5060,54 @@ define(function () { 'use strict';
|
|
|
5010
5060
|
};
|
|
5011
5061
|
|
|
5012
5062
|
/**
|
|
5013
|
-
* Track
|
|
5063
|
+
* Track a default Mixpanel page view event, which includes extra default event properties to
|
|
5064
|
+
* improve page view data. The `config.track_pageview` option for <a href="#mixpanelinit">mixpanel.init()</a>
|
|
5065
|
+
* may be turned on for tracking page loads automatically.
|
|
5014
5066
|
*
|
|
5015
|
-
*
|
|
5016
|
-
*
|
|
5067
|
+
* ### Usage
|
|
5068
|
+
*
|
|
5069
|
+
* // track a default $mp_web_page_view event
|
|
5070
|
+
* mixpanel.track_pageview();
|
|
5071
|
+
*
|
|
5072
|
+
* // track a page view event with additional event properties
|
|
5073
|
+
* mixpanel.track_pageview({'ab_test_variant': 'card-layout-b'});
|
|
5074
|
+
*
|
|
5075
|
+
* // example approach to track page views on different page types as event properties
|
|
5076
|
+
* mixpanel.track_pageview({'page': 'pricing'});
|
|
5077
|
+
* mixpanel.track_pageview({'page': 'homepage'});
|
|
5078
|
+
*
|
|
5079
|
+
* // UNCOMMON: Tracking a page view event with a custom event_name option. NOT expected to be used for
|
|
5080
|
+
* // individual pages on the same site or product. Use cases for custom event_name may be page
|
|
5081
|
+
* // views on different products or internal applications that are considered completely separate
|
|
5082
|
+
* mixpanel.track_pageview({'page': 'customer-search'}, {'event_name': '[internal] Admin Page View'});
|
|
5083
|
+
*
|
|
5084
|
+
* @param {Object} [properties] An optional set of additional properties to send with the page view event
|
|
5085
|
+
* @param {Object} [options] Page view tracking options
|
|
5086
|
+
* @param {String} [options.event_name] - Alternate name for the tracking event
|
|
5087
|
+
* @returns {Boolean|Object} If the tracking request was successfully initiated/queued, an object
|
|
5088
|
+
* with the tracking payload sent to the API server is returned; otherwise false.
|
|
5017
5089
|
*/
|
|
5018
|
-
MixpanelLib.prototype.track_pageview = function(
|
|
5019
|
-
if (
|
|
5020
|
-
|
|
5090
|
+
MixpanelLib.prototype.track_pageview = addOptOutCheckMixpanelLib(function(properties, options) {
|
|
5091
|
+
if (typeof properties !== 'object') {
|
|
5092
|
+
properties = {};
|
|
5021
5093
|
}
|
|
5022
|
-
|
|
5023
|
-
|
|
5094
|
+
options = options || {};
|
|
5095
|
+
var event_name = options['event_name'] || '$mp_web_page_view';
|
|
5096
|
+
|
|
5097
|
+
var default_page_properties = _.extend(
|
|
5098
|
+
_.info.mpPageViewProperties(),
|
|
5099
|
+
_.info.campaignParams(),
|
|
5100
|
+
_.info.clickParams()
|
|
5101
|
+
);
|
|
5102
|
+
|
|
5103
|
+
var event_properties = _.extend(
|
|
5104
|
+
{},
|
|
5105
|
+
default_page_properties,
|
|
5106
|
+
properties
|
|
5107
|
+
);
|
|
5108
|
+
|
|
5109
|
+
return this.track(event_name, event_properties);
|
|
5110
|
+
});
|
|
5024
5111
|
|
|
5025
5112
|
/**
|
|
5026
5113
|
* Track clicks on a set of document elements. Selector must be a
|
|
@@ -5516,10 +5603,20 @@ define(function () { 'use strict';
|
|
|
5516
5603
|
* // secure, meaning they will only be transmitted over https
|
|
5517
5604
|
* secure_cookie: false
|
|
5518
5605
|
*
|
|
5606
|
+
* // disables enriching user profiles with first touch marketing data
|
|
5607
|
+
* skip_first_touch_marketing: false
|
|
5608
|
+
*
|
|
5519
5609
|
* // the amount of time track_links will
|
|
5520
5610
|
* // wait for Mixpanel's servers to respond
|
|
5521
5611
|
* track_links_timeout: 300
|
|
5522
5612
|
*
|
|
5613
|
+
* // adds any UTM parameters and click IDs present on the page to any events fired
|
|
5614
|
+
* track_marketing: true
|
|
5615
|
+
*
|
|
5616
|
+
* // enables automatic page view tracking using default page view events through
|
|
5617
|
+
* // the track_pageview() method
|
|
5618
|
+
* track_pageview: false
|
|
5619
|
+
*
|
|
5523
5620
|
* // if you set upgrade to be true, the library will check for
|
|
5524
5621
|
* // a cookie from our old js library and import super
|
|
5525
5622
|
* // properties from it, then the old cookie is deleted
|
package/dist/mixpanel.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var Config = {
|
|
4
4
|
DEBUG: false,
|
|
5
|
-
LIB_VERSION: '2.
|
|
5
|
+
LIB_VERSION: '2.47.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
|
|
@@ -832,20 +832,24 @@ _.utf8Encode = function(string) {
|
|
|
832
832
|
|
|
833
833
|
_.UUID = (function() {
|
|
834
834
|
|
|
835
|
-
// Time
|
|
836
|
-
// 1*new Date() is a cross browser version of Date.now()
|
|
835
|
+
// Time-based entropy
|
|
837
836
|
var T = function() {
|
|
838
|
-
var
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
837
|
+
var time = 1 * new Date(); // cross-browser version of Date.now()
|
|
838
|
+
var ticks;
|
|
839
|
+
if (window$1.performance && window$1.performance.now) {
|
|
840
|
+
ticks = window$1.performance.now();
|
|
841
|
+
} else {
|
|
842
|
+
// fall back to busy loop
|
|
843
|
+
ticks = 0;
|
|
844
|
+
|
|
845
|
+
// this while loop figures how many browser ticks go by
|
|
846
|
+
// before 1*new Date() returns a new number, ie the amount
|
|
847
|
+
// of ticks that go by per millisecond
|
|
848
|
+
while (time == 1 * new Date()) {
|
|
849
|
+
ticks++;
|
|
850
|
+
}
|
|
846
851
|
}
|
|
847
|
-
|
|
848
|
-
return d.toString(16) + i.toString(16);
|
|
852
|
+
return time.toString(16) + Math.floor(ticks).toString(16);
|
|
849
853
|
};
|
|
850
854
|
|
|
851
855
|
// Math.Random entropy
|
|
@@ -1412,21 +1416,42 @@ _.dom_query = (function() {
|
|
|
1412
1416
|
};
|
|
1413
1417
|
})();
|
|
1414
1418
|
|
|
1419
|
+
var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'];
|
|
1420
|
+
var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid'];
|
|
1421
|
+
|
|
1415
1422
|
_.info = {
|
|
1416
|
-
campaignParams: function() {
|
|
1417
|
-
var
|
|
1418
|
-
kw = '',
|
|
1423
|
+
campaignParams: function(default_value) {
|
|
1424
|
+
var kw = '',
|
|
1419
1425
|
params = {};
|
|
1420
|
-
_.each(
|
|
1426
|
+
_.each(CAMPAIGN_KEYWORDS, function(kwkey) {
|
|
1421
1427
|
kw = _.getQueryParam(document$1.URL, kwkey);
|
|
1422
1428
|
if (kw.length) {
|
|
1423
1429
|
params[kwkey] = kw;
|
|
1430
|
+
} else if (default_value !== undefined) {
|
|
1431
|
+
params[kwkey] = default_value;
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
|
|
1435
|
+
return params;
|
|
1436
|
+
},
|
|
1437
|
+
|
|
1438
|
+
clickParams: function() {
|
|
1439
|
+
var id = '',
|
|
1440
|
+
params = {};
|
|
1441
|
+
_.each(CLICK_IDS, function(idkey) {
|
|
1442
|
+
id = _.getQueryParam(document$1.URL, idkey);
|
|
1443
|
+
if (id.length) {
|
|
1444
|
+
params[idkey] = id;
|
|
1424
1445
|
}
|
|
1425
1446
|
});
|
|
1426
1447
|
|
|
1427
1448
|
return params;
|
|
1428
1449
|
},
|
|
1429
1450
|
|
|
1451
|
+
marketingParams: function() {
|
|
1452
|
+
return _.extend(_.info.campaignParams(), _.info.clickParams());
|
|
1453
|
+
},
|
|
1454
|
+
|
|
1430
1455
|
searchEngine: function(referrer) {
|
|
1431
1456
|
if (referrer.search('https?://(.*)google.([^/?]*)') === 0) {
|
|
1432
1457
|
return 'google';
|
|
@@ -1623,12 +1648,13 @@ _.info = {
|
|
|
1623
1648
|
});
|
|
1624
1649
|
},
|
|
1625
1650
|
|
|
1626
|
-
|
|
1651
|
+
mpPageViewProperties: function() {
|
|
1627
1652
|
return _.strip_empty_properties({
|
|
1628
|
-
'
|
|
1629
|
-
'
|
|
1630
|
-
'
|
|
1631
|
-
'
|
|
1653
|
+
'current_page_title': document$1.title,
|
|
1654
|
+
'current_domain': window$1.location.hostname,
|
|
1655
|
+
'current_url_path': window$1.location.pathname,
|
|
1656
|
+
'current_url_protocol': window$1.location.protocol,
|
|
1657
|
+
'current_url_search': window$1.location.search
|
|
1632
1658
|
});
|
|
1633
1659
|
}
|
|
1634
1660
|
};
|
|
@@ -3806,13 +3832,6 @@ MixpanelPersistence.prototype.unregister = function(prop) {
|
|
|
3806
3832
|
}
|
|
3807
3833
|
};
|
|
3808
3834
|
|
|
3809
|
-
MixpanelPersistence.prototype.update_campaign_params = function() {
|
|
3810
|
-
if (!this.campaign_params_saved) {
|
|
3811
|
-
this.register_once(_.info.campaignParams());
|
|
3812
|
-
this.campaign_params_saved = true;
|
|
3813
|
-
}
|
|
3814
|
-
};
|
|
3815
|
-
|
|
3816
3835
|
MixpanelPersistence.prototype.update_search_keyword = function(referrer) {
|
|
3817
3836
|
this.register(_.info.searchInfo(referrer));
|
|
3818
3837
|
};
|
|
@@ -4137,6 +4156,9 @@ var DEFAULT_CONFIG = {
|
|
|
4137
4156
|
'cookie_domain': '',
|
|
4138
4157
|
'cookie_name': '',
|
|
4139
4158
|
'loaded': NOOP_FUNC,
|
|
4159
|
+
'track_marketing': true,
|
|
4160
|
+
'track_pageview': false,
|
|
4161
|
+
'skip_first_touch_marketing': false,
|
|
4140
4162
|
'store_google': true,
|
|
4141
4163
|
'save_referrer': true,
|
|
4142
4164
|
'test': false,
|
|
@@ -4203,6 +4225,25 @@ var create_mplib = function(token, config, name) {
|
|
|
4203
4225
|
instance['people'] = new MixpanelPeople();
|
|
4204
4226
|
instance['people']._init(instance);
|
|
4205
4227
|
|
|
4228
|
+
if (!instance.get_config('skip_first_touch_marketing')) {
|
|
4229
|
+
// We need null UTM params in the object because
|
|
4230
|
+
// UTM parameters act as a tuple. If any UTM param
|
|
4231
|
+
// is present, then we set all UTM params including
|
|
4232
|
+
// empty ones together
|
|
4233
|
+
var utm_params = _.info.campaignParams(null);
|
|
4234
|
+
var initial_utm_params = {};
|
|
4235
|
+
var has_utm = false;
|
|
4236
|
+
_.each(utm_params, function(utm_value, utm_key) {
|
|
4237
|
+
initial_utm_params['initial_' + utm_key] = utm_value;
|
|
4238
|
+
if (utm_value) {
|
|
4239
|
+
has_utm = true;
|
|
4240
|
+
}
|
|
4241
|
+
});
|
|
4242
|
+
if (has_utm) {
|
|
4243
|
+
instance['people'].set_once(initial_utm_params);
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
|
|
4206
4247
|
// if any instance on the page has debug = true, we set the
|
|
4207
4248
|
// global debug to be true
|
|
4208
4249
|
Config.DEBUG = Config.DEBUG || instance.get_config('debug');
|
|
@@ -4234,7 +4275,7 @@ var create_mplib = function(token, config, name) {
|
|
|
4234
4275
|
* mixpanel.library_name.track(...);
|
|
4235
4276
|
*
|
|
4236
4277
|
* @param {String} token Your Mixpanel API token
|
|
4237
|
-
* @param {Object} [config] A dictionary of config options to override. <a href="https://github.com/mixpanel/mixpanel-js/blob/
|
|
4278
|
+
* @param {Object} [config] A dictionary of config options to override. <a href="https://github.com/mixpanel/mixpanel-js/blob/v2.46.0/src/mixpanel-core.js#L88-L127">See a list of default config options</a>.
|
|
4238
4279
|
* @param {String} [name] The name for the new mixpanel instance that you want created
|
|
4239
4280
|
*/
|
|
4240
4281
|
MixpanelLib.prototype.init = function (token, config, name) {
|
|
@@ -4272,7 +4313,7 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
4272
4313
|
// default to JSON payload for standard mixpanel.com API hosts
|
|
4273
4314
|
if (!('api_payload_format' in config)) {
|
|
4274
4315
|
var api_host = config['api_host'] || DEFAULT_CONFIG['api_host'];
|
|
4275
|
-
if (api_host.match(/\.mixpanel\.com
|
|
4316
|
+
if (api_host.match(/\.mixpanel\.com/)) {
|
|
4276
4317
|
variable_features['api_payload_format'] = PAYLOAD_TYPE_JSON;
|
|
4277
4318
|
}
|
|
4278
4319
|
}
|
|
@@ -4347,6 +4388,10 @@ MixpanelLib.prototype._init = function(token, config, name) {
|
|
|
4347
4388
|
'$device_id': uuid
|
|
4348
4389
|
}, '');
|
|
4349
4390
|
}
|
|
4391
|
+
|
|
4392
|
+
if (this.get_config('track_pageview')) {
|
|
4393
|
+
this.track_pageview();
|
|
4394
|
+
}
|
|
4350
4395
|
};
|
|
4351
4396
|
|
|
4352
4397
|
// Private methods
|
|
@@ -4360,7 +4405,7 @@ MixpanelLib.prototype._loaded = function() {
|
|
|
4360
4405
|
MixpanelLib.prototype._set_default_superprops = function() {
|
|
4361
4406
|
this['persistence'].update_search_keyword(document$1.referrer);
|
|
4362
4407
|
if (this.get_config('store_google')) {
|
|
4363
|
-
this
|
|
4408
|
+
this.register(_.info.campaignParams(), {persistent: false});
|
|
4364
4409
|
}
|
|
4365
4410
|
if (this.get_config('save_referrer')) {
|
|
4366
4411
|
this['persistence'].update_referrer_info(document$1.referrer);
|
|
@@ -4842,6 +4887,10 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
4842
4887
|
|
|
4843
4888
|
this._set_default_superprops();
|
|
4844
4889
|
|
|
4890
|
+
var marketing_properties = this.get_config('track_marketing')
|
|
4891
|
+
? _.info.marketingParams()
|
|
4892
|
+
: {};
|
|
4893
|
+
|
|
4845
4894
|
// note: extend writes to the first object, so lets make sure we
|
|
4846
4895
|
// don't write to the persistence properties object and info
|
|
4847
4896
|
// properties object by passing in a new object
|
|
@@ -4850,6 +4899,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
|
|
|
4850
4899
|
properties = _.extend(
|
|
4851
4900
|
{},
|
|
4852
4901
|
_.info.properties(),
|
|
4902
|
+
marketing_properties,
|
|
4853
4903
|
this['persistence'].properties(),
|
|
4854
4904
|
this.unpersisted_superprops,
|
|
4855
4905
|
properties
|
|
@@ -5010,17 +5060,54 @@ MixpanelLib.prototype.get_group = function (group_key, group_id) {
|
|
|
5010
5060
|
};
|
|
5011
5061
|
|
|
5012
5062
|
/**
|
|
5013
|
-
* Track
|
|
5063
|
+
* Track a default Mixpanel page view event, which includes extra default event properties to
|
|
5064
|
+
* improve page view data. The `config.track_pageview` option for <a href="#mixpanelinit">mixpanel.init()</a>
|
|
5065
|
+
* may be turned on for tracking page loads automatically.
|
|
5014
5066
|
*
|
|
5015
|
-
*
|
|
5016
|
-
*
|
|
5067
|
+
* ### Usage
|
|
5068
|
+
*
|
|
5069
|
+
* // track a default $mp_web_page_view event
|
|
5070
|
+
* mixpanel.track_pageview();
|
|
5071
|
+
*
|
|
5072
|
+
* // track a page view event with additional event properties
|
|
5073
|
+
* mixpanel.track_pageview({'ab_test_variant': 'card-layout-b'});
|
|
5074
|
+
*
|
|
5075
|
+
* // example approach to track page views on different page types as event properties
|
|
5076
|
+
* mixpanel.track_pageview({'page': 'pricing'});
|
|
5077
|
+
* mixpanel.track_pageview({'page': 'homepage'});
|
|
5078
|
+
*
|
|
5079
|
+
* // UNCOMMON: Tracking a page view event with a custom event_name option. NOT expected to be used for
|
|
5080
|
+
* // individual pages on the same site or product. Use cases for custom event_name may be page
|
|
5081
|
+
* // views on different products or internal applications that are considered completely separate
|
|
5082
|
+
* mixpanel.track_pageview({'page': 'customer-search'}, {'event_name': '[internal] Admin Page View'});
|
|
5083
|
+
*
|
|
5084
|
+
* @param {Object} [properties] An optional set of additional properties to send with the page view event
|
|
5085
|
+
* @param {Object} [options] Page view tracking options
|
|
5086
|
+
* @param {String} [options.event_name] - Alternate name for the tracking event
|
|
5087
|
+
* @returns {Boolean|Object} If the tracking request was successfully initiated/queued, an object
|
|
5088
|
+
* with the tracking payload sent to the API server is returned; otherwise false.
|
|
5017
5089
|
*/
|
|
5018
|
-
MixpanelLib.prototype.track_pageview = function(
|
|
5019
|
-
if (
|
|
5020
|
-
|
|
5090
|
+
MixpanelLib.prototype.track_pageview = addOptOutCheckMixpanelLib(function(properties, options) {
|
|
5091
|
+
if (typeof properties !== 'object') {
|
|
5092
|
+
properties = {};
|
|
5021
5093
|
}
|
|
5022
|
-
|
|
5023
|
-
|
|
5094
|
+
options = options || {};
|
|
5095
|
+
var event_name = options['event_name'] || '$mp_web_page_view';
|
|
5096
|
+
|
|
5097
|
+
var default_page_properties = _.extend(
|
|
5098
|
+
_.info.mpPageViewProperties(),
|
|
5099
|
+
_.info.campaignParams(),
|
|
5100
|
+
_.info.clickParams()
|
|
5101
|
+
);
|
|
5102
|
+
|
|
5103
|
+
var event_properties = _.extend(
|
|
5104
|
+
{},
|
|
5105
|
+
default_page_properties,
|
|
5106
|
+
properties
|
|
5107
|
+
);
|
|
5108
|
+
|
|
5109
|
+
return this.track(event_name, event_properties);
|
|
5110
|
+
});
|
|
5024
5111
|
|
|
5025
5112
|
/**
|
|
5026
5113
|
* Track clicks on a set of document elements. Selector must be a
|
|
@@ -5516,10 +5603,20 @@ MixpanelLib.prototype.name_tag = function(name_tag) {
|
|
|
5516
5603
|
* // secure, meaning they will only be transmitted over https
|
|
5517
5604
|
* secure_cookie: false
|
|
5518
5605
|
*
|
|
5606
|
+
* // disables enriching user profiles with first touch marketing data
|
|
5607
|
+
* skip_first_touch_marketing: false
|
|
5608
|
+
*
|
|
5519
5609
|
* // the amount of time track_links will
|
|
5520
5610
|
* // wait for Mixpanel's servers to respond
|
|
5521
5611
|
* track_links_timeout: 300
|
|
5522
5612
|
*
|
|
5613
|
+
* // adds any UTM parameters and click IDs present on the page to any events fired
|
|
5614
|
+
* track_marketing: true
|
|
5615
|
+
*
|
|
5616
|
+
* // enables automatic page view tracking using default page view events through
|
|
5617
|
+
* // the track_pageview() method
|
|
5618
|
+
* track_pageview: false
|
|
5619
|
+
*
|
|
5523
5620
|
* // if you set upgrade to be true, the library will check for
|
|
5524
5621
|
* // a cookie from our old js library and import super
|
|
5525
5622
|
* // properties from it, then the old cookie is deleted
|