Socket
Socket
Sign inDemoInstall

mixpanel-browser

Package Overview
Dependencies
Maintainers
6
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mixpanel-browser - npm Package Compare versions

Comparing version 2.43.0 to 2.45.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

**2.45.0** (17 Feb 2022)
- Remove all code related to in-app messaging feature
- Add `error_reporter` config option for user-configurable handling of errors
- Fix missing `var` declarations in HTML script snippet
- Fixes for some batch/retry edge cases where localStorage write failures resulted in duplicate sends
**2.43.0** (5 Jan 2022)

@@ -2,0 +8,0 @@ - Support plain JSON tracking payloads (no base64-encoding) and use as default when sendinig to *.mixpanel.com API hosts

6

dist/mixpanel-jslib-snippet.min.js

@@ -1,3 +0,3 @@

(function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(e,f,c){function g(a,d){var b=d.split(".");2==b.length&&(a=a[b[0]],d=b[1]);a[d]=function(){a.push([d].concat(Array.prototype.slice.call(arguments,0)))}}var a=b;"undefined"!==typeof c?a=b[c]=[]:c="mixpanel";a.people=a.people||[];a.toString=function(a){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);a||(d+=" (stub)");return d};a.people.toString=function(){return a.toString(1)+".people (stub)"};i="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(" ");
for(h=0;h<i.length;h++)g(a,i[h]);var j="set set_once union unset remove delete".split(" ");a.get_group=function(){function b(c){d[c]=function(){call2_args=arguments;call2=[c].concat(Array.prototype.slice.call(call2_args,0));a.push([e,call2])}}for(var d={},e=["get_group"].concat(Array.prototype.slice.call(arguments,0)),c=0;c<j.length;c++)b(j[c]);return d};b._i.push([e,f,c])};b.__SV=1.2;e=f.createElement("script");e.type="text/javascript";e.async=!0;e.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?
MIXPANEL_CUSTOM_LIB_URL:"file:"===f.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=f.getElementsByTagName("script")[0];g.parentNode.insertBefore(e,g)}})(document,window.mixpanel||[]);
(function(f,a){if(!a.__SV){var e,g,i,h;window.mixpanel=a;a._i=[];a.init=function(e,f,c){function g(b,d){var a=d.split(".");2==a.length&&(b=b[a[0]],d=a[1]);b[d]=function(){b.push([d].concat(Array.prototype.slice.call(arguments,0)))}}var b=a;"undefined"!==typeof c?b=a[c]=[]:c="mixpanel";b.people=b.people||[];b.toString=function(b){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);b||(d+=" (stub)");return d};b.people.toString=function(){return b.toString(1)+".people (stub)"};i="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(" ");
for(h=0;h<i.length;h++)g(b,i[h]);var j="set set_once union unset remove delete".split(" ");b.get_group=function(){function a(c){d[c]=function(){var a=[c].concat(Array.prototype.slice.call(arguments,0));b.push([e,a])}}for(var d={},e=["get_group"].concat(Array.prototype.slice.call(arguments,0)),c=0;c<j.length;c++)a(j[c]);return d};a._i.push([e,f,c])};a.__SV=1.2;e=f.createElement("script");e.type="text/javascript";e.async=!0;e.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:
"file:"===f.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=f.getElementsByTagName("script")[0];g.parentNode.insertBefore(e,g)}})(document,window.mixpanel||[]);

@@ -1,3 +0,3 @@

