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.
@@ -6,7 +6,7 @@
6
6
 
7
7
  var Config = {
8
8
  DEBUG: false,
9
- LIB_VERSION: '2.46.0'
9
+ LIB_VERSION: '2.47.0'
10
10
  };
11
11
 
12
12
  // since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
@@ -836,20 +836,24 @@
836
836
 
837
837
  _.UUID = (function() {
838
838
 
839
- // Time/ticks information
840
- // 1*new Date() is a cross browser version of Date.now()
839
+ // Time-based entropy
841
840
  var T = function() {
842
- var d = 1 * new Date(),
843
- i = 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 (d == 1 * new Date()) {
849
- i++;
841
+ var time = 1 * new Date(); // cross-browser version of Date.now()
842
+ var ticks;
843
+ if (window$1.performance && window$1.performance.now) {
844
+ ticks = window$1.performance.now();
845
+ } else {
846
+ // fall back to busy loop
847
+ ticks = 0;
848
+
849
+ // this while loop figures how many browser ticks go by
850
+ // before 1*new Date() returns a new number, ie the amount
851
+ // of ticks that go by per millisecond
852
+ while (time == 1 * new Date()) {
853
+ ticks++;
854
+ }
850
855
  }
851
-
852
- return d.toString(16) + i.toString(16);
856
+ return time.toString(16) + Math.floor(ticks).toString(16);
853
857
  };
854
858
 
855
859
  // Math.Random entropy
@@ -1416,21 +1420,42 @@
1416
1420
  };
1417
1421
  })();
1418
1422
 
