diff --git a/dist/mixpanel-lite.min.js b/dist/mixpanel-lite.min.js index 3f39597..cc4124a 100644 --- a/dist/mixpanel-lite.min.js +++ b/dist/mixpanel-lite.min.js @@ -1,8 +1,8 @@ /*! - * mixpanel-lite.js - v1.5.5 + * mixpanel-lite.js - v1.5.6 * Lightweight version of mixpanel-js with offline support * https://github.com/john-doherty/mixpanel-lite * @author John Doherty * @license MIT */ -!function(e,n){"use strict";if(e.localStorage)if(e.Promise){var t="https://api.mixpanel.com/track?ip=1&verbose=1&data=",i="https://api.mixpanel.com/engage?ip=1&verbose=1&data=",o=null,r=!1,a=!1,l=null,s=(new Date).getTime(),c=0,d={},u={_key:"mixpanel-lite",_maxLength:100,all:function(){return JSON.parse(localStorage.getItem(u._key)||"[]")},add:function(e){var n=u.all();c++,e._id=s+"-"+c,n.length+1>u._maxLength&&n.shift(),n.push(e),localStorage.setItem(u._key,JSON.stringify(n))},remove:function(e){var n=(e||[]).map(function(e){return e._id}),t=u.all().filter(function(e){return-1===n.indexOf(e._id)});localStorage.setItem(u._key,JSON.stringify(t))},clear:function(){localStorage.setItem(u._key,JSON.stringify([]))}},f={init:function(e,n){console.log("mixpanel.track('"+e+"',"+JSON.stringify(n||{})+")")},track:function(e,n){console.log("mixpanel.track('"+e+"',"+JSON.stringify(n||{})+")")},register:function(e){console.log("mixpanel.register("+JSON.stringify(e||{})+")")},reset:function(){console.log("mixpanel.reset()")},identify:function(e){console.log("mixpanel.identify('"+e+"')")},getProperty:function(e){console.log("mixpanel.getProperty('"+e+"')")},people:{set:function(e){console.log("mixpanel.people.set("+JSON.stringify(e||{})+")")}},mute:O,unmute:_,muted:!0},p={init:b,track:m,register:function(e){Object.keys(e||{}).forEach(function(n){null!==e[n]&&""!==e[n]?d[n]=e[n]:delete d[n]})},reset:function(){b(o),r&&console.log("mixpanel.reset()")},identify:function(e){e&&""!==e.trim()?(r&&console.log("mixpanel.identify('"+e+"')"),m("$identify",{$anon_distinct_id:d.distinct_id,distinct_id:e,$user_id:e}),d.distinct_id=e,d.$user_id=e):console.warn("mixpanel.identify: Invalid id")},getProperty:function(e){return d[e]},people:{set:function(e){if(e&&"object"==typeof e){var n={$token:o,$distinct_id:d.distinct_id,$set:{}};Object.keys(e||{}).forEach(function(t){n.$set[t]=e[t]}),Object.keys(n.$set).forEach(function(e){null!==n.$set[e]&&""!==n.$set[e]||delete n.$set[e]}),u.add(n),v(),r&&(console.log("mixpanel.people.set("+JSON.stringify(e||{})+")"),console.dir(n))}else console.warn("mixpanel.setPeople: Invalid data param, must be an object")}},mute:O,unmute:_,muted:!1};e.mixpanel=p,e.addEventListener(e.cordova?"deviceready":"load",v,{passive:!0}),e.addEventListener("online",v,{passive:!0})}else console.warn("mixpanel-lite: Promise not supported (try adding a polyfill)");else console.warn("mixpanel-lite: localStorage not supported");function g(){var e=navigator.connection||navigator.mozConnection||navigator.webkitConnection||{};return e.effectiveType||e.type||""}function m(e,n){if(o)if(e&&""!==e)if(n&&"object"!=typeof n)console.warn("mixpanel.track: Data param must be an object");else{var t={event:e,properties:h(d)};Object.keys(n||{}).forEach(function(e){t.properties[e]=n[e]}),t.properties.$insert_id=Math.random().toString(36).substring(2,10)+Math.random().toString(36).substring(2,10),t.properties.time=Math.round((new Date).getTime()/1e3),Object.keys(t.properties).forEach(function(e){null!==t.properties[e]&&""!==t.properties[e]||delete t.properties[e]}),u.add(t),v(),r&&(n?console.log("mixpanel.track('"+e+"',"+JSON.stringify(n||{})+")"):console.log("mixpanel.track('"+e+"')"),console.dir(t))}else console.warn("mixpanel.track: Invalid eventName");else console.warn("mixpanel.track: You must call mixpanel.init(token) first")}function v(){if(a)return l&&clearTimeout(l),void(l=setTimeout(v,500));var n=u.all();if(-1!==n.length){a=!0,l&&(clearTimeout(l),l=null);var o,s,c=n.map(function(n){return function(){var o=n.$set?i:t,r=h(n);delete r._id;var a,l=(a=JSON.stringify(r),e.btoa(unescape(encodeURIComponent(a))));return function(e){return new Promise(function(n,t){var i=new XMLHttpRequest;i.open("GET",e),i.withCredentials=!0,i.onreadystatechange=function(){4===i.readyState&&(200===i.status?n({url:e,status:200,body:i.responseText||""}):t({url:e,status:i.status,body:i.responseText||""}))},i.send()})}(o+=encodeURIComponent(l)+"&_="+(new Date).getTime()).then(function(){n.__completed=!0})}});(o=c,s=Promise.resolve(),o.forEach(function(e){s=s.then(e)}),s).then(function(){var e=n.filter(function(e){return e.__completed});u.remove(e),a=!1}).catch(function(e){r&&console.log(e),a=!1})}}function h(e){return JSON.parse(JSON.stringify(e))}function y(){var e=navigator.userAgent;return/Windows Phone/i.test(e)||/WPDesktop/.test(e)?"Windows Phone":/iPad/.test(e)?"iPad":/iPod/.test(e)?"iPod Touch":/iPhone/.test(e)?"iPhone":/(BlackBerry|PlayBook|BB10)/i.test(e)?"BlackBerry":/Android/.test(e)?"Android":""}function x(e,n){return-1!==e.indexOf(n)}function S(){var n=navigator.userAgent,t=navigator.vendor||"";return e.opera||x(n," OPR/")?x(n,"Mini")?"Opera Mini":"Opera":/(BlackBerry|PlayBook|BB10)/i.test(n)?"BlackBerry":x(n,"IEMobile")||x(n,"WPDesktop")?"Internet Explorer Mobile":x(n,"Edge")?"Microsoft Edge":x(n,"FBIOS")?"Facebook Mobile":x(n,"Chrome")?"Chrome":x(n,"CriOS")?"Chrome iOS":x(n,"UCWEB")||x(n,"UCBrowser")?"UC Browser":x(n,"FxiOS")?"Firefox iOS":x(t,"Apple")?x(n,"Mobile")?"Mobile Safari":"Safari":x(n,"Android")?"Android Mobile":x(n,"Konqueror")?"Konqueror":x(n,"Firefox")?"Firefox":x(n,"MSIE")||x(n,"Trident/")?"Internet Explorer":x(n,"Gecko")?"Mozilla":""}function k(){var e=S(),n=navigator.userAgent,t={"Internet Explorer Mobile":/rv:(\d+(\.\d+)?)/,"Microsoft Edge":/Edge\/(\d+(\.\d+)?)/,Chrome:/Chrome\/(\d+(\.\d+)?)/,"Chrome iOS":/CriOS\/(\d+(\.\d+)?)/,"UC Browser":/(UCBrowser|UCWEB)\/(\d+(\.\d+)?)/,Safari:/Version\/(\d+(\.\d+)?)/,"Mobile Safari":/Version\/(\d+(\.\d+)?)/,Opera:/(Opera|OPR)\/(\d+(\.\d+)?)/,Firefox:/Firefox\/(\d+(\.\d+)?)/,"Firefox iOS":/FxiOS\/(\d+(\.\d+)?)/,Konqueror:/Konqueror:(\d+(\.\d+)?)/,BlackBerry:/BlackBerry (\d+(\.\d+)?)/,"Android Mobile":/android\s(\d+(\.\d+)?)/,"Internet Explorer":/(rv:|MSIE )(\d+(\.\d+)?)/,Mozilla:/rv:(\d+(\.\d+)?)/}[e];if(void 0===t)return null;var i=n.match(t);return i?parseFloat(i[i.length-2]):null}function O(){e.mixpanel=f}function _(){e.mixpanel=p}function b(a,l){if(!0===(l=l||{}).mute&&(e.mixpanel=f),l.trackingUrl&&""!==l.trackingUrl&&(t=l.trackingUrl),l.engageUrl&&""!==l.engageUrl&&(i=l.engageUrl),""!==(a=String(a||""))){o=a,r=!0===l.debug;var s,c,u,p,m=(s=function(){for(var e=1*new Date,n=0;e==1*new Date;)n++;return e.toString(16)+n.toString(16)},c=(screen.height*screen.width).toString(16),s()+"-"+Math.random().toString(16).replace(".","")+"-"+function(){var e,n,t=navigator.userAgent,i=[],o=0;function r(e,n){var t,o=0;for(t=0;t=4&&(o=r(o,i),i=[]);return i.length>0&&(o=r(o,i)),o.toString(16)}()+"-"+c+"-"+s());d={token:a,$os:(p=navigator.userAgent,/Windows/i.test(p)?/Phone/.test(p)||/WPDesktop/.test(p)?"Windows Phone":"Windows":/(iPhone|iPad|iPod)/.test(p)?"iOS":/Android/.test(p)?"Android":/(BlackBerry|PlayBook|BB10)/i.test(p)?"BlackBerry":/Mac/i.test(p)?"Mac OS X":/Linux/.test(p)?"Linux":/CrOS/.test(p)?"Chrome OS":""),$browser:S(),$browser_version:k(),$device:y(),$screen_height:screen.height,$screen_width:screen.width,$referrer:n.referrer,$referring_domain:(u=String(n.referrer||"").split("/"),u.length>=3?u[2]:""),distinct_id:m,$device_id:m,mp_lib:"mixpanel-lite",$lib_version:"1.5.5"},0===String(e.location.protocol).indexOf("http")&&(d.$current_url=e.location.href),"1"===String(navigator.doNotTrack||"0")&&(d.doNotTrack=!0),e.device&&(e.device.manufacturer&&(d.$manufacturer=e.device.manufacturer),e.device.model&&(d.$model=e.device.model),e.device.version&&(d.$os_version=e.device.version)),d.connectionType=g();var v=navigator.connection||navigator.mozConnection||navigator.webkitConnection;v&&v.addEventListener&&v.addEventListener("change",function(){d.connectionType=g()}),r&&console.log("mixpanel.init('"+o+"')")}else console.warn("mixpanel.init: invalid token")}}(this,document); \ No newline at end of file +!function(e,n){"use strict";if(e.localStorage)if(e.Promise){var t="https://api.mixpanel.com/track?ip=1&verbose=1&data=",i="https://api.mixpanel.com/engage?ip=1&verbose=1&data=",o=null,r=!1,a=!1,l=null,s=(new Date).getTime(),c=0,d={},u={_key:"mixpanel-lite",_maxLength:100,all:function(){return JSON.parse(localStorage.getItem(u._key)||"[]")},add:function(e){var n=u.all();c++,e._id=s+"-"+c,n.length+1>u._maxLength&&n.shift(),n.push(e),localStorage.setItem(u._key,JSON.stringify(n))},remove:function(e){var n=(e||[]).map(function(e){return e._id}),t=u.all().filter(function(e){return-1===n.indexOf(e._id)});localStorage.setItem(u._key,JSON.stringify(t))},clear:function(){localStorage.setItem(u._key,JSON.stringify([]))}},f={init:function(e,n){console.log("mixpanel.track('"+e+"',"+JSON.stringify(n||{})+")")},track:function(e,n){console.log("mixpanel.track('"+e+"',"+JSON.stringify(n||{})+")")},register:function(e){console.log("mixpanel.register("+JSON.stringify(e||{})+")")},reset:function(){console.log("mixpanel.reset()")},identify:function(e){console.log("mixpanel.identify('"+e+"')")},getProperty:function(e){console.log("mixpanel.getProperty('"+e+"')")},people:{set:function(e){console.log("mixpanel.people.set("+JSON.stringify(e||{})+")")}},mute:O,unmute:_,muted:!0},p={init:b,track:m,register:function(e){Object.keys(e||{}).forEach(function(n){null!==e[n]&&""!==e[n]?d[n]=e[n]:delete d[n]})},reset:function(){b(o),r&&console.log("mixpanel.reset()")},identify:function(e){e&&""!==e.trim()?(r&&console.log("mixpanel.identify('"+e+"')"),m("$identify",{$anon_distinct_id:d.distinct_id,distinct_id:e,$user_id:e}),d.distinct_id=e,d.$user_id=e):console.warn("mixpanel.identify: Invalid id")},getProperty:function(e){return d[e]},people:{set:function(e){if(e&&"object"==typeof e){var n={$token:o,$distinct_id:d.distinct_id,$set:{}};Object.keys(e||{}).forEach(function(t){n.$set[t]=e[t]}),Object.keys(n.$set).forEach(function(e){null!==n.$set[e]&&""!==n.$set[e]||delete n.$set[e]}),u.add(n),v(),r&&(console.log("mixpanel.people.set("+JSON.stringify(e||{})+")"),console.dir(n))}else console.warn("mixpanel.setPeople: Invalid data param, must be an object")}},mute:O,unmute:_,muted:!1};e.mixpanel=p,e.addEventListener(e.cordova?"deviceready":"load",v,{passive:!0}),e.addEventListener("online",v,{passive:!0})}else console.warn("mixpanel-lite: Promise not supported (try adding a polyfill)");else console.warn("mixpanel-lite: localStorage not supported");function g(){var e=navigator.connection||navigator.mozConnection||navigator.webkitConnection||{};return e.effectiveType||e.type||""}function m(e,n){if(o)if(e&&""!==e)if(n&&"object"!=typeof n)console.warn("mixpanel.track: Data param must be an object");else{var t={event:e,properties:h(d)};Object.keys(n||{}).forEach(function(e){t.properties[e]=n[e]}),t.properties.$insert_id=Math.random().toString(36).substring(2,10)+Math.random().toString(36).substring(2,10),t.properties.time=Math.round((new Date).getTime()/1e3),Object.keys(t.properties).forEach(function(e){null!==t.properties[e]&&""!==t.properties[e]||delete t.properties[e]}),u.add(t),v(),r&&(n?console.log("mixpanel.track('"+e+"',"+JSON.stringify(n||{})+")"):console.log("mixpanel.track('"+e+"')"),console.dir(t))}else console.warn("mixpanel.track: Invalid eventName");else console.warn("mixpanel.track: You must call mixpanel.init(token) first")}function v(){if(a)return l&&clearTimeout(l),void(l=setTimeout(v,500));var n=u.all();if(-1!==n.length){a=!0,l&&(clearTimeout(l),l=null);var o,s,c=n.map(function(n){return function(){var o=n.$set?i:t,r=h(n);delete r._id;var a,l=(a=JSON.stringify(r),e.btoa(unescape(encodeURIComponent(a))));return function(e){return new Promise(function(n,t){var i=new XMLHttpRequest;i.open("GET",e),i.withCredentials=!0,i.onreadystatechange=function(){4===i.readyState&&(200===i.status?n({url:e,status:200,body:i.responseText||""}):t({url:e,status:i.status,body:i.responseText||""}))},i.send()})}(o+=encodeURIComponent(l)+"&_="+(new Date).getTime()).then(function(){n.__completed=!0})}});(o=c,s=Promise.resolve(),o.forEach(function(e){s=s.then(e)}),s).then(function(){var e=n.filter(function(e){return e.__completed});u.remove(e),a=!1}).catch(function(e){r&&console.log(e),a=!1})}}function h(e){return JSON.parse(JSON.stringify(e))}function y(){var e=navigator.userAgent;return/Windows Phone/i.test(e)||/WPDesktop/.test(e)?"Windows Phone":/iPad/.test(e)?"iPad":/iPod/.test(e)?"iPod Touch":/iPhone/.test(e)?"iPhone":/(BlackBerry|PlayBook|BB10)/i.test(e)?"BlackBerry":/Android/.test(e)?"Android":""}function x(e,n){return-1!==e.indexOf(n)}function S(){var n=navigator.userAgent,t=navigator.vendor||"";return e.opera||x(n," OPR/")?x(n,"Mini")?"Opera Mini":"Opera":/(BlackBerry|PlayBook|BB10)/i.test(n)?"BlackBerry":x(n,"IEMobile")||x(n,"WPDesktop")?"Internet Explorer Mobile":x(n,"Edge")?"Microsoft Edge":x(n,"FBIOS")?"Facebook Mobile":x(n,"Chrome")?"Chrome":x(n,"CriOS")?"Chrome iOS":x(n,"UCWEB")||x(n,"UCBrowser")?"UC Browser":x(n,"FxiOS")?"Firefox iOS":x(t,"Apple")?x(n,"Mobile")?"Mobile Safari":"Safari":x(n,"Android")?"Android Mobile":x(n,"Konqueror")?"Konqueror":x(n,"Firefox")?"Firefox":x(n,"MSIE")||x(n,"Trident/")?"Internet Explorer":x(n,"Gecko")?"Mozilla":""}function k(){var e=S(),n=navigator.userAgent,t={"Internet Explorer Mobile":/rv:(\d+(\.\d+)?)/,"Microsoft Edge":/Edge\/(\d+(\.\d+)?)/,Chrome:/Chrome\/(\d+(\.\d+)?)/,"Chrome iOS":/CriOS\/(\d+(\.\d+)?)/,"UC Browser":/(UCBrowser|UCWEB)\/(\d+(\.\d+)?)/,Safari:/Version\/(\d+(\.\d+)?)/,"Mobile Safari":/Version\/(\d+(\.\d+)?)/,Opera:/(Opera|OPR)\/(\d+(\.\d+)?)/,Firefox:/Firefox\/(\d+(\.\d+)?)/,"Firefox iOS":/FxiOS\/(\d+(\.\d+)?)/,Konqueror:/Konqueror:(\d+(\.\d+)?)/,BlackBerry:/BlackBerry (\d+(\.\d+)?)/,"Android Mobile":/android\s(\d+(\.\d+)?)/,"Internet Explorer":/(rv:|MSIE )(\d+(\.\d+)?)/,Mozilla:/rv:(\d+(\.\d+)?)/}[e];if(void 0===t)return null;var i=n.match(t);return i?parseFloat(i[i.length-2]):null}function O(){e.mixpanel=f}function _(){e.mixpanel=p}function b(a,l){if(!0===(l=l||{}).mute&&(e.mixpanel=f),l.trackingUrl&&""!==l.trackingUrl&&(t=l.trackingUrl),l.engageUrl&&""!==l.engageUrl&&(i=l.engageUrl),""!==(a=String(a||""))){o=a,r=!0===l.debug;var s,c,u,p,m=(s=function(){for(var e=1*new Date,n=0;e==1*new Date;)n++;return e.toString(16)+n.toString(16)},c=(screen.height*screen.width).toString(16),s()+"-"+Math.random().toString(16).replace(".","")+"-"+function(){var e,n,t=navigator.userAgent,i=[],o=0;function r(e,n){var t,o=0;for(t=0;t=4&&(o=r(o,i),i=[]);return i.length>0&&(o=r(o,i)),o.toString(16)}()+"-"+c+"-"+s());d={token:a,$os:(p=navigator.userAgent,/Windows/i.test(p)?/Phone/.test(p)||/WPDesktop/.test(p)?"Windows Phone":"Windows":/(iPhone|iPad|iPod)/.test(p)?"iOS":/Android/.test(p)?"Android":/(BlackBerry|PlayBook|BB10)/i.test(p)?"BlackBerry":/Mac/i.test(p)?"Mac OS X":/Linux/.test(p)?"Linux":/CrOS/.test(p)?"Chrome OS":""),$browser:S(),$browser_version:k(),$device:y(),$screen_height:screen.height,$screen_width:screen.width,$referrer:n.referrer,$referring_domain:(u=String(n.referrer||"").split("/"),u.length>=3?u[2]:""),distinct_id:m,$device_id:m,mp_lib:"mixpanel-lite",$lib_version:"1.5.6"},0===String(e.location.protocol).indexOf("http")&&(d.$current_url=e.location.href),"1"===String(navigator.doNotTrack||"0")&&(d.doNotTrack=!0),e.device&&(e.device.manufacturer&&(d.$manufacturer=e.device.manufacturer),e.device.model&&(d.$model=e.device.model),e.device.version&&(d.$os_version=e.device.version)),d.connectionType=g();var v=navigator.connection||navigator.mozConnection||navigator.webkitConnection;v&&v.addEventListener&&v.addEventListener("change",function(){d.connectionType=g()}),r&&console.log("mixpanel.init('"+o+"')")}else console.warn("mixpanel.init: invalid token")}}(this,document); \ No newline at end of file diff --git a/package.json b/package.json index 8b19797..13f3490 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mixpanel-lite", - "version": "1.5.5", + "version": "1.5.6", "description": "A lightweight alternative to mixpanel-js with offline support for Hybrid and Progressive Web Apps", "main": "src/mixpanel-lite.js", "scripts": {