(function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(e,f,c){function g(a,d){var b=d.split(".");2==b.length&&(a=a[b[0]],d=b[1]);a[d]=function(){a.push([d].concat(Array.prototype.slice.call(arguments,0)))}}var a=b;"undefined"!==typeof c?a=b[c]=[]:c="mixpanel";a.people=a.people||[];a.toString=function(a){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);a||(d+=" (stub)");return d};a.people.toString=function(){return a.toString(1)+".people (stub)"};i="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(" ");
for(h=0;h<i.length;h++)g(a,i[h]);var j="set set_once union unset remove delete".split(" ");a.get_group=function(){function b(c){d[c]=function(){call2_args=arguments;call2=[c].concat(Array.prototype.slice.call(call2_args,0));a.push([e,call2])}}for(var d={},e=["get_group"].concat(Array.prototype.slice.call(arguments,0)),c=0;c<j.length;c++)b(j[c]);return d};b._i.push([e,f,c])};b.__SV=1.2;e=f.createElement("script");e.type="text/javascript";e.async=!0;e.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?
MIXPANEL_CUSTOM_LIB_URL:"file:"===f.location.protocol&&"../build/mixpanel.min.js".match(/^\/\//)?"https:../build/mixpanel.min.js":"../build/mixpanel.min.js";g=f.getElementsByTagName("script")[0];g.parentNode.insertBefore(e,g)}})(document,window.mixpanel||[]);
(function(f,a){if(!a.__SV){var e,g,i,h;window.mixpanel=a;a._i=[];a.init=function(e,f,c){function g(b,d){var a=d.split(".");2==a.length&&(b=b[a[0]],d=a[1]);b[d]=function(){b.push([d].concat(Array.prototype.slice.call(arguments,0)))}}var b=a;"undefined"!==typeof c?b=a[c]=[]:c="mixpanel";b.people=b.people||[];b.toString=function(b){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);b||(d+=" (stub)");return d};b.people.toString=function(){return b.toString(1)+".people (stub)"};i="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(" ");
for(h=0;h<i.length;h++)g(b,i[h]);var j="set set_once union unset remove delete".split(" ");b.get_group=function(){function a(c){d[c]=function(){var a=[c].concat(Array.prototype.slice.call(arguments,0));b.push([e,a])}}for(var d={},e=["get_group"].concat(Array.prototype.slice.call(arguments,0)),c=0;c<j.length;c++)a(j[c]);return d};a._i.push([e,f,c])};a.__SV=1.2;e=f.createElement("script");e.type="text/javascript";e.async=!0;e.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:
"file:"===f.location.protocol&&"../build/mixpanel.min.js".match(/^\/\//)?"https:../build/mixpanel.min.js":"../build/mixpanel.min.js";g=f.getElementsByTagName("script")[0];g.parentNode.insertBefore(e,g)}})(document,window.mixpanel||[]);

@@ -71,4 +71,4 @@ // ==ClosureCompiler==

mock_group[fn_name] = function() {
call2_args = arguments;
call2 = [fn_name].concat(Array.prototype.slice.call(call2_args, 0));
var call2_args = arguments;
var call2 = [fn_name].concat(Array.prototype.slice.call(call2_args, 0));
target.push([call1, call2]);

@@ -75,0 +75,0 @@ };

{
"name": "mixpanel-browser",
"version": "2.43.0",
"version": "2.45.0",
"description": "The official Mixpanel JavaScript browser client library",

@@ -5,0 +5,0 @@ "main": "dist/mixpanel.cjs.js",

var Config = {
DEBUG: false,
LIB_VERSION: '2.43.0'
LIB_VERSION: '2.45.0'
};
export default Config;

@@ -12,3 +12,2 @@ /* eslint camelcase: "off" */

} from './api-actions';
import Config from './config';
import { _, console } from './utils';

@@ -29,3 +28,2 @@

/** @const */ var ALIAS_ID_KEY = '__alias';
/** @const */ var CAMPAIGN_IDS_KEY = '__cmpns';
/** @const */ var EVENT_TIMERS_KEY = '__timers';

@@ -42,3 +40,2 @@ /** @const */ var RESERVED_PROPERTIES = [

ALIAS_ID_KEY,
CAMPAIGN_IDS_KEY,
EVENT_TIMERS_KEY

@@ -157,3 +154,2 @@ ];

if (this.disabled) { return; }
this._expire_notification_campaigns();
this.storage.set(

@@ -230,18 +226,2 @@ this.name,

MixpanelPersistence.prototype._expire_notification_campaigns = _.safewrap(function() {
var campaigns_shown = this['props'][CAMPAIGN_IDS_KEY],
EXPIRY_TIME = Config.DEBUG ? 60 * 1000 : 60 * 60 * 1000; // 1 minute (Config.DEBUG) / 1 hour (PDXN)
if (!campaigns_shown) {
return;
}
for (var campaign_id in campaigns_shown) {
if (1 * new Date() - campaigns_shown[campaign_id] > EXPIRY_TIME) {
delete campaigns_shown[campaign_id];
}
}
if (_.isEmptyObject(campaigns_shown)) {
delete this['props'][CAMPAIGN_IDS_KEY];
}
});
MixpanelPersistence.prototype.update_campaign_params = function() {

@@ -509,4 +489,3 @@ if (!this.campaign_params_saved) {

ALIAS_ID_KEY,
CAMPAIGN_IDS_KEY,
EVENT_TIMERS_KEY
};

@@ -16,3 +16,7 @@ import { RequestQueue } from './request-queue';

var RequestBatcher = function(storageKey, options) {
this.queue = new RequestQueue(storageKey, {storage: options.storage});
this.errorReporter = options.errorReporter;
this.queue = new RequestQueue(storageKey, {
errorReporter: _.bind(this.reportError, this),
storage: options.storage
});

@@ -22,2 +26,3 @@ this.libConfig = options.libConfig;

this.beforeSendHook = options.beforeSendHook;
this.stopAllBatching = options.stopAllBatchingFunc;

@@ -29,2 +34,3 @@ // seed variable batch size + flush interval with configured values

this.stopped = !this.libConfig['batch_autostart'];
this.consecutiveRemovalFailures = 0;
};

@@ -45,2 +51,3 @@

this.stopped = false;
this.consecutiveRemovalFailures = 0;
this.flush();

@@ -150,3 +157,3 @@ };

) {
logger.error('Network timeout; retrying');
this.reportError('Network timeout; retrying');
this.flush();

@@ -168,3 +175,3 @@ } else if (

retryMS = Math.min(MAX_RETRY_INTERVAL_MS, retryMS);
logger.error('Error; retry in ' + retryMS + ' ms');
this.reportError('Error; retry in ' + retryMS + ' ms');
this.scheduleFlush(retryMS);

@@ -176,6 +183,6 @@ } else if (_.isObject(res) && res.xhr_req && res.xhr_req['status'] === 413) {

this.batchSize = Math.min(this.batchSize, halvedBatchSize, batch.length - 1);
logger.error('413 response; reducing batch size to ' + this.batchSize);
this.reportError('413 response; reducing batch size to ' + this.batchSize);
this.resetFlush();
} else {
logger.error('Single-event request too large; dropping', batch);
this.reportError('Single-event request too large; dropping', batch);
this.resetBatchSize();

@@ -193,3 +200,16 @@ removeItemsFromQueue = true;

_.map(batch, function(item) { return item['id']; }),
_.bind(this.flush, this) // handle next batch if the queue isn't empty
_.bind(function(succeeded) {
if (succeeded) {
this.consecutiveRemovalFailures = 0;
this.flush(); // handle next batch if the queue isn't empty
} else {
this.reportError('Failed to remove items from queue');
if (++this.consecutiveRemovalFailures > 5) {
this.reportError('Too many queue failures; disabling batching system.');
this.stopAllBatching();
} else {
this.resetFlush();
}
}
}, this)
);

@@ -199,3 +219,3 @@ }

} catch(err) {
logger.error('Error handling API response', err);
this.reportError('Error handling API response', err);
this.resetFlush();

@@ -217,3 +237,3 @@ }

} catch(err) {
logger.error('Error flushing request queue', err);
this.reportError('Error flushing request queue', err);
this.resetFlush();

@@ -223,2 +243,19 @@ }

/**
* Log error to global logger and optional user-defined logger.
*/
RequestBatcher.prototype.reportError = function(msg, err) {
logger.error.apply(logger.error, arguments);
if (this.errorReporter) {
try {
if (!(err instanceof Error)) {
err = new Error(msg);
}
this.errorReporter(msg, err);
} catch(err) {
logger.error(err);
}
}
};
export { RequestBatcher };
import { SharedLock } from './shared-lock';
import { cheap_guid, console_with_prefix, JSONParse, JSONStringify, _ } from './utils'; // eslint-disable-line camelcase
import { cheap_guid, console_with_prefix, localStorageSupported, JSONParse, JSONStringify, _ } from './utils'; // eslint-disable-line camelcase

@@ -26,2 +26,3 @@ var logger = console_with_prefix('batch');

this.storage = options.storage || window.localStorage;
this.reportError = options.errorReporter || _.bind(logger.error, logger);
this.lock = new SharedLock(storageKey, {storage: this.storage});

@@ -64,3 +65,3 @@

} catch(err) {
logger.error('Error enqueueing item', item);
this.reportError('Error enqueueing item', item);
succeeded = false;

@@ -71,8 +72,8 @@ }

}
}, this), function lockFailure(err) {
logger.error('Error acquiring storage lock', err);
}, this), _.bind(function lockFailure(err) {
this.reportError('Error acquiring storage lock', err);
if (cb) {
cb(false);
}
}, this.pid);
}, this), this.pid);
};