1423
+ var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'];
1424
+ var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid'];
1425
+
1419
1426
  _.info = {
1420
- campaignParams: function() {
1421
- var campaign_keywords = 'utm_source utm_medium utm_campaign utm_content utm_term'.split(' '),
1422
- kw = '',
1427
+ campaignParams: function(default_value) {
1428
+ var kw = '',
1423
1429
  params = {};
1424
- _.each(campaign_keywords, function(kwkey) {
1430
+ _.each(CAMPAIGN_KEYWORDS, function(kwkey) {
1425
1431
  kw = _.getQueryParam(document$1.URL, kwkey);
1426
1432
  if (kw.length) {
1427
1433
  params[kwkey] = kw;
1434
+ } else if (default_value !== undefined) {
1435
+ params[kwkey] = default_value;
1436
+ }
1437
+ });
1438
+
1439
+ return params;
1440
+ },
1441
+
1442
+ clickParams: function() {
1443
+ var id = '',
1444
+ params = {};
1445
+ _.each(CLICK_IDS, function(idkey) {
1446
+ id = _.getQueryParam(document$1.URL, idkey);
1447
+ if (id.length) {
1448
+ params[idkey] = id;
1428
1449
  }
1429
1450
  });
1430
1451
 
1431
1452
  return params;
1432
1453
  },
1433
1454
 
1455
+ marketingParams: function() {
1456
+ return _.extend(_.info.campaignParams(), _.info.clickParams());
1457
+ },
1458
+
1434
1459
  searchEngine: function(referrer) {
1435
1460
  if (referrer.search('https?://(.*)google.([^/?]*)') === 0) {
1436
1461
  return 'google';
@@ -1627,12 +1652,13 @@
1627
1652
  });
1628
1653
  },
1629
1654
 
1630
- pageviewInfo: function(page) {
1655
+ mpPageViewProperties: function() {
1631
1656
  return _.strip_empty_properties({
1632
- 'mp_page': page,
1633
- 'mp_referrer': document$1.referrer,
1634
- 'mp_browser': _.info.browser(userAgent, navigator.vendor, windowOpera),
1635
- 'mp_platform': _.info.os()
1657
+ 'current_page_title': document$1.title,
1658
+ 'current_domain': window$1.location.hostname,
1659
+ 'current_url_path': window$1.location.pathname,
1660
+ 'current_url_protocol': window$1.location.protocol,
1661
+ 'current_url_search': window$1.location.search
1636
1662
  });
1637
1663
  }
1638
1664
  };
@@ -3810,13 +3836,6 @@
3810
3836
  }
3811
3837
  };
3812
3838
 
3813
- MixpanelPersistence.prototype.update_campaign_params = function() {
3814
- if (!this.campaign_params_saved) {
3815
- this.register_once(_.info.campaignParams());
3816
- this.campaign_params_saved = true;
3817
- }
3818
- };
3819
-
3820
3839
  MixpanelPersistence.prototype.update_search_keyword = function(referrer) {
3821
3840
  this.register(_.info.searchInfo(referrer));
3822
3841
  };
@@ -4141,6 +4160,9 @@
4141
4160
  'cookie_domain': '',
4142
4161
  'cookie_name': '',
4143
4162
  'loaded': NOOP_FUNC,
4163
+ 'track_marketing': true,
4164
+ 'track_pageview': false,
4165
+ 'skip_first_touch_marketing': false,
4144
4166
  'store_google': true,
4145
4167
  'save_referrer': true,
4146
4168
  'test': false,
@@ -4207,6 +4229,25 @@
4207
4229
  instance['people'] = new MixpanelPeople();
4208
4230
  instance['people']._init(instance);
4209
4231
 
4232
+ if (!instance.get_config('skip_first_touch_marketing')) {
4233
+ // We need null UTM params in the object because
4234
+ // UTM parameters act as a tuple. If any UTM param
4235
+ // is present, then we set all UTM params including
4236
+ // empty ones together
4237
+ var utm_params = _.info.campaignParams(null);
4238
+ var initial_utm_params = {};
4239
+ var has_utm = false;
4240
+ _.each(utm_params, function(utm_value, utm_key) {
4241
+ initial_utm_params['initial_' + utm_key] = utm_value;
4242
+ if (utm_value) {
4243
+ has_utm = true;
4244
+ }
4245
+ });
4246
+ if (has_utm) {
4247
+ instance['people'].set_once(initial_utm_params);
4248
+ }
4249
+ }
4250
+
4210
4251
  // if any instance on the page has debug = true, we set the
4211
4252
  // global debug to be true
4212
4253
  Config.DEBUG = Config.DEBUG || instance.get_config('debug');
@@ -4238,7 +4279,7 @@
4238
4279
  * mixpanel.library_name.track(...);
4239
4280
  *
4240
4281
  * @param {String} token Your Mixpanel API token
4241
- * @param {Object} [config] A dictionary of config options to override. <a href="https://github.com/mixpanel/mixpanel-js/blob/8b2e1f7b/src/mixpanel-core.js#L87-L110">See a list of default config options</a>.
4282
+ * @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>.
4242
4283
  * @param {String} [name] The name for the new mixpanel instance that you want created
4243
4284
  */
4244
4285
  MixpanelLib.prototype.init = function (token, config, name) {
@@ -4276,7 +4317,7 @@
4276
4317
  // default to JSON payload for standard mixpanel.com API hosts
4277
4318
  if (!('api_payload_format' in config)) {
4278
4319
  var api_host = config['api_host'] || DEFAULT_CONFIG['api_host'];
4279
- if (api_host.match(/\.mixpanel\.com$/)) {
4320
+ if (api_host.match(/\.mixpanel\.com/)) {
4280
4321
  variable_features['api_payload_format'] = PAYLOAD_TYPE_JSON;
4281
4322
  }
4282
4323
  }
@@ -4351,6 +4392,10 @@
4351
4392
  '$device_id': uuid
4352
4393
  }, '');
4353
4394
  }
4395
+
4396
+ if (this.get_config('track_pageview')) {
4397
+ this.track_pageview();
4398
+ }
4354
4399
  };
4355
4400
 
4356
4401
  // Private methods