@@ -137,3 +138,4 @@

this.memQueue = filterOutIDsAndInvalid(this.memQueue, idSet);
this.lock.withLock(_.bind(function lockAcquired() {
var removeFromStorage = _.bind(function() {
var succeeded;

@@ -144,15 +146,50 @@ try {

succeeded = this.saveToStorage(storedQueue);
// an extra check: did storage report success but somehow
// the items are still there?
if (succeeded) {
storedQueue = this.readFromStorage();
for (var i = 0; i < storedQueue.length; i++) {
var item = storedQueue[i];
if (item['id'] && !!idSet[item['id']]) {
this.reportError('Item not removed from storage');
return false;
}
}
}
} catch(err) {
logger.error('Error removing items', ids);
this.reportError('Error removing items', ids);
succeeded = false;
}
return succeeded;
}, this);
this.lock.withLock(function lockAcquired() {
var succeeded = removeFromStorage();
if (cb) {
cb(succeeded);
}
}, this), function lockFailure(err) {
logger.error('Error acquiring storage lock', err);
}, _.bind(function lockFailure(err) {
var succeeded = false;
this.reportError('Error acquiring storage lock', err);
if (!localStorageSupported(this.storage, true)) {
// Looks like localStorage writes have stopped working sometime after
// initialization (probably full), and so nobody can acquire locks
// anymore. Consider it temporarily safe to remove items without the
// lock, since nobody's writing successfully anyway.
succeeded = removeFromStorage();
if (!succeeded) {
// OK, we couldn't even write out the smaller queue. Try clearing it
// entirely.
try {
this.storage.removeItem(this.storageKey);
} catch(err) {
this.reportError('Error clearing queue', err);
}
}
}
if (cb) {
cb(false);
cb(succeeded);
}
}, this.pid);
}, this), this.pid);
};