@@ -4364,7 +4409,7 @@
4364
4409
  MixpanelLib.prototype._set_default_superprops = function() {
4365
4410
  this['persistence'].update_search_keyword(document$1.referrer);
4366
4411
  if (this.get_config('store_google')) {
4367
- this['persistence'].update_campaign_params();
4412
+ this.register(_.info.campaignParams(), {persistent: false});
4368
4413
  }
4369
4414
  if (this.get_config('save_referrer')) {
4370
4415
  this['persistence'].update_referrer_info(document$1.referrer);
@@ -4846,6 +4891,10 @@
4846
4891
 
4847
4892
  this._set_default_superprops();
4848
4893
 
4894
+ var marketing_properties = this.get_config('track_marketing')
4895
+ ? _.info.marketingParams()
4896
+ : {};
4897
+
4849
4898
  // note: extend writes to the first object, so lets make sure we
4850
4899
  // don't write to the persistence properties object and info
4851
4900
  // properties object by passing in a new object
@@ -4854,6 +4903,7 @@
4854
4903
  properties = _.extend(
4855
4904
  {},
4856
4905
  _.info.properties(),
4906
+ marketing_properties,
4857
4907
  this['persistence'].properties(),
4858
4908
  this.unpersisted_superprops,
4859
4909
  properties
@@ -5014,17 +5064,54 @@
5014
5064
  };
5015
5065
 
5016
5066
  /**
5017
- * Track mp_page_view event. This is now ignored by the server.
5067
+ * Track a default Mixpanel page view event, which includes extra default event properties to
5068
+ * improve page view data. The `config.track_pageview` option for <a href="#mixpanelinit">mixpanel.init()</a>
5069
+ * may be turned on for tracking page loads automatically.
5018
5070
  *
5019
- * @param {String} [page] The url of the page to record. If you don't include this, it defaults to the current url.
5020
- * @deprecated
5071
+ * ### Usage
5072
+ *
5073
+ * // track a default $mp_web_page_view event
5074
+ * mixpanel.track_pageview();
5075
+ *
5076
+ * // track a page view event with additional event properties
5077
+ * mixpanel.track_pageview({'ab_test_variant': 'card-layout-b'});
5078
+ *
5079
+ * // example approach to track page views on different page types as event properties
5080
+ * mixpanel.track_pageview({'page': 'pricing'});
5081
+ * mixpanel.track_pageview({'page': 'homepage'});
5082
+ *
5083
+ * // UNCOMMON: Tracking a page view event with a custom event_name option. NOT expected to be used for
5084
+ * // individual pages on the same site or product. Use cases for custom event_name may be page
5085
+ * // views on different products or internal applications that are considered completely separate
5086
+ * mixpanel.track_pageview({'page': 'customer-search'}, {'event_name': '[internal] Admin Page View'});
5087
+ *
5088
+ * @param {Object} [properties] An optional set of additional properties to send with the page view event
5089
+ * @param {Object} [options] Page view tracking options
5090
+ * @param {String} [options.event_name] - Alternate name for the tracking event
5091
+ * @returns {Boolean|Object} If the tracking request was successfully initiated/queued, an object
5092
+ * with the tracking payload sent to the API server is returned; otherwise false.
5021
5093
  */
5022
- MixpanelLib.prototype.track_pageview = function(page) {
5023
- if (_.isUndefined(page)) {
5024
- page = document$1.location.href;
5094
+ MixpanelLib.prototype.track_pageview = addOptOutCheckMixpanelLib(function(properties, options) {
5095
+ if (typeof properties !== 'object') {
5096
+ properties = {};
5025
5097
  }
5026
- this.track('mp_page_view', _.info.pageviewInfo(page));
5027
- };
5098
+ options = options || {};
5099
+ var event_name = options['event_name'] || '$mp_web_page_view';
5100
+
5101
+ var default_page_properties = _.extend(
5102
+ _.info.mpPageViewProperties(),
5103
+ _.info.campaignParams(),
5104
+ _.info.clickParams()
5105
+ );
5106
+
5107
+ var event_properties = _.extend(
5108
+ {},
5109
+ default_page_properties,
5110
+ properties
5111
+ );
5112
+
5113
+ return this.track(event_name, event_properties);
5114
+ });
5028
5115
 
5029
5116
  /**
5030
5117
  * Track clicks on a set of document elements. Selector must be a
@@ -5520,10 +5607,20 @@
5520
5607
  * // secure, meaning they will only be transmitted over https
5521
5608
  * secure_cookie: false
5522
5609
  *
5610
+ * // disables enriching user profiles with first touch marketing data
5611
+ * skip_first_touch_marketing: false
5612
+ *
5523
5613
  * // the amount of time track_links will
5524
5614
  * // wait for Mixpanel's servers to respond
5525
5615
  * track_links_timeout: 300
5526
5616
  *
5617
+ * // adds any UTM parameters and click IDs present on the page to any events fired
5618
+ * track_marketing: true
5619
+ *
5620
+ * // enables automatic page view tracking using default page view events through
5621
+ * // the track_pageview() method
5622
+ * track_pageview: false
5623
+ *
5527
5624
  * // if you set upgrade to be true, the library will check for
5528
5625
  * // a cookie from our old js library and import super
5529
5626
  * // properties from it, then the old cookie is deleted
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mixpanel-browser",
3
- "version": "2.46.0",
3
+ "version": "2.47.0",
4
4
  "description": "The official Mixpanel JavaScript browser client library",
5
5
  "main": "dist/mixpanel.cjs.js",
6
6
  "directories": {
package/src/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var Config = {
2
2
  DEBUG: false,
3
- LIB_VERSION: '2.46.0'
3
+ LIB_VERSION: '2.47.0'
4
4
  };
5
5
 
6
6
  export default Config;
@@ -99,6 +99,9 @@ var DEFAULT_CONFIG = {
99
99
  'cookie_domain': '',
100
100
  'cookie_name': '',
101
101
  'loaded': NOOP_FUNC,
102
+ 'track_marketing': true,
103
+ 'track_pageview': false,
104
+ 'skip_first_touch_marketing': false,
102
105
  'store_google': true,
103
106
  'save_referrer': true,
104
107
  'test': false,
@@ -165,6 +168,25 @@ var create_mplib = function(token, config, name) {
165
168
  instance['people'] = new MixpanelPeople();
166
169
  instance['people']._init(instance);
167
170
 
171
+ if (!instance.get_config('skip_first_touch_marketing')) {
172
+ // We need null UTM params in the object because
173
+ // UTM parameters act as a tuple. If any UTM param
174
+ // is present, then we set all UTM params including
175
+ // empty ones together
176
+ var utm_params = _.info.campaignParams(null);
177
+ var initial_utm_params = {};
178
+ var has_utm = false;
179
+ _.each(utm_params, function(utm_value, utm_key) {
180
+ initial_utm_params['initial_' + utm_key] = utm_value;
181
+ if (utm_value) {
182
+ has_utm = true;
183
+ }
184
+ });
185
+ if (has_utm) {
186
+ instance['people'].set_once(initial_utm_params);
187
+ }
188
+ }
189
+
168
190
  // if any instance on the page has debug = true, we set the
169
191
  // global debug to be true
170
192
  Config.DEBUG = Config.DEBUG || instance.get_config('debug');
@@ -196,7 +218,7 @@ var create_mplib = function(token, config, name) {
196
218
  * mixpanel.library_name.track(...);
197
219
  *
198
220
  * @param {String} token Your Mixpanel API token
199
- * @param {Object} [config] A dictionary of config options to override. <a href="https://github.com/mixpanel/mixpanel-js/blob/8b2e1f7b/src/mixpanel-core.js#L87-L110">See a list of default config options</a>.
221
+ * @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>.
200
222
  * @param {String} [name] The name for the new mixpanel instance that you want created
201
223
  */
202
224
  MixpanelLib.prototype.init = function (token, config, name) {
@@ -234,7 +256,7 @@ MixpanelLib.prototype._init = function(token, config, name) {
234
256
  // default to JSON payload for standard mixpanel.com API hosts
235
257
  if (!('api_payload_format' in config)) {
236
258
  var api_host = config['api_host'] || DEFAULT_CONFIG['api_host'];
237
- if (api_host.match(/\.mixpanel\.com$/)) {
259
+ if (api_host.match(/\.mixpanel\.com/)) {
238
260
  variable_features['api_payload_format'] = PAYLOAD_TYPE_JSON;
239
261
  }
240
262
  }
@@ -309,6 +331,10 @@ MixpanelLib.prototype._init = function(token, config, name) {
309
331
  '$device_id': uuid
310
332
  }, '');
311
333
  }
334
+
335
+ if (this.get_config('track_pageview')) {
336
+ this.track_pageview();
337
+ }
312
338
  };
313
339
 
314
340
  // Private methods
@@ -322,7 +348,7 @@ MixpanelLib.prototype._loaded = function() {
322
348
  MixpanelLib.prototype._set_default_superprops = function() {
323
349
  this['persistence'].update_search_keyword(document.referrer);
324
350
  if (this.get_config('store_google')) {
325
- this['persistence'].update_campaign_params();
351
+ this.register(_.info.campaignParams(), {persistent: false});
326
352
  }
327
353
  if (this.get_config('save_referrer')) {
328
354
  this['persistence'].update_referrer_info(document.referrer);
@@ -804,6 +830,10 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
804
830
 
805
831
  this._set_default_superprops();
806
832
 
833
+ var marketing_properties = this.get_config('track_marketing')
834
+ ? _.info.marketingParams()
835
+ : {};
836
+
807
837
  // note: extend writes to the first object, so lets make sure we
808
838
  // don't write to the persistence properties object and info
809
839
  // properties object by passing in a new object
@@ -812,6 +842,7 @@ MixpanelLib.prototype.track = addOptOutCheckMixpanelLib(function(event_name, pro
812
842
  properties = _.extend(
813
843
  {},
814
844
  _.info.properties(),
845
+ marketing_properties,
815
846
  this['persistence'].properties(),
816
847
  this.unpersisted_superprops,
817
848
  properties
@@ -972,17 +1003,54 @@ MixpanelLib.prototype.get_group = function (group_key, group_id) {
972
1003
  };
973
1004
 
974
1005
  /**
975
- * Track mp_page_view event. This is now ignored by the server.
1006
+ * Track a default Mixpanel page view event, which includes extra default event properties to
1007
+ * improve page view data. The `config.track_pageview` option for <a href="#mixpanelinit">mixpanel.init()</a>
1008
+ * may be turned on for tracking page loads automatically.
976
1009
  *
977
- * @param {String} [page] The url of the page to record. If you don't include this, it defaults to the current url.
978
- * @deprecated
1010
+ * ### Usage
1011
+ *
1012
+ * // track a default $mp_web_page_view event
1013
+ * mixpanel.track_pageview();
1014
+ *
1015
+ * // track a page view event with additional event properties
1016
+ * mixpanel.track_pageview({'ab_test_variant': 'card-layout-b'});
1017
+ *
1018
+ * // example approach to track page views on different page types as event properties
1019
+ * mixpanel.track_pageview({'page': 'pricing'});
1020
+ * mixpanel.track_pageview({'page': 'homepage'});
1021
+ *
1022
+ * // UNCOMMON: Tracking a page view event with a custom event_name option. NOT expected to be used for
1023
+ * // individual pages on the same site or product. Use cases for custom event_name may be page
1024
+ * // views on different products or internal applications that are considered completely separate
1025
+ * mixpanel.track_pageview({'page': 'customer-search'}, {'event_name': '[internal] Admin Page View'});
1026
+ *
1027
+ * @param {Object} [properties] An optional set of additional properties to send with the page view event
1028
+ * @param {Object} [options] Page view tracking options
1029
+ * @param {String} [options.event_name] - Alternate name for the tracking event
1030
+ * @returns {Boolean|Object} If the tracking request was successfully initiated/queued, an object
1031
+ * with the tracking payload sent to the API server is returned; otherwise false.
979
1032
  */
980
- MixpanelLib.prototype.track_pageview = function(page) {
981
- if (_.isUndefined(page)) {
982
- page = document.location.href;
1033
+ MixpanelLib.prototype.track_pageview = addOptOutCheckMixpanelLib(function(properties, options) {
1034
+ if (typeof properties !== 'object') {
1035
+ properties = {};
983
1036
  }
984
- this.track('mp_page_view', _.info.pageviewInfo(page));
985
- };
1037
+ options = options || {};
1038
+ var event_name = options['event_name'] || '$mp_web_page_view';
1039
+
1040
+ var default_page_properties = _.extend(
1041
+ _.info.mpPageViewProperties(),
1042
+ _.info.campaignParams(),
1043
+ _.info.clickParams()
1044
+ );
1045
+
1046
+ var event_properties = _.extend(
1047
+ {},
1048
+ default_page_properties,
1049
+ properties
1050
+ );
1051
+
1052
+ return this.track(event_name, event_properties);
1053
+ });
986
1054
 
987
1055
  /**
988
1056
  * Track clicks on a set of document elements. Selector must be a
@@ -1478,10 +1546,20 @@ MixpanelLib.prototype.name_tag = function(name_tag) {
1478
1546
  * // secure, meaning they will only be transmitted over https
1479
1547
  * secure_cookie: false
1480
1548
  *
1549
+ * // disables enriching user profiles with first touch marketing data
1550
+ * skip_first_touch_marketing: false
1551
+ *
1481
1552
  * // the amount of time track_links will
1482
1553
  * // wait for Mixpanel's servers to respond
1483
1554
  * track_links_timeout: 300
1484
1555
  *
1556
+ * // adds any UTM parameters and click IDs present on the page to any events fired
1557
+ * track_marketing: true
1558
+ *
1559
+ * // enables automatic page view tracking using default page view events through
1560
+ * // the track_pageview() method
1561
+ * track_pageview: false
1562
+ *
1485
1563
  * // if you set upgrade to be true, the library will check for
1486
1564
  * // a cookie from our old js library and import super
1487
1565
  * // properties from it, then the old cookie is deleted
@@ -219,13 +219,6 @@ MixpanelPersistence.prototype.unregister = function(prop) {
219
219
  }
220
220
  };
221
221
 
222
- MixpanelPersistence.prototype.update_campaign_params = function() {
223
- if (!this.campaign_params_saved) {
224
- this.register_once(_.info.campaignParams());
225
- this.campaign_params_saved = true;
226
- }
227
- };
228
-
229
222
  MixpanelPersistence.prototype.update_search_keyword = function(referrer) {
230
223
  this.register(_.info.searchInfo(referrer));
231
224
  };
package/src/utils.js CHANGED
@@ -830,20 +830,24 @@ _.utf8Encode = function(string) {
830
830
 
831
831
  _.UUID = (function() {
832
832
 
833
- // Time/ticks information
834
- // 1*new Date() is a cross browser version of Date.now()
833
+ // Time-based entropy
835
834
  var T = function() {
836
- var d = 1 * new Date(),
837
- i = 0;
838
-
839
- // this while loop figures how many browser ticks go by
840
- // before 1*new Date() returns a new number, ie the amount
841
- // of ticks that go by per millisecond
842
- while (d == 1 * new Date()) {
843
- i++;
835
+ var time = 1 * new Date(); // cross-browser version of Date.now()
836
+ var ticks;
837
+ if (win.performance && win.performance.now) {
838
+ ticks = win.performance.now();
839
+ } else {
840
+ // fall back to busy loop
841
+ ticks = 0;
842
+
843
+ // this while loop figures how many browser ticks go by
844
+ // before 1*new Date() returns a new number, ie the amount
845
+ // of ticks that go by per millisecond
846
+ while (time == 1 * new Date()) {
847
+ ticks++;
848
+ }
844
849
  }
845
-
846
- return d.toString(16) + i.toString(16);
850
+ return time.toString(16) + Math.floor(ticks).toString(16);
847
851
  };
848
852
 
849
853
  // Math.Random entropy
@@ -1410,21 +1414,42 @@ _.dom_query = (function() {
1410
1414
  };
1411
1415
  })();
1412
1416
 
1417
+ var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'];
1418
+ var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid'];
1419
+
1413
1420
  _.info = {
1414
- campaignParams: function() {
1415
- var campaign_keywords = 'utm_source utm_medium utm_campaign utm_content utm_term'.split(' '),
1416
- kw = '',
1421
+ campaignParams: function(default_value) {
1422
+ var kw = '',
1417
1423
  params = {};
1418
- _.each(campaign_keywords, function(kwkey) {
1424
+ _.each(CAMPAIGN_KEYWORDS, function(kwkey) {
1419
1425
  kw = _.getQueryParam(document.URL, kwkey);
1420
1426
  if (kw.length) {
1421
1427
  params[kwkey] = kw;
1428
+ } else if (default_value !== undefined) {
1429
+ params[kwkey] = default_value;
1422
1430
  }
1423
1431
  });
1424
1432
 
1425
1433
  return params;
1426
1434
  },
1427
1435
 
1436
+ clickParams: function() {
1437
+ var id = '',
1438
+ params = {};
1439
+ _.each(CLICK_IDS, function(idkey) {
1440
+ id = _.getQueryParam(document.URL, idkey);
1441
+ if (id.length) {
1442
+ params[idkey] = id;
1443
+ }
1444
+ });
1445
+
1446
+ return params;
1447
+ },
1448
+
1449
+ marketingParams: function() {
1450
+ return _.extend(_.info.campaignParams(), _.info.clickParams());
1451
+ },
1452
+
1428
1453
  searchEngine: function(referrer) {
1429
1454
  if (referrer.search('https?://(.*)google.([^/?]*)') === 0) {
1430
1455
  return 'google';
@@ -1621,12 +1646,13 @@ _.info = {
1621
1646
  });
1622
1647
  },
1623
1648
 
1624
- pageviewInfo: function(page) {
1649
+ mpPageViewProperties: function() {
1625
1650
  return _.strip_empty_properties({
1626
- 'mp_page': page,
1627
- 'mp_referrer': document.referrer,
1628
- 'mp_browser': _.info.browser(userAgent, navigator.vendor, windowOpera),
1629
- 'mp_platform': _.info.os()
1651
+ 'current_page_title': document.title,
1652
+ 'current_domain': win.location.hostname,
1653
+ 'current_url_path': win.location.pathname,
1654
+ 'current_url_protocol': win.location.protocol,
1655
+ 'current_url_search': win.location.search
1630
1656
  });
1631
1657
  }
1632
1658
  };