@@ -192,3 +229,3 @@

} catch(err) {
logger.error('Error updating items', itemsToUpdate);
this.reportError('Error updating items', itemsToUpdate);
succeeded = false;

@@ -199,8 +236,8 @@ }

}
}, this), function lockFailure(err) {
logger.error('Error acquiring storage lock', err);
}, this), _.bind(function lockFailure(err) {
this.reportError('Error acquiring storage lock', err);
if (cb) {
cb(false);
}
}, this.pid);
}, this), this.pid);
};

@@ -219,3 +256,3 @@

if (!_.isArray(storageEntry)) {
logger.error('Invalid storage entry:', storageEntry);
this.reportError('Invalid storage entry:', storageEntry);
storageEntry = null;

@@ -225,3 +262,3 @@ }

} catch (err) {
logger.error('Error retrieving queue', err);
this.reportError('Error retrieving queue', err);
storageEntry = null;

@@ -240,3 +277,3 @@ }

} catch (err) {
logger.error('Error saving queue', err);
this.reportError('Error saving queue', err);
return false;

@@ -243,0 +280,0 @@ }

@@ -153,10 +153,2 @@ /* eslint camelcase: "off", eqeqeq: "off" */

_.bind_instance_methods = function(obj) {
for (var func in obj) {
if (typeof(obj[func]) === 'function') {
obj[func] = _.bind(obj[func], obj);
}
}
};
/**

@@ -190,15 +182,2 @@ * @param {*=} obj

_.escapeHTML = function(s) {
var escaped = s;
if (escaped && _.isString(escaped)) {
escaped = escaped
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
return escaped;
};
_.extend = function(obj) {

@@ -379,29 +358,2 @@ _.each(slice.call(arguments, 1), function(source) {

_.safewrap = function(f) {
return function() {
try {
return f.apply(this, arguments);
} catch (e) {
console.critical('Implementation error. Please turn on debug and contact support@mixpanel.com.');
if (Config.DEBUG){
console.critical(e);
}
}
};
};
_.safewrap_class = function(klass, functions) {
for (var i = 0; i < functions.length; i++) {
klass.prototype[functions[i]] = _.safewrap(klass.prototype[functions[i]]);
}
};
_.safewrap_instance_methods = function(obj) {
for (var func in obj) {
if (typeof(obj[func]) === 'function') {
obj[func] = _.safewrap(obj[func]);
}
}
};
_.strip_empty_properties = function(p) {

@@ -408,0 +360,0 @@ var ret = {};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc