Comparing version 0.0.6 to 0.0.7
@@ -76,3 +76,3 @@ import { createStore, combineReducers, applyMiddleware, compose } from 'redux' | ||
let composeEnhancers | ||
let composeEnhancers = compose | ||
if (typeof window !== 'undefined') { | ||
@@ -79,0 +79,0 @@ const withDevTools = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose |
import EVENTS from '../events' | ||
import uuid from '../utils/uuid' | ||
// TODO come up with ls keys | ||
const ANALYTICS_ID = 'analytics_id' | ||
const inBrowser = typeof window !== 'undefined' | ||
const setId = () => { | ||
const id = uuid() | ||
if (!inBrowser) { | ||
return id | ||
} | ||
// TODO refactor with persistance options https://github.com/harrysolovay/state-mint/tree/master/src/persistence/methods | ||
localStorage.setItem(ANALYTICS_ID, id) | ||
@@ -14,2 +18,5 @@ return id | ||
const getId = () => { | ||
if (!inBrowser) { | ||
return null | ||
} | ||
return localStorage.getItem(ANALYTICS_ID) | ||
@@ -19,2 +26,5 @@ } | ||
const deleteId = () => { | ||
if (!inBrowser) { | ||
return null | ||
} | ||
return localStorage.removeItem(ANALYTICS_ID) | ||
@@ -21,0 +31,0 @@ } |
@@ -1,1 +0,1 @@ | ||
"use strict";var $jscomp=$jscomp||{};$jscomp.scope={},$jscomp.owns=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},$jscomp.assign="function"==typeof Object.assign?Object.assign:function(t,e){for(var n=1;n<arguments.length;n++){var r=arguments[n];if(r)for(var o in r)$jscomp.owns(r,o)&&(t[o]=r[o])}return t},$jscomp.ASSUME_ES5=!1,$jscomp.ASSUME_NO_NATIVE_MAP=!1,$jscomp.ASSUME_NO_NATIVE_SET=!1,$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(t,e,n){t!=Array.prototype&&t!=Object.prototype&&(t[e]=n.value)},$jscomp.getGlobal=function(t){return"undefined"!=typeof window&&window===t?t:"undefined"!=typeof global&&null!=global?global:t},$jscomp.global=$jscomp.getGlobal(this),$jscomp.polyfill=function(t,e,n,r){if(e){for(n=$jscomp.global,t=t.split("."),r=0;r<t.length-1;r++){var o=t[r];o in n||(n[o]={}),n=n[o]}(e=e(r=n[t=t[t.length-1]]))!=r&&null!=e&&$jscomp.defineProperty(n,t,{configurable:!0,writable:!0,value:e})}},$jscomp.polyfill("Object.assign",function(t){return t||$jscomp.assign},"es6","es3"),$jscomp.SYMBOL_PREFIX="jscomp_symbol_",$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){},$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)},$jscomp.Symbol=function(){var e=0;return function(t){return $jscomp.SYMBOL_PREFIX+(t||"")+e++}}(),$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var t=$jscomp.global.Symbol.iterator;t||(t=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator")),"function"!=typeof Array.prototype[t]&&$jscomp.defineProperty(Array.prototype,t,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}}),$jscomp.initSymbolIterator=function(){}},$jscomp.arrayIterator=function(t){var e=0;return $jscomp.iteratorPrototype(function(){return e<t.length?{done:!1,value:t[e++]}:{done:!0}})},$jscomp.iteratorPrototype=function(t){return $jscomp.initSymbolIterator(),(t={next:t})[$jscomp.global.Symbol.iterator]=function(){return this},t},$jscomp.polyfill("Array.from",function(t){return t||function(t,e,n){$jscomp.initSymbolIterator(),e=null!=e?e:function(t){return t};var r=[],o=t[Symbol.iterator];if("function"==typeof o){t=o.call(t);for(var i=0;!(o=t.next()).done;)r.push(e.call(n,o.value,i++))}else for(o=t.length,i=0;i<o;i++)r.push(e.call(n,t[i],i));return r}},"es6","es3"),$jscomp.findInternal=function(t,e,n){t instanceof String&&(t=String(t));for(var r=t.length,o=0;o<r;o++){var i=t[o];if(e.call(n,i,o,t))return{i:o,v:i}}return{i:-1,v:void 0}},$jscomp.polyfill("Array.prototype.findIndex",function(t){return t||function(t,e){return $jscomp.findInternal(this,t,e).i}},"es6","es3"),$jscomp.iteratorFromArray=function(e,n){$jscomp.initSymbolIterator(),e instanceof String&&(e+="");var r=0,o={next:function(){if(r<e.length){var t=r++;return{value:n(t,e[t]),done:!1}}return o.next=function(){return{done:!0,value:void 0}},o.next()}};return o[Symbol.iterator]=function(){return o},o},$jscomp.polyfill("Array.prototype.keys",function(t){return t||function(){return $jscomp.iteratorFromArray(this,function(t){return t})}},"es6","es3"),$jscomp.makeIterator=function(t){$jscomp.initSymbolIterator();var e=t[Symbol.iterator];return e?e.call(t):$jscomp.arrayIterator(t)},$jscomp.FORCE_POLYFILL_PROMISE=!1,$jscomp.polyfill("Promise",function(t){function e(){this.batch_=null}function c(n){return n instanceof u?n:new u(function(t,e){t(n)})}if(t&&!$jscomp.FORCE_POLYFILL_PROMISE)return t;e.prototype.asyncExecute=function(t){return null==this.batch_&&(this.batch_=[],this.asyncExecuteBatch_()),this.batch_.push(t),this},e.prototype.asyncExecuteBatch_=function(){var t=this;this.asyncExecuteFunction(function(){t.executeBatch_()})};var n=$jscomp.global.setTimeout;e.prototype.asyncExecuteFunction=function(t){n(t,0)},e.prototype.executeBatch_=function(){for(;this.batch_&&this.batch_.length;){var t=this.batch_;this.batch_=[];for(var e=0;e<t.length;++e){var n=t[e];t[e]=null;try{n()}catch(t){this.asyncThrow_(t)}}}this.batch_=null},e.prototype.asyncThrow_=function(t){this.asyncExecuteFunction(function(){throw t})};var u=function(t){this.state_=0,this.result_=void 0,this.onSettledCallbacks_=[];var e=this.createResolveAndReject_();try{t(e.resolve,e.reject)}catch(t){e.reject(t)}};u.prototype.createResolveAndReject_=function(){function t(e){return function(t){r||(r=!0,e.call(n,t))}}var n=this,r=!1;return{resolve:t(this.resolveTo_),reject:t(this.reject_)}},u.prototype.resolveTo_=function(t){if(t===this)this.reject_(new TypeError("A Promise cannot resolve to itself"));else if(t instanceof u)this.settleSameAsPromise_(t);else{t:switch(typeof t){case"object":var e=null!=t;break t;case"function":e=!0;break t;default:e=!1}e?this.resolveToNonPromiseObj_(t):this.fulfill_(t)}},u.prototype.resolveToNonPromiseObj_=function(t){var e=void 0;try{e=t.then}catch(t){return void this.reject_(t)}"function"==typeof e?this.settleSameAsThenable_(e,t):this.fulfill_(t)},u.prototype.reject_=function(t){this.settle_(2,t)},u.prototype.fulfill_=function(t){this.settle_(1,t)},u.prototype.settle_=function(t,e){if(0!=this.state_)throw Error("Cannot settle("+t+", "+e+"): Promise already settled in state"+this.state_);this.state_=t,this.result_=e,this.executeOnSettledCallbacks_()},u.prototype.executeOnSettledCallbacks_=function(){if(null!=this.onSettledCallbacks_){for(var t=0;t<this.onSettledCallbacks_.length;++t)o.asyncExecute(this.onSettledCallbacks_[t]);this.onSettledCallbacks_=null}};var o=new e;return u.prototype.settleSameAsPromise_=function(t){var e=this.createResolveAndReject_();t.callWhenSettled_(e.resolve,e.reject)},u.prototype.settleSameAsThenable_=function(t,e){var n=this.createResolveAndReject_();try{t.call(e,n.resolve,n.reject)}catch(t){n.reject(t)}},u.prototype.then=function(t,e){function n(e,t){return"function"==typeof e?function(t){try{r(e(t))}catch(t){o(t)}}:t}var r,o,i=new u(function(t,e){r=t,o=e});return this.callWhenSettled_(n(t,r),n(e,o)),i},u.prototype.catch=function(t){return this.then(void 0,t)},u.prototype.callWhenSettled_=function(t,e){function n(){switch(r.state_){case 1:t(r.result_);break;case 2:e(r.result_);break;default:throw Error("Unexpected state: "+r.state_)}}var r=this;null==this.onSettledCallbacks_?o.asyncExecute(n):this.onSettledCallbacks_.push(n)},u.resolve=c,u.reject=function(n){return new u(function(t,e){e(n)})},u.race=function(o){return new u(function(t,e){for(var n=$jscomp.makeIterator(o),r=n.next();!r.done;r=n.next())c(r.value).callWhenSettled_(t,e)})},u.all=function(t){var i=$jscomp.makeIterator(t),a=i.next();return a.done?c([]):new u(function(n,t){function e(e){return function(t){r[e]=t,0==--o&&n(r)}}for(var r=[],o=0;r.push(void 0),o++,c(a.value).callWhenSettled_(e(r.length-1),t),!(a=i.next()).done;);})},u},"es6","es3");var redux=require("redux"),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n,r=arguments[e];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},toConsumableArray=function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)},dynamic=[],dynamicMiddlewares=function(o){return function(r){return function(t){var e={getState:o.getState,dispatch:function(t){return o.dispatch(t)}},n=dynamic.map(function(t){return t(e)});return redux.compose.apply(void 0,toConsumableArray(n))(r)(t)}}},addMiddleware=function(){var t;dynamic=(t=dynamic).concat.apply(t,arguments)},removeMiddleware=function(e){var t=dynamic.findIndex(function(t){return t===e});-1!==t&&(dynamic=[].concat(toConsumableArray(dynamic.slice(0,t)),toConsumableArray(dynamic.slice(t+1))))},EVENTS={INITIALIZE:"analyticsInit",HANDLE_PARAMS:"params",SET_CAMPAIGN:"campaign",READY:"ready",REGISTER_INTEGRATION:"integration_init",INTEGRATION_LOADED:"integration_ready",INTEGRATION_FAILED:"integration_failed",ENABLE_INTEGRATION:"enable_integration",DISABLE_INTEGRATION:"disable_integration",PAGE_START:"page_init",PAGE:"page",PAGE_COMPLETE:"page_complete",PAGE_ABORT:"page_abort",TRACK_START:"track_init",TRACK:"track",TRACK_COMPLETE:"track_complete",TRACK_ABORT:"track_abort",IDENTIFY_START:"identify_init",IDENTIFY:"identify",IDENTIFY_COMPLETE:"identify_complete",IDENTIFY_ABORTED:"identify_abort"};function getUrlParams(t){if("undefined"==typeof window)return{};var e,n={},r=/([^&=]+)=?([^&]*)/g;if(!(t=t?(t=t.match(/\?(.*)/))&&t[1]?t[1].split("#")[0]:"":window.location.search.substring(1)))return!1;for(;e=r.exec(t);)if("-1"==e[1].indexOf("["))n[decode(e[1])]=decode(e[2]);else{var o=e[1].indexOf("["),i=e[1].slice(o+1,e[1].indexOf("]",o));o=decode(e[1].slice(0,o)),"object"!==_typeof(n[o])&&(n[decode(o)]={},n[decode(o)].length=0),i?n[decode(o)][decode(i)]=decode(e[2]):Array.prototype.push.call(n[decode(o)],decode(e[2]))}return n}function decode(t){return decodeURIComponent(t).replace(/\+/g," ")}var initialize=function(o){return function(r){return function(t){if(t.type===EVENTS.INITIALIZE){var n=getUrlParams();if(n){o.dispatch({type:EVENTS.HANDLE_PARAMS,params:n});var e=Object.keys(n).reduce(function(t,e){return e.match(/utm_/)&&(t[e]=n[e]),t},{});Object.keys(e).length&&o.dispatch({type:EVENTS.SET_CAMPAIGN,campaign:e})}}return r(t)}}};function formatPayload(t,e){var n={};return"object"===(void 0===t?"undefined":_typeof(t))?n=t:"object"===(void 0===e?"undefined":_typeof(e))&&(n=e),n}function getIntegrationWithMethod(n,r){return Object.keys(n).reduce(function(t,e){return(e=n[e])[r]?t.concat(e):t},[])}function getCallback(){for(var t=0;t<arguments.length;++t)if("function"==typeof arguments[t])return arguments[t];return!1}function trackMiddleware(r){return function(y){return function(e){return function(t){var n=t.type,a=t.eventName,c=t.data,u=t.options,s=t.callback;if(n===EVENTS.TRACK_START){var l=formatPayload(a,c),d={eventName:a,payload:l,options:u};if(t.abort)return y.dispatch(_extends({type:EVENTS.TRACK_ABORT},d)),e(t);var f=getIntegrationWithMethod(r(),"track");if(!f.length)return y.dispatch(_extends({type:EVENTS.TRACK},d)),y.dispatch(_extends({type:EVENTS.TRACK_COMPLETE},d));var p=0,E=!1;f.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT TRACK>>>>>",t.NAMESPACE,n),!e}).forEach(function(r){var o=r.NAMESPACE,i=0;!function t(){var e=y.getState(),n=_extends({},e,{options:u});if(!e.integrations[o].loaded)return 1e4<i?y.dispatch(_extends({},d,{type:"trackingTimeout"})):(i+=10,setTimeout(t,10)),!1;r.track(a,l,n),E||(y.dispatch(_extends({type:EVENTS.TRACK},d)),E=!0),y.dispatch(_extends({type:"track:"+o,integration:o},d)),(p+=1)===f.length&&((n=getCallback(c,u,s))&&n(e),y.dispatch(_extends({type:EVENTS.TRACK_COMPLETE},d)))}()})}return e(t)}}}}var inBrowser="undefined"!=typeof window,getPageData=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return inBrowser&&(t=_extends({title:document.title,url:window.location.href,path:window.location.pathname,hash:window.location.hash,search:window.location.search,width:window.innerWidth,height:window.innerHeight},t),document.referrer&&""!==document.referrer&&(t.referrer=document.referrer)),t},initialState=getPageData();function page(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:initialState,e=arguments[1];switch(e.type){case EVENTS.PAGE:return Object.assign({},t,e.data);default:return t}}var pageView=function(t,e,n){return{type:EVENTS.PAGE_START,data:t,options:e,callback:n}};function pageMiddleware(r){return function(p){return function(e){return function(t){var n=t.type,c=t.data,u=t.options,s=t.callback;if(n===EVENTS.PAGE_START){var l=getIntegrationWithMethod(r(),"page");if(!l.length)return p.dispatch({type:EVENTS.PAGE,data:getPageData(),options:u}),p.dispatch({type:EVENTS.PAGE_COMPLETE});var d=0,f=!1;l.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT PageView>>>>>",t.NAMESPACE,n),!e}).forEach(function(o){var i=o.NAMESPACE,a=0;!function t(){var e=p.getState(),n=getPageData(),r=_extends({},e,{options:u});if(!e.integrations[i].loaded)return console.log("try again",i),1e4<a?p.dispatch({type:"pageTimeout",name:i}):(a+=10,setTimeout(t,10)),!1;f||(p.dispatch({type:EVENTS.PAGE,data:n,options:u}),f=!0),o.page(n,r),p.dispatch({type:"page:"+i,data:n}),(d+=1)===l.length&&((e=getCallback(c,u,s))&&e(p),p.dispatch({type:EVENTS.PAGE_COMPLETE}))}()})}return e(t)}}}}function identifyMiddleware(r){return function(p){return function(e){return function(t){var n=t.type,a=t.userId,c=t.traits,u=t.options,s=t.callback;if(n===EVENTS.IDENTIFY_START){var l=getIntegrationWithMethod(r(),"identify");if(!l.length)return p.dispatch({type:EVENTS.IDENTIFY,userId:a,traits:c,options:u}),p.dispatch(_extends({type:EVENTS.IDENTIFY_COMPLETE}));var d=0,f=!1;l.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT Identify >>>>>",t.NAMESPACE,n),!e}).forEach(function(r){var o=r.NAMESPACE,i=0;!function t(){var e=p.getState();if(!e.integrations[o].loaded)return 1e4<i?p.dispatch({type:"identifyTimeout",name:o}):(i+=10,setTimeout(t,10)),!1;if(f||(f=!0,p.dispatch({type:EVENTS.IDENTIFY,userId:a,traits:c,options:u})),r.identify(a,c,u),p.dispatch({type:"identify:"+o}),(d+=1)===l.length){var n=getCallback(c,u,s);n&&n(e),p.dispatch({type:EVENTS.IDENTIFY_COMPLETE})}}()})}return e(t)}}}}function getBrowserOS(){if("undefined"==typeof navigator)return!1;var t=navigator.appVersion;return-1!==t.indexOf("Win")?"Windows":-1!==t.indexOf("Mac")?"MacOS":-1!==t.indexOf("X11")?"UNIX":-1!==t.indexOf("Linux")?"Linux":"Unknown OS"}var osName=void 0,initialState$1={initialized:!1,app:null,version:null,os:{name:osName=getBrowserOS()},userAgent:"undefined"!=typeof navigator?navigator.userAgent:"node",library:{name:"analytics",version:"0.0.5"},campaign:{}};function context(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:initialState$1,e=arguments[1],n=t.initialized,r=e.campaign;switch(e.type){case EVENTS.SET_CAMPAIGN:return _extends({},t,{campaign:r});default:return n?t:_extends({},initialState$1,t,{initialized:!0})}}function makeContext(n){return Object.keys(n).reduce(function(t,e){return"plugins"===e||"reducers"===e||(t[e]=n[e]),t},{})}var initialState$2={};function integrations(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:initialState$2,e=arguments[1],n={};switch(e.type){case EVENTS.REGISTER_INTEGRATION:return n[e.name]={enabled:!0,loaded:!1,config:e.integration.config},_extends({},t,n);case EVENTS.INTEGRATION_LOADED:return(n={})[e.name]=_extends({},t[e.name],{loaded:!0}),_extends({},t,n);case EVENTS.INTEGRATION_FAILED:return n[e.name]=_extends({},t[e.name],{loaded:!1}),_extends({},t,n);case EVENTS.DISABLE_INTEGRATION:return n[e.name]=_extends({},t[e.name],{enabled:!1}),_extends({},t,n);default:return t}}var initialState$3={event:{},lastEvent:null,history:[]};function trackReducer(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:initialState$3,e=arguments[1],n=e.data;switch(e.type){case EVENTS.TRACK:return e=t.lastEvent?t.event:n,console.log(">>>>>>>>>>>> state.lastEvent",t.lastEvent),_extends({},t,{event:n,lastEvent:e});default:return t}}var trackEvent=function(t,e,n,r){return{type:EVENTS.TRACK_START,eventName:t,data:e,options:n,callback:r}},uuid=function(){for(var t=[],e=0;e<256;e++)t[e]=(e<16?"0":"")+e.toString(16);e=4294967295*Math.random()|0;var n=4294967295*Math.random()|0,r=4294967295*Math.random()|0,o=4294967295*Math.random()|0;return t[255&e]+t[e>>8&255]+t[e>>16&255]+t[e>>24&255]+"-"+t[255&n]+t[n>>8&255]+"-"+t[n>>16&15|64]+t[n>>24&255]+"-"+t[63&r|128]+t[r>>8&255]+"-"+t[r>>16&255]+t[r>>24&255]+t[255&o]+t[o>>8&255]+t[o>>16&255]+t[o>>24&255]},ANALYTICS_ID="analytics_id",setId=function(){var t=uuid();return localStorage.setItem(ANALYTICS_ID,t),t},getId=function(){return localStorage.getItem(ANALYTICS_ID)},initializeId=function(){return getId()||setId()},initialState$4={userId:null,anonymousId:initializeId(),traits:{}};function user(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:initialState$4,e=arguments[1];switch(e.type){case EVENTS.IDENTIFY:return Object.assign({},t,{userId:e.userId,traits:_extends({},t.traits,e.traits)});default:return t}}var identify=function(t,e,n,r){return console.log("identify",t,e,n),{type:EVENTS.IDENTIFY_START,userId:t,traits:e,options:n,callback:r}};function analytics(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=t.plugins||[],n=t.reducers||{},o=e.reduce(function(t,e){return"function"!=typeof e&&e.NAMESPACE&&(t[e.NAMESPACE]=e),t},{}),r=function(){return o};e=e.reduce(function(t,e){return"function"==typeof e?t.concat(e):t},[]).concat([initialize,identifyMiddleware(r),trackMiddleware(r),pageMiddleware(r),dynamicMiddlewares]),r={context:context,user:user,page:page,track:trackReducer,integrations:integrations};var i=void 0;"undefined"!=typeof window&&(i=redux.compose);var a=redux.createStore(redux.combineReducers(_extends({},r,n)),{context:makeContext(t)},i(redux.applyMiddleware.apply(void 0,toConsumableArray(e))));a.dispatch({type:EVENTS.INITIALIZE});var c=Object.keys(o),u=0;return c.forEach(function(t,e){var n=o[t];if(a.dispatch({type:EVENTS.REGISTER_INTEGRATION,name:n.NAMESPACE,integration:n}),n&&n.initialize&&(n.initialize(n.config),n.loaded&&"function"==typeof n.loaded)){var r=0;!function t(){return 1e3<r?(a.dispatch({type:EVENTS.INTEGRATION_FAILED,name:n.NAMESPACE}),a.dispatch({type:"integration_failed:"+n.NAMESPACE}),!1):n.loaded()?(a.dispatch({type:EVENTS.INTEGRATION_LOADED,name:n.NAMESPACE}),a.dispatch({type:"integration_ready:"+n.NAMESPACE}),void((u+=1)===c.length&&a.dispatch({type:EVENTS.READY}))):(r++,setTimeout(t,10),!1)}()}}),c.length||setTimeout(function(){a.dispatch({type:EVENTS.READY})},0),{getState:function(t){var e=a.getState();return t?e[t]:e},dispatch:a.dispatch,subscribe:a.subscribe,replaceReducer:a.replaceReducer,track:function(t,e,n,r){return a.dispatch(trackEvent(t,e,n,r)),Promise.resolve()},page:function(t,e,n){return a.dispatch(pageView(t,e,n)),Promise.resolve()},identify:function(t,e,n,r){return a.dispatch(identify(t,e,n,r)),Promise.resolve()},user:function(){return a.getState().user},ready:function(t){var r="function"==typeof t&&t;if(!r)return!1;var e=function(n){return function(e){return function(t){return t.type===EVENTS.READY&&r(t,n),e(t)}}};return addMiddleware(e),function(){return removeMiddleware(e)}},on:function(r,t){var o="function"==typeof t&&t;if(!o)return!1;if("*"===r){var e=function(n){return function(e){return function(t){return o(t,n),e(t)}}};return addMiddleware(e),function(){removeMiddleware(e)}}var n=function(n){return function(e){return function(t){return t.type===r&&o(t,n),e(t)}}};return addMiddleware(n),function(){removeMiddleware(n)}},addIntegration:function(t){if("object"===(void 0===t?"undefined":_typeof(t))){var e={};e[t.NAMESPACE]=t,o=_extends({},o,e),console.log("add new integration dynamically",o)}a.dispatch({type:EVENTS.REGISTER_INTEGRATION,name:t.NAMESPACE,integration:t})}}}module.exports=function(t){return analytics(t)}; | ||
"use strict";var $jscomp=$jscomp||{};$jscomp.scope={},$jscomp.owns=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},$jscomp.assign="function"==typeof Object.assign?Object.assign:function(t,e){for(var n=1;n<arguments.length;n++){var r=arguments[n];if(r)for(var o in r)$jscomp.owns(r,o)&&(t[o]=r[o])}return t},$jscomp.ASSUME_ES5=!1,$jscomp.ASSUME_NO_NATIVE_MAP=!1,$jscomp.ASSUME_NO_NATIVE_SET=!1,$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(t,e,n){t!=Array.prototype&&t!=Object.prototype&&(t[e]=n.value)},$jscomp.getGlobal=function(t){return"undefined"!=typeof window&&window===t?t:"undefined"!=typeof global&&null!=global?global:t},$jscomp.global=$jscomp.getGlobal(this),$jscomp.polyfill=function(t,e,n,r){if(e){for(n=$jscomp.global,t=t.split("."),r=0;r<t.length-1;r++){var o=t[r];o in n||(n[o]={}),n=n[o]}(e=e(r=n[t=t[t.length-1]]))!=r&&null!=e&&$jscomp.defineProperty(n,t,{configurable:!0,writable:!0,value:e})}},$jscomp.polyfill("Object.assign",function(t){return t||$jscomp.assign},"es6","es3"),$jscomp.SYMBOL_PREFIX="jscomp_symbol_",$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){},$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)},$jscomp.Symbol=function(){var e=0;return function(t){return $jscomp.SYMBOL_PREFIX+(t||"")+e++}}(),$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var t=$jscomp.global.Symbol.iterator;t||(t=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator")),"function"!=typeof Array.prototype[t]&&$jscomp.defineProperty(Array.prototype,t,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}}),$jscomp.initSymbolIterator=function(){}},$jscomp.arrayIterator=function(t){var e=0;return $jscomp.iteratorPrototype(function(){return e<t.length?{done:!1,value:t[e++]}:{done:!0}})},$jscomp.iteratorPrototype=function(t){return $jscomp.initSymbolIterator(),(t={next:t})[$jscomp.global.Symbol.iterator]=function(){return this},t},$jscomp.polyfill("Array.from",function(t){return t||function(t,e,n){$jscomp.initSymbolIterator(),e=null!=e?e:function(t){return t};var r=[],o=t[Symbol.iterator];if("function"==typeof o){t=o.call(t);for(var i=0;!(o=t.next()).done;)r.push(e.call(n,o.value,i++))}else for(o=t.length,i=0;i<o;i++)r.push(e.call(n,t[i],i));return r}},"es6","es3"),$jscomp.findInternal=function(t,e,n){t instanceof String&&(t=String(t));for(var r=t.length,o=0;o<r;o++){var i=t[o];if(e.call(n,i,o,t))return{i:o,v:i}}return{i:-1,v:void 0}},$jscomp.polyfill("Array.prototype.findIndex",function(t){return t||function(t,e){return $jscomp.findInternal(this,t,e).i}},"es6","es3"),$jscomp.iteratorFromArray=function(e,n){$jscomp.initSymbolIterator(),e instanceof String&&(e+="");var r=0,o={next:function(){if(r<e.length){var t=r++;return{value:n(t,e[t]),done:!1}}return o.next=function(){return{done:!0,value:void 0}},o.next()}};return o[Symbol.iterator]=function(){return o},o},$jscomp.polyfill("Array.prototype.keys",function(t){return t||function(){return $jscomp.iteratorFromArray(this,function(t){return t})}},"es6","es3"),$jscomp.makeIterator=function(t){$jscomp.initSymbolIterator();var e=t[Symbol.iterator];return e?e.call(t):$jscomp.arrayIterator(t)},$jscomp.FORCE_POLYFILL_PROMISE=!1,$jscomp.polyfill("Promise",function(t){function e(){this.batch_=null}function c(n){return n instanceof u?n:new u(function(t,e){t(n)})}if(t&&!$jscomp.FORCE_POLYFILL_PROMISE)return t;e.prototype.asyncExecute=function(t){return null==this.batch_&&(this.batch_=[],this.asyncExecuteBatch_()),this.batch_.push(t),this},e.prototype.asyncExecuteBatch_=function(){var t=this;this.asyncExecuteFunction(function(){t.executeBatch_()})};var n=$jscomp.global.setTimeout;e.prototype.asyncExecuteFunction=function(t){n(t,0)},e.prototype.executeBatch_=function(){for(;this.batch_&&this.batch_.length;){var t=this.batch_;this.batch_=[];for(var e=0;e<t.length;++e){var n=t[e];t[e]=null;try{n()}catch(t){this.asyncThrow_(t)}}}this.batch_=null},e.prototype.asyncThrow_=function(t){this.asyncExecuteFunction(function(){throw t})};var u=function(t){this.state_=0,this.result_=void 0,this.onSettledCallbacks_=[];var e=this.createResolveAndReject_();try{t(e.resolve,e.reject)}catch(t){e.reject(t)}};u.prototype.createResolveAndReject_=function(){function t(e){return function(t){r||(r=!0,e.call(n,t))}}var n=this,r=!1;return{resolve:t(this.resolveTo_),reject:t(this.reject_)}},u.prototype.resolveTo_=function(t){if(t===this)this.reject_(new TypeError("A Promise cannot resolve to itself"));else if(t instanceof u)this.settleSameAsPromise_(t);else{t:switch(typeof t){case"object":var e=null!=t;break t;case"function":e=!0;break t;default:e=!1}e?this.resolveToNonPromiseObj_(t):this.fulfill_(t)}},u.prototype.resolveToNonPromiseObj_=function(t){var e=void 0;try{e=t.then}catch(t){return void this.reject_(t)}"function"==typeof e?this.settleSameAsThenable_(e,t):this.fulfill_(t)},u.prototype.reject_=function(t){this.settle_(2,t)},u.prototype.fulfill_=function(t){this.settle_(1,t)},u.prototype.settle_=function(t,e){if(0!=this.state_)throw Error("Cannot settle("+t+", "+e+"): Promise already settled in state"+this.state_);this.state_=t,this.result_=e,this.executeOnSettledCallbacks_()},u.prototype.executeOnSettledCallbacks_=function(){if(null!=this.onSettledCallbacks_){for(var t=0;t<this.onSettledCallbacks_.length;++t)o.asyncExecute(this.onSettledCallbacks_[t]);this.onSettledCallbacks_=null}};var o=new e;return u.prototype.settleSameAsPromise_=function(t){var e=this.createResolveAndReject_();t.callWhenSettled_(e.resolve,e.reject)},u.prototype.settleSameAsThenable_=function(t,e){var n=this.createResolveAndReject_();try{t.call(e,n.resolve,n.reject)}catch(t){n.reject(t)}},u.prototype.then=function(t,e){function n(e,t){return"function"==typeof e?function(t){try{r(e(t))}catch(t){o(t)}}:t}var r,o,i=new u(function(t,e){r=t,o=e});return this.callWhenSettled_(n(t,r),n(e,o)),i},u.prototype.catch=function(t){return this.then(void 0,t)},u.prototype.callWhenSettled_=function(t,e){function n(){switch(r.state_){case 1:t(r.result_);break;case 2:e(r.result_);break;default:throw Error("Unexpected state: "+r.state_)}}var r=this;null==this.onSettledCallbacks_?o.asyncExecute(n):this.onSettledCallbacks_.push(n)},u.resolve=c,u.reject=function(n){return new u(function(t,e){e(n)})},u.race=function(o){return new u(function(t,e){for(var n=$jscomp.makeIterator(o),r=n.next();!r.done;r=n.next())c(r.value).callWhenSettled_(t,e)})},u.all=function(t){var i=$jscomp.makeIterator(t),a=i.next();return a.done?c([]):new u(function(n,t){function e(e){return function(t){r[e]=t,0==--o&&n(r)}}for(var r=[],o=0;r.push(void 0),o++,c(a.value).callWhenSettled_(e(r.length-1),t),!(a=i.next()).done;);})},u},"es6","es3");var redux=require("redux"),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n,r=arguments[e];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},toConsumableArray=function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)},dynamic=[],dynamicMiddlewares=function(o){return function(r){return function(t){var e={getState:o.getState,dispatch:function(t){return o.dispatch(t)}},n=dynamic.map(function(t){return t(e)});return redux.compose.apply(void 0,toConsumableArray(n))(r)(t)}}},addMiddleware=function(){var t;dynamic=(t=dynamic).concat.apply(t,arguments)},removeMiddleware=function(e){var t=dynamic.findIndex(function(t){return t===e});-1!==t&&(dynamic=[].concat(toConsumableArray(dynamic.slice(0,t)),toConsumableArray(dynamic.slice(t+1))))},EVENTS={INITIALIZE:"analyticsInit",HANDLE_PARAMS:"params",SET_CAMPAIGN:"campaign",READY:"ready",REGISTER_INTEGRATION:"integration_init",INTEGRATION_LOADED:"integration_ready",INTEGRATION_FAILED:"integration_failed",ENABLE_INTEGRATION:"enable_integration",DISABLE_INTEGRATION:"disable_integration",PAGE_START:"page_init",PAGE:"page",PAGE_COMPLETE:"page_complete",PAGE_ABORT:"page_abort",TRACK_START:"track_init",TRACK:"track",TRACK_COMPLETE:"track_complete",TRACK_ABORT:"track_abort",IDENTIFY_START:"identify_init",IDENTIFY:"identify",IDENTIFY_COMPLETE:"identify_complete",IDENTIFY_ABORTED:"identify_abort"};function getUrlParams(t){if("undefined"==typeof window)return{};var e,n={},r=/([^&=]+)=?([^&]*)/g;if(!(t=t?(t=t.match(/\?(.*)/))&&t[1]?t[1].split("#")[0]:"":window.location.search.substring(1)))return!1;for(;e=r.exec(t);)if("-1"==e[1].indexOf("["))n[decode(e[1])]=decode(e[2]);else{var o=e[1].indexOf("["),i=e[1].slice(o+1,e[1].indexOf("]",o));o=decode(e[1].slice(0,o)),"object"!==_typeof(n[o])&&(n[decode(o)]={},n[decode(o)].length=0),i?n[decode(o)][decode(i)]=decode(e[2]):Array.prototype.push.call(n[decode(o)],decode(e[2]))}return n}function decode(t){return decodeURIComponent(t).replace(/\+/g," ")}var initialize=function(o){return function(r){return function(t){if(t.type===EVENTS.INITIALIZE){var n=getUrlParams();if(n){o.dispatch({type:EVENTS.HANDLE_PARAMS,params:n});var e=Object.keys(n).reduce(function(t,e){return e.match(/utm_/)&&(t[e]=n[e]),t},{});Object.keys(e).length&&o.dispatch({type:EVENTS.SET_CAMPAIGN,campaign:e})}}return r(t)}}};function formatPayload(t,e){var n={};return"object"===(void 0===t?"undefined":_typeof(t))?n=t:"object"===(void 0===e?"undefined":_typeof(e))&&(n=e),n}function getIntegrationWithMethod(n,r){return Object.keys(n).reduce(function(t,e){return(e=n[e])[r]?t.concat(e):t},[])}function getCallback(){for(var t=0;t<arguments.length;++t)if("function"==typeof arguments[t])return arguments[t];return!1}function trackMiddleware(r){return function(E){return function(e){return function(t){var n=t.type,a=t.eventName,c=t.data,u=t.options,s=t.callback;if(n===EVENTS.TRACK_START){var l=formatPayload(a,c),d={eventName:a,payload:l,options:u};if(t.abort)return E.dispatch(_extends({type:EVENTS.TRACK_ABORT},d)),e(t);var f=getIntegrationWithMethod(r(),"track");if(!f.length)return E.dispatch(_extends({type:EVENTS.TRACK},d)),E.dispatch(_extends({type:EVENTS.TRACK_COMPLETE},d));var p=0,y=!1;f.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT TRACK>>>>>",t.NAMESPACE,n),!e}).forEach(function(r){var o=r.NAMESPACE,i=0;!function t(){var e=E.getState(),n=_extends({},e,{options:u});if(!e.integrations[o].loaded)return 1e4<i?E.dispatch(_extends({},d,{type:"trackingTimeout"})):(i+=10,setTimeout(t,10)),!1;r.track(a,l,n),y||(E.dispatch(_extends({type:EVENTS.TRACK},d)),y=!0),E.dispatch(_extends({type:"track:"+o,integration:o},d)),(p+=1)===f.length&&((n=getCallback(c,u,s))&&n(e),E.dispatch(_extends({type:EVENTS.TRACK_COMPLETE},d)))}()})}return e(t)}}}}var inBrowser="undefined"!=typeof window,getPageData=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return inBrowser&&(t=_extends({title:document.title,url:window.location.href,path:window.location.pathname,hash:window.location.hash,search:window.location.search,width:window.innerWidth,height:window.innerHeight},t),document.referrer&&""!==document.referrer&&(t.referrer=document.referrer)),t},initialState=getPageData();function page(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:initialState,e=arguments[1];switch(e.type){case EVENTS.PAGE:return Object.assign({},t,e.data);default:return t}}var pageView=function(t,e,n){return{type:EVENTS.PAGE_START,data:t,options:e,callback:n}};function pageMiddleware(r){return function(p){return function(e){return function(t){var n=t.type,c=t.data,u=t.options,s=t.callback;if(n===EVENTS.PAGE_START){var l=getIntegrationWithMethod(r(),"page");if(!l.length)return p.dispatch({type:EVENTS.PAGE,data:getPageData(),options:u}),p.dispatch({type:EVENTS.PAGE_COMPLETE});var d=0,f=!1;l.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT PageView>>>>>",t.NAMESPACE,n),!e}).forEach(function(o){var i=o.NAMESPACE,a=0;!function t(){var e=p.getState(),n=getPageData(),r=_extends({},e,{options:u});if(!e.integrations[i].loaded)return console.log("try again",i),1e4<a?p.dispatch({type:"pageTimeout",name:i}):(a+=10,setTimeout(t,10)),!1;f||(p.dispatch({type:EVENTS.PAGE,data:n,options:u}),f=!0),o.page(n,r),p.dispatch({type:"page:"+i,data:n}),(d+=1)===l.length&&((e=getCallback(c,u,s))&&e(p),p.dispatch({type:EVENTS.PAGE_COMPLETE}))}()})}return e(t)}}}}function identifyMiddleware(r){return function(p){return function(e){return function(t){var n=t.type,a=t.userId,c=t.traits,u=t.options,s=t.callback;if(n===EVENTS.IDENTIFY_START){var l=getIntegrationWithMethod(r(),"identify");if(!l.length)return p.dispatch({type:EVENTS.IDENTIFY,userId:a,traits:c,options:u}),p.dispatch(_extends({type:EVENTS.IDENTIFY_COMPLETE}));var d=0,f=!1;l.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT Identify >>>>>",t.NAMESPACE,n),!e}).forEach(function(r){var o=r.NAMESPACE,i=0;!function t(){var e=p.getState();if(!e.integrations[o].loaded)return 1e4<i?p.dispatch({type:"identifyTimeout",name:o}):(i+=10,setTimeout(t,10)),!1;if(f||(f=!0,p.dispatch({type:EVENTS.IDENTIFY,userId:a,traits:c,options:u})),r.identify(a,c,u),p.dispatch({type:"identify:"+o}),(d+=1)===l.length){var n=getCallback(c,u,s);n&&n(e),p.dispatch({type:EVENTS.IDENTIFY_COMPLETE})}}()})}return e(t)}}}}function getBrowserOS(){if("undefined"==typeof navigator)return!1;var t=navigator.appVersion;return-1!==t.indexOf("Win")?"Windows":-1!==t.indexOf("Mac")?"MacOS":-1!==t.indexOf("X11")?"UNIX":-1!==t.indexOf("Linux")?"Linux":"Unknown OS"}var osName=void 0,initialState$1={initialized:!1,app:null,version:null,os:{name:osName=getBrowserOS()},userAgent:"undefined"!=typeof navigator?navigator.userAgent:"node",library:{name:"analytics",version:"0.0.6"},campaign:{}};function context(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:initialState$1,e=arguments[1],n=t.initialized,r=e.campaign;switch(e.type){case EVENTS.SET_CAMPAIGN:return _extends({},t,{campaign:r});default:return n?t:_extends({},initialState$1,t,{initialized:!0})}}function makeContext(n){return Object.keys(n).reduce(function(t,e){return"plugins"===e||"reducers"===e||(t[e]=n[e]),t},{})}var initialState$2={};function integrations(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:initialState$2,e=arguments[1],n={};switch(e.type){case EVENTS.REGISTER_INTEGRATION:return n[e.name]={enabled:!0,loaded:!1,config:e.integration.config},_extends({},t,n);case EVENTS.INTEGRATION_LOADED:return(n={})[e.name]=_extends({},t[e.name],{loaded:!0}),_extends({},t,n);case EVENTS.INTEGRATION_FAILED:return n[e.name]=_extends({},t[e.name],{loaded:!1}),_extends({},t,n);case EVENTS.DISABLE_INTEGRATION:return n[e.name]=_extends({},t[e.name],{enabled:!1}),_extends({},t,n);default:return t}}var initialState$3={event:{},lastEvent:null,history:[]};function trackReducer(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:initialState$3,e=arguments[1],n=e.data;switch(e.type){case EVENTS.TRACK:return e=t.lastEvent?t.event:n,console.log(">>>>>>>>>>>> state.lastEvent",t.lastEvent),_extends({},t,{event:n,lastEvent:e});default:return t}}var trackEvent=function(t,e,n,r){return{type:EVENTS.TRACK_START,eventName:t,data:e,options:n,callback:r}},uuid=function(){for(var t=[],e=0;e<256;e++)t[e]=(e<16?"0":"")+e.toString(16);e=4294967295*Math.random()|0;var n=4294967295*Math.random()|0,r=4294967295*Math.random()|0,o=4294967295*Math.random()|0;return t[255&e]+t[e>>8&255]+t[e>>16&255]+t[e>>24&255]+"-"+t[255&n]+t[n>>8&255]+"-"+t[n>>16&15|64]+t[n>>24&255]+"-"+t[63&r|128]+t[r>>8&255]+"-"+t[r>>16&255]+t[r>>24&255]+t[255&o]+t[o>>8&255]+t[o>>16&255]+t[o>>24&255]},ANALYTICS_ID="analytics_id",inBrowser$1="undefined"!=typeof window,setId=function(){var t=uuid();return inBrowser$1&&localStorage.setItem(ANALYTICS_ID,t),t},getId=function(){return inBrowser$1?localStorage.getItem(ANALYTICS_ID):null},initializeId=function(){return getId()||setId()},initialState$4={userId:null,anonymousId:initializeId(),traits:{}};function user(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:initialState$4,e=arguments[1];switch(e.type){case EVENTS.IDENTIFY:return Object.assign({},t,{userId:e.userId,traits:_extends({},t.traits,e.traits)});default:return t}}var identify=function(t,e,n,r){return console.log("identify",t,e,n),{type:EVENTS.IDENTIFY_START,userId:t,traits:e,options:n,callback:r}};function analytics(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=t.plugins||[],n=t.reducers||{},o=e.reduce(function(t,e){return"function"!=typeof e&&e.NAMESPACE&&(t[e.NAMESPACE]=e),t},{}),r=function(){return o};e=e.reduce(function(t,e){return"function"==typeof e?t.concat(e):t},[]).concat([initialize,identifyMiddleware(r),trackMiddleware(r),pageMiddleware(r),dynamicMiddlewares]),r={context:context,user:user,page:page,track:trackReducer,integrations:integrations};var i=redux.compose;"undefined"!=typeof window&&(i=redux.compose);var a=redux.createStore(redux.combineReducers(_extends({},r,n)),{context:makeContext(t)},i(redux.applyMiddleware.apply(void 0,toConsumableArray(e))));a.dispatch({type:EVENTS.INITIALIZE});var c=Object.keys(o),u=0;return c.forEach(function(t,e){var n=o[t];if(a.dispatch({type:EVENTS.REGISTER_INTEGRATION,name:n.NAMESPACE,integration:n}),n&&n.initialize&&(n.initialize(n.config),n.loaded&&"function"==typeof n.loaded)){var r=0;!function t(){return 1e3<r?(a.dispatch({type:EVENTS.INTEGRATION_FAILED,name:n.NAMESPACE}),a.dispatch({type:"integration_failed:"+n.NAMESPACE}),!1):n.loaded()?(a.dispatch({type:EVENTS.INTEGRATION_LOADED,name:n.NAMESPACE}),a.dispatch({type:"integration_ready:"+n.NAMESPACE}),void((u+=1)===c.length&&a.dispatch({type:EVENTS.READY}))):(r++,setTimeout(t,10),!1)}()}}),c.length||setTimeout(function(){a.dispatch({type:EVENTS.READY})},0),{getState:function(t){var e=a.getState();return t?e[t]:e},dispatch:a.dispatch,subscribe:a.subscribe,replaceReducer:a.replaceReducer,track:function(t,e,n,r){return a.dispatch(trackEvent(t,e,n,r)),Promise.resolve()},page:function(t,e,n){return a.dispatch(pageView(t,e,n)),Promise.resolve()},identify:function(t,e,n,r){return a.dispatch(identify(t,e,n,r)),Promise.resolve()},user:function(){return a.getState().user},ready:function(t){var r="function"==typeof t&&t;if(!r)return!1;var e=function(n){return function(e){return function(t){return t.type===EVENTS.READY&&r(t,n),e(t)}}};return addMiddleware(e),function(){return removeMiddleware(e)}},on:function(r,t){var o="function"==typeof t&&t;if(!o)return!1;if("*"===r){var e=function(n){return function(e){return function(t){return o(t,n),e(t)}}};return addMiddleware(e),function(){removeMiddleware(e)}}var n=function(n){return function(e){return function(t){return t.type===r&&o(t,n),e(t)}}};return addMiddleware(n),function(){removeMiddleware(n)}},addIntegration:function(t){if("object"===(void 0===t?"undefined":_typeof(t))){var e={};e[t.NAMESPACE]=t,o=_extends({},o,e),console.log("add new integration dynamically",o)}a.dispatch({type:EVENTS.REGISTER_INTEGRATION,name:t.NAMESPACE,integration:t})}}}module.exports=function(t){return analytics(t)}; |
@@ -606,3 +606,3 @@ import { compose, createStore, combineReducers, applyMiddleware } from 'redux'; | ||
name: 'analytics', | ||
version: "0.0.5" | ||
version: "0.0.6" | ||
}, | ||
@@ -737,5 +737,10 @@ campaign: {} | ||
var ANALYTICS_ID = 'analytics_id'; | ||
var inBrowser$1 = typeof window !== 'undefined'; | ||
var setId = function setId() { | ||
var id = uuid(); | ||
if (!inBrowser$1) { | ||
return id; | ||
} | ||
// TODO refactor with persistance options https://github.com/harrysolovay/state-mint/tree/master/src/persistence/methods | ||
localStorage.setItem(ANALYTICS_ID, id); | ||
@@ -746,2 +751,5 @@ return id; | ||
var getId = function getId() { | ||
if (!inBrowser$1) { | ||
return null; | ||
} | ||
return localStorage.getItem(ANALYTICS_ID); | ||
@@ -869,3 +877,3 @@ }; | ||
var composeEnhancers = void 0; | ||
var composeEnhancers = compose; | ||
if (typeof window !== 'undefined') { | ||
@@ -872,0 +880,0 @@ var withDevTools = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; |
@@ -1,1 +0,1 @@ | ||
"use strict";var $jscomp=$jscomp||{};$jscomp.scope={},$jscomp.ASSUME_ES5=!1,$jscomp.ASSUME_NO_NATIVE_MAP=!1,$jscomp.ASSUME_NO_NATIVE_SET=!1,$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(t,e,n){t!=Array.prototype&&t!=Object.prototype&&(t[e]=n.value)},$jscomp.getGlobal=function(t){return"undefined"!=typeof window&&window===t?t:"undefined"!=typeof global&&null!=global?global:t},$jscomp.global=$jscomp.getGlobal(this),$jscomp.SYMBOL_PREFIX="jscomp_symbol_",$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){},$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)},$jscomp.Symbol=function(){var e=0;return function(t){return $jscomp.SYMBOL_PREFIX+(t||"")+e++}}(),$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var t=$jscomp.global.Symbol.iterator;t||(t=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator")),"function"!=typeof Array.prototype[t]&&$jscomp.defineProperty(Array.prototype,t,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}}),$jscomp.initSymbolIterator=function(){}},$jscomp.arrayIterator=function(t){var e=0;return $jscomp.iteratorPrototype(function(){return e<t.length?{done:!1,value:t[e++]}:{done:!0}})},$jscomp.iteratorPrototype=function(t){return $jscomp.initSymbolIterator(),(t={next:t})[$jscomp.global.Symbol.iterator]=function(){return this},t},$jscomp.iteratorFromArray=function(e,n){$jscomp.initSymbolIterator(),e instanceof String&&(e+="");var r=0,o={next:function(){if(r<e.length){var t=r++;return{value:n(t,e[t]),done:!1}}return o.next=function(){return{done:!0,value:void 0}},o.next()}};return o[Symbol.iterator]=function(){return o},o},$jscomp.polyfill=function(t,e,n,r){if(e){for(n=$jscomp.global,t=t.split("."),r=0;r<t.length-1;r++){var o=t[r];o in n||(n[o]={}),n=n[o]}(e=e(r=n[t=t[t.length-1]]))!=r&&null!=e&&$jscomp.defineProperty(n,t,{configurable:!0,writable:!0,value:e})}},$jscomp.polyfill("Array.prototype.keys",function(t){return t||function(){return $jscomp.iteratorFromArray(this,function(t){return t})}},"es6","es3"),$jscomp.owns=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},$jscomp.assign="function"==typeof Object.assign?Object.assign:function(t,e){for(var n=1;n<arguments.length;n++){var r=arguments[n];if(r)for(var o in r)$jscomp.owns(r,o)&&(t[o]=r[o])}return t},$jscomp.polyfill("Object.assign",function(t){return t||$jscomp.assign},"es6","es3"),$jscomp.polyfill("Array.from",function(t){return t||function(t,e,n){$jscomp.initSymbolIterator(),e=null!=e?e:function(t){return t};var r=[],o=t[Symbol.iterator];if("function"==typeof o){t=o.call(t);for(var i=0;!(o=t.next()).done;)r.push(e.call(n,o.value,i++))}else for(o=t.length,i=0;i<o;i++)r.push(e.call(n,t[i],i));return r}},"es6","es3"),$jscomp.findInternal=function(t,e,n){t instanceof String&&(t=String(t));for(var r=t.length,o=0;o<r;o++){var i=t[o];if(e.call(n,i,o,t))return{i:o,v:i}}return{i:-1,v:void 0}},$jscomp.polyfill("Array.prototype.findIndex",function(t){return t||function(t,e){return $jscomp.findInternal(this,t,e).i}},"es6","es3"),$jscomp.makeIterator=function(t){$jscomp.initSymbolIterator();var e=t[Symbol.iterator];return e?e.call(t):$jscomp.arrayIterator(t)},$jscomp.FORCE_POLYFILL_PROMISE=!1,$jscomp.polyfill("Promise",function(t){function e(){this.batch_=null}function c(n){return n instanceof u?n:new u(function(t,e){t(n)})}if(t&&!$jscomp.FORCE_POLYFILL_PROMISE)return t;e.prototype.asyncExecute=function(t){return null==this.batch_&&(this.batch_=[],this.asyncExecuteBatch_()),this.batch_.push(t),this},e.prototype.asyncExecuteBatch_=function(){var t=this;this.asyncExecuteFunction(function(){t.executeBatch_()})};var n=$jscomp.global.setTimeout;e.prototype.asyncExecuteFunction=function(t){n(t,0)},e.prototype.executeBatch_=function(){for(;this.batch_&&this.batch_.length;){var t=this.batch_;this.batch_=[];for(var e=0;e<t.length;++e){var n=t[e];t[e]=null;try{n()}catch(t){this.asyncThrow_(t)}}}this.batch_=null},e.prototype.asyncThrow_=function(t){this.asyncExecuteFunction(function(){throw t})};var u=function(t){this.state_=0,this.result_=void 0,this.onSettledCallbacks_=[];var e=this.createResolveAndReject_();try{t(e.resolve,e.reject)}catch(t){e.reject(t)}};u.prototype.createResolveAndReject_=function(){function t(e){return function(t){r||(r=!0,e.call(n,t))}}var n=this,r=!1;return{resolve:t(this.resolveTo_),reject:t(this.reject_)}},u.prototype.resolveTo_=function(t){if(t===this)this.reject_(new TypeError("A Promise cannot resolve to itself"));else if(t instanceof u)this.settleSameAsPromise_(t);else{t:switch(typeof t){case"object":var e=null!=t;break t;case"function":e=!0;break t;default:e=!1}e?this.resolveToNonPromiseObj_(t):this.fulfill_(t)}},u.prototype.resolveToNonPromiseObj_=function(t){var e=void 0;try{e=t.then}catch(t){return void this.reject_(t)}"function"==typeof e?this.settleSameAsThenable_(e,t):this.fulfill_(t)},u.prototype.reject_=function(t){this.settle_(2,t)},u.prototype.fulfill_=function(t){this.settle_(1,t)},u.prototype.settle_=function(t,e){if(0!=this.state_)throw Error("Cannot settle("+t+", "+e+"): Promise already settled in state"+this.state_);this.state_=t,this.result_=e,this.executeOnSettledCallbacks_()},u.prototype.executeOnSettledCallbacks_=function(){if(null!=this.onSettledCallbacks_){for(var t=0;t<this.onSettledCallbacks_.length;++t)o.asyncExecute(this.onSettledCallbacks_[t]);this.onSettledCallbacks_=null}};var o=new e;return u.prototype.settleSameAsPromise_=function(t){var e=this.createResolveAndReject_();t.callWhenSettled_(e.resolve,e.reject)},u.prototype.settleSameAsThenable_=function(t,e){var n=this.createResolveAndReject_();try{t.call(e,n.resolve,n.reject)}catch(t){n.reject(t)}},u.prototype.then=function(t,e){function n(e,t){return"function"==typeof e?function(t){try{r(e(t))}catch(t){o(t)}}:t}var r,o,i=new u(function(t,e){r=t,o=e});return this.callWhenSettled_(n(t,r),n(e,o)),i},u.prototype.catch=function(t){return this.then(void 0,t)},u.prototype.callWhenSettled_=function(t,e){function n(){switch(r.state_){case 1:t(r.result_);break;case 2:e(r.result_);break;default:throw Error("Unexpected state: "+r.state_)}}var r=this;null==this.onSettledCallbacks_?o.asyncExecute(n):this.onSettledCallbacks_.push(n)},u.resolve=c,u.reject=function(n){return new u(function(t,e){e(n)})},u.race=function(o){return new u(function(t,e){for(var n=$jscomp.makeIterator(o),r=n.next();!r.done;r=n.next())c(r.value).callWhenSettled_(t,e)})},u.all=function(t){var i=$jscomp.makeIterator(t),a=i.next();return a.done?c([]):new u(function(n,t){function e(e){return function(t){r[e]=t,0==--o&&n(r)}}for(var r=[],o=0;r.push(void 0),o++,c(a.value).callWhenSettled_(e(r.length-1),t),!(a=i.next()).done;);})},u},"es6","es3"),function(){function p(t,e,n){function r(e){if("function"!=typeof e)throw Error("Expected listener to be a function.");var n=!0;return s===u&&(s=u.slice()),s.push(e),function(){if(n){n=!1,s===u&&(s=u.slice());var t=s.indexOf(e);s.splice(t,1)}}}function o(t){var e;if(e=null!=t&&"object"==typeof t){if(null==t)e=void 0===t?"[object Undefined]":"[object Null]";else if(S&&S in Object(t)){e=f.call(t,I);var n=t[I];try{t[I]=void 0}catch(t){}var r=T.call(t);e?t[I]=n:delete t[I],e=r}else e=j.call(t);e="[object Object]"==e}if(!(e=!!e&&(null===(e=O(t))||"function"==typeof(e=R.call(e,"constructor")&&e.constructor)&&e instanceof e&&N.call(e)==w)))throw Error("Actions must be plain objects. Use custom middleware for async actions.");if(void 0===t.type)throw Error('Actions may not have an undefined "type" property. Have you misspelled a constant?');if(l)throw Error("Reducers may not dispatch actions.");try{l=!0,c=a(c,t)}finally{l=!1}for(e=u=s,n=0;n<e.length;n++)e[n]();return t}var i;if("function"==typeof e&&void 0===n&&(n=e,e=void 0),void 0!==n){if("function"!=typeof n)throw Error("Expected the enhancer to be a function.");return n(p)(t,e)}if("function"!=typeof t)throw Error("Expected the reducer to be a function.");var a=t,c=e,u=[],s=u,l=!1;return o({type:$.INIT}),(i={dispatch:o,subscribe:r,getState:function(){return c},replaceReducer:function(t){if("function"!=typeof t)throw Error("Expected the nextReducer to be a function.");a=t,o({type:$.INIT})}})[P]=function(){var t;return(t={subscribe:function(t){function e(){t.next&&t.next(c)}if("object"!=typeof t)throw new TypeError("Expected the observer to be an object.");return e(),{unsubscribe:r(e)}}})[P]=function(){return this},t},i}function d(t){for(var e=Object.keys(t),u={},n=0;n<e.length;n++){var r=e[n];"function"==typeof t[r]&&(u[r]=t[r])}var o,s=Object.keys(u);try{o=u,Object.keys(o).forEach(function(t){var e=o[t];if(void 0===e(void 0,{type:$.INIT}))throw Error('Reducer "'+t+'" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined.');if(void 0===e(void 0,{type:"@@redux/PROBE_UNKNOWN_ACTION_"+Math.random().toString(36).substring(7).split("").join(".")}))throw Error('Reducer "'+t+"\" returned undefined when probed with a random type. Don't try to handle "+$.INIT+' or other actions in "redux/*" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined.')})}catch(t){var l=t}return function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=arguments[1];if(l)throw l;for(var n=!1,r={},o=0;o<s.length;o++){var i=s[o],a=t[i],c=(0,u[i])(a,e);if(void 0===c)throw t=e&&e.type,Error("Given action "+(t&&'"'+t.toString()+'"'||"an action")+', reducer "'+i+'" returned undefined. To ignore an action, you must explicitly return the previous state.');r[i]=c,n=n||c!==a}return n?r:t}}function y(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];if(0===e.length)return function(t){return t};if(1===e.length)return e[0];var r=e[e.length-1],o=e.slice(0,-1);return function(){return o.reduceRight(function(t,e){return e(t)},r.apply(void 0,arguments))}}function a(t){return decodeURIComponent(t).replace(/\+/g," ")}function m(n,r){return Object.keys(n).reduce(function(t,e){return(e=n[e])[r]?t.concat(e):t},[])}function b(){for(var t=0;t<arguments.length;++t)if("function"==typeof arguments[t])return arguments[t];return!1}function h(v){return function(h){return function(i){return function(t){var e,n,r,o=t.type,a=t.eventName,c=t.data,u=t.options,s=t.callback;if(o===F.TRACK_START){var l=(n=c,r={},"object"===(void 0===(e=a)?"undefined":x(e))?r=e:"object"===(void 0===n?"undefined":x(n))&&(r=n),r),f={eventName:a,payload:l,options:u};if(t.abort)return h.dispatch(M({type:F.TRACK_ABORT},f)),i(t);var p=m(v(),"track");if(!p.length)return h.dispatch(M({type:F.TRACK},f)),h.dispatch(M({type:F.TRACK_COMPLETE},f));var d=0,y=!1;p.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT TRACK>>>>>",t.NAMESPACE,o),!e}).forEach(function(r){var o=r.NAMESPACE,i=0;!function t(){var e=h.getState(),n=M({},e,{options:u});if(!e.integrations[o].loaded)return 1e4<i?h.dispatch(M({},f,{type:"trackingTimeout"})):(i+=10,setTimeout(t,10)),!1;r.track(a,l,n),y||(h.dispatch(M({type:F.TRACK},f)),y=!0),h.dispatch(M({type:"track:"+o,integration:o},f)),(d+=1)===p.length&&((n=b(c,u,s))&&n(e),h.dispatch(M({type:F.TRACK_COMPLETE},f)))}()})}return i(t)}}}}function v(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:l,e=arguments[1];switch(e.type){case F.PAGE:return Object.assign({},t,e.data);default:return t}}function E(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:K,e=arguments[1],n=t.initialized,r=e.campaign;switch(e.type){case F.SET_CAMPAIGN:return M({},t,{campaign:r});default:return n?t:M({},K,t,{initialized:!0})}}function g(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:U,e=arguments[1],n={};switch(e.type){case F.REGISTER_INTEGRATION:return n[e.name]={enabled:!0,loaded:!1,config:e.integration.config},M({},t,n);case F.INTEGRATION_LOADED:return(n={})[e.name]=M({},t[e.name],{loaded:!0}),M({},t,n);case F.INTEGRATION_FAILED:return n[e.name]=M({},t[e.name],{loaded:!1}),M({},t,n);case F.DISABLE_INTEGRATION:return n[e.name]=M({},t[e.name],{enabled:!1}),M({},t,n);default:return t}}function A(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:W,e=arguments[1],n=e.data;switch(e.type){case F.TRACK:return e=t.lastEvent?t.event:n,console.log(">>>>>>>>>>>> state.lastEvent",t.lastEvent),M({},t,{event:n,lastEvent:e});default:return t}}function _(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:z,e=arguments[1];switch(e.type){case F.IDENTIFY:return Object.assign({},t,{userId:e.userId,traits:M({},t.traits,e.traits)});default:return t}}function e(){var r,o,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=t.plugins||[],n=t.reducers||{},i=e.reduce(function(t,e){return"function"!=typeof e&&e.NAMESPACE&&(t[e.NAMESPACE]=e),t},{}),a=function(){return i};e=e.reduce(function(t,e){return"function"==typeof e?t.concat(e):t},[]).concat([Y,(o=a,function(d){return function(e){return function(t){var n=t.type,a=t.userId,c=t.traits,u=t.options,s=t.callback;if(n===F.IDENTIFY_START){var l=m(o(),"identify");if(!l.length)return d.dispatch({type:F.IDENTIFY,userId:a,traits:c,options:u}),d.dispatch(M({type:F.IDENTIFY_COMPLETE}));var f=0,p=!1;l.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT Identify >>>>>",t.NAMESPACE,n),!e}).forEach(function(r){var o=r.NAMESPACE,i=0;!function t(){var e=d.getState();if(!e.integrations[o].loaded)return 1e4<i?d.dispatch({type:"identifyTimeout",name:o}):(i+=10,setTimeout(t,10)),!1;if(p||(p=!0,d.dispatch({type:F.IDENTIFY,userId:a,traits:c,options:u})),r.identify(a,c,u),d.dispatch({type:"identify:"+o}),(f+=1)===l.length){var n=b(c,u,s);n&&n(e),d.dispatch({type:F.IDENTIFY_COMPLETE})}}()})}return e(t)}}}),h(a),(r=a,function(d){return function(e){return function(t){var n=t.type,c=t.data,u=t.options,s=t.callback;if(n===F.PAGE_START){var l=m(r(),"page");if(!l.length)return d.dispatch({type:F.PAGE,data:B(),options:u}),d.dispatch({type:F.PAGE_COMPLETE});var f=0,p=!1;l.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT PageView>>>>>",t.NAMESPACE,n),!e}).forEach(function(o){var i=o.NAMESPACE,a=0;!function t(){var e=d.getState(),n=B(),r=M({},e,{options:u});if(!e.integrations[i].loaded)return console.log("try again",i),1e4<a?d.dispatch({type:"pageTimeout",name:i}):(a+=10,setTimeout(t,10)),!1;p||(d.dispatch({type:F.PAGE,data:n,options:u}),p=!0),o.page(n,r),d.dispatch({type:"page:"+i,data:n}),(f+=1)===l.length&&((e=b(c,u,s))&&e(d),d.dispatch({type:F.PAGE_COMPLETE}))}()})}return e(t)}}}),G]),a={context:E,user:_,page:v,track:A,integrations:g};var c=void 0;"undefined"!=typeof window&&(c=y);var u,s=p(d(M({},a,n)),{context:(u=t,Object.keys(u).reduce(function(t,e){return"plugins"===e||"reducers"===e||(t[e]=u[e]),t},{}))},c(function(){for(var t=arguments.length,a=Array(t),e=0;e<t;e++)a[e]=arguments[e];return function(i){return function(t,e,n){var r=(t=i(t,e,n)).dispatch;e=[];var o={getState:t.getState,dispatch:function(t){return r(t)}};return e=a.map(function(t){return t(o)}),r=y.apply(void 0,e)(t.dispatch),C({},t,{dispatch:r})}}}.apply(void 0,k(e))));s.dispatch({type:F.INITIALIZE});var l=Object.keys(i),f=0;return l.forEach(function(t,e){var n=i[t];if(s.dispatch({type:F.REGISTER_INTEGRATION,name:n.NAMESPACE,integration:n}),n&&n.initialize&&(n.initialize(n.config),n.loaded&&"function"==typeof n.loaded)){var r=0;!function t(){return 1e3<r?(s.dispatch({type:F.INTEGRATION_FAILED,name:n.NAMESPACE}),s.dispatch({type:"integration_failed:"+n.NAMESPACE}),!1):n.loaded()?(s.dispatch({type:F.INTEGRATION_LOADED,name:n.NAMESPACE}),s.dispatch({type:"integration_ready:"+n.NAMESPACE}),void((f+=1)===l.length&&s.dispatch({type:F.READY}))):(r++,setTimeout(t,10),!1)}()}}),l.length||setTimeout(function(){s.dispatch({type:F.READY})},0),{getState:function(t){var e=s.getState();return t?e[t]:e},dispatch:s.dispatch,subscribe:s.subscribe,replaceReducer:s.replaceReducer,track:function(t,e,n,r){return s.dispatch({type:F.TRACK_START,eventName:t,data:e,options:n,callback:r}),Promise.resolve()},page:function(t,e,n){return s.dispatch({type:F.PAGE_START,data:t,options:e,callback:n}),Promise.resolve()},identify:function(t,e,n,r){var o,i,a,c;return s.dispatch((o=t,i=e,a=n,c=r,console.log("identify",o,i,a),{type:F.IDENTIFY_START,userId:o,traits:i,options:a,callback:c})),Promise.resolve()},user:function(){return s.getState().user},ready:function(t){var r="function"==typeof t&&t;if(!r)return!1;var e=function(n){return function(e){return function(t){return t.type===F.READY&&r(t,n),e(t)}}};return L(e),function(){return D(e)}},on:function(r,t){var o="function"==typeof t&&t;if(!o)return!1;if("*"===r){var e=function(n){return function(e){return function(t){return o(t,n),e(t)}}};return L(e),function(){D(e)}}var n=function(n){return function(e){return function(t){return t.type===r&&o(t,n),e(t)}}};return L(n),function(){D(n)}},addIntegration:function(t){if("object"===(void 0===t?"undefined":x(t))){var e={};e[t.NAMESPACE]=t,i=M({},i,e),console.log("add new integration dynamically",i)}s.dispatch({type:F.REGISTER_INTEGRATION,name:t.NAMESPACE,integration:t})}}}var t="object"==typeof self&&self&&self.Object===Object&&self;t=("object"==typeof global&&global&&global.Object===Object&&global||t||Function("return this")()).Symbol;var n,r,o,i,c=Object.prototype,f=c.hasOwnProperty,T=c.toString,I=t?t.toStringTag:void 0,j=Object.prototype.toString,S=t?t.toStringTag:void 0,O=(o=Object.getPrototypeOf,i=Object,function(t){return o(i(t))}),N=Function.prototype.toString,R=Object.prototype.hasOwnProperty,w=N.call(Object),P=(n="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof module?module:Function("return this")(),"function"==typeof(r=n.Symbol)?r.observable?n=r.observable:(n=r("observable"),r.observable=n):n="@@observable",n),$={INIT:"@@redux/INIT"},C=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n,r=arguments[e];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},M=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n,r=arguments[e];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},k=function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)},u=[],G=function(o){return function(r){return function(t){var e={getState:o.getState,dispatch:function(t){return o.dispatch(t)}},n=u.map(function(t){return t(e)});return y.apply(void 0,k(n))(r)(t)}}},L=function(){var t;u=(t=u).concat.apply(t,arguments)},D=function(e){var t=u.findIndex(function(t){return t===e});-1!==t&&(u=[].concat(k(u.slice(0,t)),k(u.slice(t+1))))},F={INITIALIZE:"analyticsInit",HANDLE_PARAMS:"params",SET_CAMPAIGN:"campaign",READY:"ready",REGISTER_INTEGRATION:"integration_init",INTEGRATION_LOADED:"integration_ready",INTEGRATION_FAILED:"integration_failed",ENABLE_INTEGRATION:"enable_integration",DISABLE_INTEGRATION:"disable_integration",PAGE_START:"page_init",PAGE:"page",PAGE_COMPLETE:"page_complete",PAGE_ABORT:"page_abort",TRACK_START:"track_init",TRACK:"track",TRACK_COMPLETE:"track_complete",TRACK_ABORT:"track_abort",IDENTIFY_START:"identify_init",IDENTIFY:"identify",IDENTIFY_COMPLETE:"identify_complete",IDENTIFY_ABORTED:"identify_abort"},Y=function(o){return function(r){return function(t){if(t.type===F.INITIALIZE){var n=function(t){if("undefined"==typeof window)return{};var e,n={},r=/([^&=]+)=?([^&]*)/g;if(!(t=t?(t=t.match(/\?(.*)/))&&t[1]?t[1].split("#")[0]:"":window.location.search.substring(1)))return!1;for(;e=r.exec(t);)if("-1"==e[1].indexOf("["))n[a(e[1])]=a(e[2]);else{var o=e[1].indexOf("["),i=e[1].slice(o+1,e[1].indexOf("]",o));o=a(e[1].slice(0,o)),"object"!==x(n[o])&&(n[a(o)]={},n[a(o)].length=0),i?n[a(o)][a(i)]=a(e[2]):Array.prototype.push.call(n[a(o)],a(e[2]))}return n}();if(n){o.dispatch({type:F.HANDLE_PARAMS,params:n});var e=Object.keys(n).reduce(function(t,e){return e.match(/utm_/)&&(t[e]=n[e]),t},{});Object.keys(e).length&&o.dispatch({type:F.SET_CAMPAIGN,campaign:e})}}return r(t)}}},s="undefined"!=typeof window,B=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return s&&(t=M({title:document.title,url:window.location.href,path:window.location.pathname,hash:window.location.hash,search:window.location.search,width:window.innerWidth,height:window.innerHeight},t),document.referrer&&""!==document.referrer&&(t.referrer=document.referrer)),t},l=B();t=void 0;var K={initialized:!1,app:null,version:null,os:{name:t=function(){if("undefined"==typeof navigator)return!1;var t=navigator.appVersion;return-1!==t.indexOf("Win")?"Windows":-1!==t.indexOf("Mac")?"MacOS":-1!==t.indexOf("X11")?"UNIX":-1!==t.indexOf("Linux")?"Linux":"Unknown OS"}()},userAgent:"undefined"!=typeof navigator?navigator.userAgent:"node",library:{name:"analytics",version:"0.0.5"},campaign:{}},U={},W={event:{},lastEvent:null,history:[]},z={userId:null,anonymousId:function(){var t;if(!(t=localStorage.getItem("analytics_id"))){t=[];for(var e=0;e<256;e++)t[e]=(e<16?"0":"")+e.toString(16);e=4294967295*Math.random()|0;var n=4294967295*Math.random()|0,r=4294967295*Math.random()|0,o=4294967295*Math.random()|0;t=t[255&e]+t[e>>8&255]+t[e>>16&255]+t[e>>24&255]+"-"+t[255&n]+t[n>>8&255]+"-"+t[n>>16&15|64]+t[n>>24&255]+"-"+t[63&r|128]+t[r>>8&255]+"-"+t[r>>16&255]+t[r>>24&255]+t[255&o]+t[o>>8&255]+t[o>>16&255]+t[o>>24&255],localStorage.setItem("analytics_id",t)}return t}(),traits:{}};module.exports=function(t){return e(t)}}(); | ||
"use strict";var $jscomp=$jscomp||{};$jscomp.scope={},$jscomp.ASSUME_ES5=!1,$jscomp.ASSUME_NO_NATIVE_MAP=!1,$jscomp.ASSUME_NO_NATIVE_SET=!1,$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(t,e,n){t!=Array.prototype&&t!=Object.prototype&&(t[e]=n.value)},$jscomp.getGlobal=function(t){return"undefined"!=typeof window&&window===t?t:"undefined"!=typeof global&&null!=global?global:t},$jscomp.global=$jscomp.getGlobal(this),$jscomp.SYMBOL_PREFIX="jscomp_symbol_",$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){},$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)},$jscomp.Symbol=function(){var e=0;return function(t){return $jscomp.SYMBOL_PREFIX+(t||"")+e++}}(),$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var t=$jscomp.global.Symbol.iterator;t||(t=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator")),"function"!=typeof Array.prototype[t]&&$jscomp.defineProperty(Array.prototype,t,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}}),$jscomp.initSymbolIterator=function(){}},$jscomp.arrayIterator=function(t){var e=0;return $jscomp.iteratorPrototype(function(){return e<t.length?{done:!1,value:t[e++]}:{done:!0}})},$jscomp.iteratorPrototype=function(t){return $jscomp.initSymbolIterator(),(t={next:t})[$jscomp.global.Symbol.iterator]=function(){return this},t},$jscomp.iteratorFromArray=function(e,n){$jscomp.initSymbolIterator(),e instanceof String&&(e+="");var r=0,o={next:function(){if(r<e.length){var t=r++;return{value:n(t,e[t]),done:!1}}return o.next=function(){return{done:!0,value:void 0}},o.next()}};return o[Symbol.iterator]=function(){return o},o},$jscomp.polyfill=function(t,e,n,r){if(e){for(n=$jscomp.global,t=t.split("."),r=0;r<t.length-1;r++){var o=t[r];o in n||(n[o]={}),n=n[o]}(e=e(r=n[t=t[t.length-1]]))!=r&&null!=e&&$jscomp.defineProperty(n,t,{configurable:!0,writable:!0,value:e})}},$jscomp.polyfill("Array.prototype.keys",function(t){return t||function(){return $jscomp.iteratorFromArray(this,function(t){return t})}},"es6","es3"),$jscomp.owns=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},$jscomp.assign="function"==typeof Object.assign?Object.assign:function(t,e){for(var n=1;n<arguments.length;n++){var r=arguments[n];if(r)for(var o in r)$jscomp.owns(r,o)&&(t[o]=r[o])}return t},$jscomp.polyfill("Object.assign",function(t){return t||$jscomp.assign},"es6","es3"),$jscomp.polyfill("Array.from",function(t){return t||function(t,e,n){$jscomp.initSymbolIterator(),e=null!=e?e:function(t){return t};var r=[],o=t[Symbol.iterator];if("function"==typeof o){t=o.call(t);for(var i=0;!(o=t.next()).done;)r.push(e.call(n,o.value,i++))}else for(o=t.length,i=0;i<o;i++)r.push(e.call(n,t[i],i));return r}},"es6","es3"),$jscomp.findInternal=function(t,e,n){t instanceof String&&(t=String(t));for(var r=t.length,o=0;o<r;o++){var i=t[o];if(e.call(n,i,o,t))return{i:o,v:i}}return{i:-1,v:void 0}},$jscomp.polyfill("Array.prototype.findIndex",function(t){return t||function(t,e){return $jscomp.findInternal(this,t,e).i}},"es6","es3"),$jscomp.makeIterator=function(t){$jscomp.initSymbolIterator();var e=t[Symbol.iterator];return e?e.call(t):$jscomp.arrayIterator(t)},$jscomp.FORCE_POLYFILL_PROMISE=!1,$jscomp.polyfill("Promise",function(t){function e(){this.batch_=null}function c(n){return n instanceof u?n:new u(function(t,e){t(n)})}if(t&&!$jscomp.FORCE_POLYFILL_PROMISE)return t;e.prototype.asyncExecute=function(t){return null==this.batch_&&(this.batch_=[],this.asyncExecuteBatch_()),this.batch_.push(t),this},e.prototype.asyncExecuteBatch_=function(){var t=this;this.asyncExecuteFunction(function(){t.executeBatch_()})};var n=$jscomp.global.setTimeout;e.prototype.asyncExecuteFunction=function(t){n(t,0)},e.prototype.executeBatch_=function(){for(;this.batch_&&this.batch_.length;){var t=this.batch_;this.batch_=[];for(var e=0;e<t.length;++e){var n=t[e];t[e]=null;try{n()}catch(t){this.asyncThrow_(t)}}}this.batch_=null},e.prototype.asyncThrow_=function(t){this.asyncExecuteFunction(function(){throw t})};var u=function(t){this.state_=0,this.result_=void 0,this.onSettledCallbacks_=[];var e=this.createResolveAndReject_();try{t(e.resolve,e.reject)}catch(t){e.reject(t)}};u.prototype.createResolveAndReject_=function(){function t(e){return function(t){r||(r=!0,e.call(n,t))}}var n=this,r=!1;return{resolve:t(this.resolveTo_),reject:t(this.reject_)}},u.prototype.resolveTo_=function(t){if(t===this)this.reject_(new TypeError("A Promise cannot resolve to itself"));else if(t instanceof u)this.settleSameAsPromise_(t);else{t:switch(typeof t){case"object":var e=null!=t;break t;case"function":e=!0;break t;default:e=!1}e?this.resolveToNonPromiseObj_(t):this.fulfill_(t)}},u.prototype.resolveToNonPromiseObj_=function(t){var e=void 0;try{e=t.then}catch(t){return void this.reject_(t)}"function"==typeof e?this.settleSameAsThenable_(e,t):this.fulfill_(t)},u.prototype.reject_=function(t){this.settle_(2,t)},u.prototype.fulfill_=function(t){this.settle_(1,t)},u.prototype.settle_=function(t,e){if(0!=this.state_)throw Error("Cannot settle("+t+", "+e+"): Promise already settled in state"+this.state_);this.state_=t,this.result_=e,this.executeOnSettledCallbacks_()},u.prototype.executeOnSettledCallbacks_=function(){if(null!=this.onSettledCallbacks_){for(var t=0;t<this.onSettledCallbacks_.length;++t)o.asyncExecute(this.onSettledCallbacks_[t]);this.onSettledCallbacks_=null}};var o=new e;return u.prototype.settleSameAsPromise_=function(t){var e=this.createResolveAndReject_();t.callWhenSettled_(e.resolve,e.reject)},u.prototype.settleSameAsThenable_=function(t,e){var n=this.createResolveAndReject_();try{t.call(e,n.resolve,n.reject)}catch(t){n.reject(t)}},u.prototype.then=function(t,e){function n(e,t){return"function"==typeof e?function(t){try{r(e(t))}catch(t){o(t)}}:t}var r,o,i=new u(function(t,e){r=t,o=e});return this.callWhenSettled_(n(t,r),n(e,o)),i},u.prototype.catch=function(t){return this.then(void 0,t)},u.prototype.callWhenSettled_=function(t,e){function n(){switch(r.state_){case 1:t(r.result_);break;case 2:e(r.result_);break;default:throw Error("Unexpected state: "+r.state_)}}var r=this;null==this.onSettledCallbacks_?o.asyncExecute(n):this.onSettledCallbacks_.push(n)},u.resolve=c,u.reject=function(n){return new u(function(t,e){e(n)})},u.race=function(o){return new u(function(t,e){for(var n=$jscomp.makeIterator(o),r=n.next();!r.done;r=n.next())c(r.value).callWhenSettled_(t,e)})},u.all=function(t){var i=$jscomp.makeIterator(t),a=i.next();return a.done?c([]):new u(function(n,t){function e(e){return function(t){r[e]=t,0==--o&&n(r)}}for(var r=[],o=0;r.push(void 0),o++,c(a.value).callWhenSettled_(e(r.length-1),t),!(a=i.next()).done;);})},u},"es6","es3"),function(){function p(t,e,n){function r(e){if("function"!=typeof e)throw Error("Expected listener to be a function.");var n=!0;return s===u&&(s=u.slice()),s.push(e),function(){if(n){n=!1,s===u&&(s=u.slice());var t=s.indexOf(e);s.splice(t,1)}}}function o(t){var e;if(e=null!=t&&"object"==typeof t){if(null==t)e=void 0===t?"[object Undefined]":"[object Null]";else if(S&&S in Object(t)){e=f.call(t,I);var n=t[I];try{t[I]=void 0}catch(t){}var r=T.call(t);e?t[I]=n:delete t[I],e=r}else e=j.call(t);e="[object Object]"==e}if(!(e=!!e&&(null===(e=O(t))||"function"==typeof(e=w.call(e,"constructor")&&e.constructor)&&e instanceof e&&N.call(e)==R)))throw Error("Actions must be plain objects. Use custom middleware for async actions.");if(void 0===t.type)throw Error('Actions may not have an undefined "type" property. Have you misspelled a constant?');if(l)throw Error("Reducers may not dispatch actions.");try{l=!0,c=a(c,t)}finally{l=!1}for(e=u=s,n=0;n<e.length;n++)e[n]();return t}var i;if("function"==typeof e&&void 0===n&&(n=e,e=void 0),void 0!==n){if("function"!=typeof n)throw Error("Expected the enhancer to be a function.");return n(p)(t,e)}if("function"!=typeof t)throw Error("Expected the reducer to be a function.");var a=t,c=e,u=[],s=u,l=!1;return o({type:$.INIT}),(i={dispatch:o,subscribe:r,getState:function(){return c},replaceReducer:function(t){if("function"!=typeof t)throw Error("Expected the nextReducer to be a function.");a=t,o({type:$.INIT})}})[P]=function(){var t;return(t={subscribe:function(t){function e(){t.next&&t.next(c)}if("object"!=typeof t)throw new TypeError("Expected the observer to be an object.");return e(),{unsubscribe:r(e)}}})[P]=function(){return this},t},i}function d(t){for(var e=Object.keys(t),u={},n=0;n<e.length;n++){var r=e[n];"function"==typeof t[r]&&(u[r]=t[r])}var o,s=Object.keys(u);try{o=u,Object.keys(o).forEach(function(t){var e=o[t];if(void 0===e(void 0,{type:$.INIT}))throw Error('Reducer "'+t+'" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined.');if(void 0===e(void 0,{type:"@@redux/PROBE_UNKNOWN_ACTION_"+Math.random().toString(36).substring(7).split("").join(".")}))throw Error('Reducer "'+t+"\" returned undefined when probed with a random type. Don't try to handle "+$.INIT+' or other actions in "redux/*" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined.')})}catch(t){var l=t}return function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=arguments[1];if(l)throw l;for(var n=!1,r={},o=0;o<s.length;o++){var i=s[o],a=t[i],c=(0,u[i])(a,e);if(void 0===c)throw t=e&&e.type,Error("Given action "+(t&&'"'+t.toString()+'"'||"an action")+', reducer "'+i+'" returned undefined. To ignore an action, you must explicitly return the previous state.');r[i]=c,n=n||c!==a}return n?r:t}}function y(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];if(0===e.length)return function(t){return t};if(1===e.length)return e[0];var r=e[e.length-1],o=e.slice(0,-1);return function(){return o.reduceRight(function(t,e){return e(t)},r.apply(void 0,arguments))}}function a(t){return decodeURIComponent(t).replace(/\+/g," ")}function m(n,r){return Object.keys(n).reduce(function(t,e){return(e=n[e])[r]?t.concat(e):t},[])}function b(){for(var t=0;t<arguments.length;++t)if("function"==typeof arguments[t])return arguments[t];return!1}function h(v){return function(h){return function(i){return function(t){var e,n,r,o=t.type,a=t.eventName,c=t.data,u=t.options,s=t.callback;if(o===F.TRACK_START){var l=(n=c,r={},"object"===(void 0===(e=a)?"undefined":x(e))?r=e:"object"===(void 0===n?"undefined":x(n))&&(r=n),r),f={eventName:a,payload:l,options:u};if(t.abort)return h.dispatch(M({type:F.TRACK_ABORT},f)),i(t);var p=m(v(),"track");if(!p.length)return h.dispatch(M({type:F.TRACK},f)),h.dispatch(M({type:F.TRACK_COMPLETE},f));var d=0,y=!1;p.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT TRACK>>>>>",t.NAMESPACE,o),!e}).forEach(function(r){var o=r.NAMESPACE,i=0;!function t(){var e=h.getState(),n=M({},e,{options:u});if(!e.integrations[o].loaded)return 1e4<i?h.dispatch(M({},f,{type:"trackingTimeout"})):(i+=10,setTimeout(t,10)),!1;r.track(a,l,n),y||(h.dispatch(M({type:F.TRACK},f)),y=!0),h.dispatch(M({type:"track:"+o,integration:o},f)),(d+=1)===p.length&&((n=b(c,u,s))&&n(e),h.dispatch(M({type:F.TRACK_COMPLETE},f)))}()})}return i(t)}}}}function v(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:l,e=arguments[1];switch(e.type){case F.PAGE:return Object.assign({},t,e.data);default:return t}}function E(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:K,e=arguments[1],n=t.initialized,r=e.campaign;switch(e.type){case F.SET_CAMPAIGN:return M({},t,{campaign:r});default:return n?t:M({},K,t,{initialized:!0})}}function g(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:U,e=arguments[1],n={};switch(e.type){case F.REGISTER_INTEGRATION:return n[e.name]={enabled:!0,loaded:!1,config:e.integration.config},M({},t,n);case F.INTEGRATION_LOADED:return(n={})[e.name]=M({},t[e.name],{loaded:!0}),M({},t,n);case F.INTEGRATION_FAILED:return n[e.name]=M({},t[e.name],{loaded:!1}),M({},t,n);case F.DISABLE_INTEGRATION:return n[e.name]=M({},t[e.name],{enabled:!1}),M({},t,n);default:return t}}function A(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:W,e=arguments[1],n=e.data;switch(e.type){case F.TRACK:return e=t.lastEvent?t.event:n,console.log(">>>>>>>>>>>> state.lastEvent",t.lastEvent),M({},t,{event:n,lastEvent:e});default:return t}}function _(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:H,e=arguments[1];switch(e.type){case F.IDENTIFY:return Object.assign({},t,{userId:e.userId,traits:M({},t.traits,e.traits)});default:return t}}function e(){var r,o,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=t.plugins||[],n=t.reducers||{},i=e.reduce(function(t,e){return"function"!=typeof e&&e.NAMESPACE&&(t[e.NAMESPACE]=e),t},{}),a=function(){return i};e=e.reduce(function(t,e){return"function"==typeof e?t.concat(e):t},[]).concat([Y,(o=a,function(d){return function(e){return function(t){var n=t.type,a=t.userId,c=t.traits,u=t.options,s=t.callback;if(n===F.IDENTIFY_START){var l=m(o(),"identify");if(!l.length)return d.dispatch({type:F.IDENTIFY,userId:a,traits:c,options:u}),d.dispatch(M({type:F.IDENTIFY_COMPLETE}));var f=0,p=!1;l.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT Identify >>>>>",t.NAMESPACE,n),!e}).forEach(function(r){var o=r.NAMESPACE,i=0;!function t(){var e=d.getState();if(!e.integrations[o].loaded)return 1e4<i?d.dispatch({type:"identifyTimeout",name:o}):(i+=10,setTimeout(t,10)),!1;if(p||(p=!0,d.dispatch({type:F.IDENTIFY,userId:a,traits:c,options:u})),r.identify(a,c,u),d.dispatch({type:"identify:"+o}),(f+=1)===l.length){var n=b(c,u,s);n&&n(e),d.dispatch({type:F.IDENTIFY_COMPLETE})}}()})}return e(t)}}}),h(a),(r=a,function(d){return function(e){return function(t){var n=t.type,c=t.data,u=t.options,s=t.callback;if(n===F.PAGE_START){var l=m(r(),"page");if(!l.length)return d.dispatch({type:F.PAGE,data:B(),options:u}),d.dispatch({type:F.PAGE_COMPLETE});var f=0,p=!1;l.filter(function(t){var e=u&&u.integrations;return(e=e&&!1===e[t.NAMESPACE])&&console.log("ABORT PageView>>>>>",t.NAMESPACE,n),!e}).forEach(function(o){var i=o.NAMESPACE,a=0;!function t(){var e=d.getState(),n=B(),r=M({},e,{options:u});if(!e.integrations[i].loaded)return console.log("try again",i),1e4<a?d.dispatch({type:"pageTimeout",name:i}):(a+=10,setTimeout(t,10)),!1;p||(d.dispatch({type:F.PAGE,data:n,options:u}),p=!0),o.page(n,r),d.dispatch({type:"page:"+i,data:n}),(f+=1)===l.length&&((e=b(c,u,s))&&e(d),d.dispatch({type:F.PAGE_COMPLETE}))}()})}return e(t)}}}),G]),a={context:E,user:_,page:v,track:A,integrations:g};var c=y;"undefined"!=typeof window&&(c=y);var u,s=p(d(M({},a,n)),{context:(u=t,Object.keys(u).reduce(function(t,e){return"plugins"===e||"reducers"===e||(t[e]=u[e]),t},{}))},c(function(){for(var t=arguments.length,a=Array(t),e=0;e<t;e++)a[e]=arguments[e];return function(i){return function(t,e,n){var r=(t=i(t,e,n)).dispatch;e=[];var o={getState:t.getState,dispatch:function(t){return r(t)}};return e=a.map(function(t){return t(o)}),r=y.apply(void 0,e)(t.dispatch),C({},t,{dispatch:r})}}}.apply(void 0,k(e))));s.dispatch({type:F.INITIALIZE});var l=Object.keys(i),f=0;return l.forEach(function(t,e){var n=i[t];if(s.dispatch({type:F.REGISTER_INTEGRATION,name:n.NAMESPACE,integration:n}),n&&n.initialize&&(n.initialize(n.config),n.loaded&&"function"==typeof n.loaded)){var r=0;!function t(){return 1e3<r?(s.dispatch({type:F.INTEGRATION_FAILED,name:n.NAMESPACE}),s.dispatch({type:"integration_failed:"+n.NAMESPACE}),!1):n.loaded()?(s.dispatch({type:F.INTEGRATION_LOADED,name:n.NAMESPACE}),s.dispatch({type:"integration_ready:"+n.NAMESPACE}),void((f+=1)===l.length&&s.dispatch({type:F.READY}))):(r++,setTimeout(t,10),!1)}()}}),l.length||setTimeout(function(){s.dispatch({type:F.READY})},0),{getState:function(t){var e=s.getState();return t?e[t]:e},dispatch:s.dispatch,subscribe:s.subscribe,replaceReducer:s.replaceReducer,track:function(t,e,n,r){return s.dispatch({type:F.TRACK_START,eventName:t,data:e,options:n,callback:r}),Promise.resolve()},page:function(t,e,n){return s.dispatch({type:F.PAGE_START,data:t,options:e,callback:n}),Promise.resolve()},identify:function(t,e,n,r){var o,i,a,c;return s.dispatch((o=t,i=e,a=n,c=r,console.log("identify",o,i,a),{type:F.IDENTIFY_START,userId:o,traits:i,options:a,callback:c})),Promise.resolve()},user:function(){return s.getState().user},ready:function(t){var r="function"==typeof t&&t;if(!r)return!1;var e=function(n){return function(e){return function(t){return t.type===F.READY&&r(t,n),e(t)}}};return L(e),function(){return D(e)}},on:function(r,t){var o="function"==typeof t&&t;if(!o)return!1;if("*"===r){var e=function(n){return function(e){return function(t){return o(t,n),e(t)}}};return L(e),function(){D(e)}}var n=function(n){return function(e){return function(t){return t.type===r&&o(t,n),e(t)}}};return L(n),function(){D(n)}},addIntegration:function(t){if("object"===(void 0===t?"undefined":x(t))){var e={};e[t.NAMESPACE]=t,i=M({},i,e),console.log("add new integration dynamically",i)}s.dispatch({type:F.REGISTER_INTEGRATION,name:t.NAMESPACE,integration:t})}}}var t="object"==typeof self&&self&&self.Object===Object&&self;t=("object"==typeof global&&global&&global.Object===Object&&global||t||Function("return this")()).Symbol;var n,r,o,i,c=Object.prototype,f=c.hasOwnProperty,T=c.toString,I=t?t.toStringTag:void 0,j=Object.prototype.toString,S=t?t.toStringTag:void 0,O=(o=Object.getPrototypeOf,i=Object,function(t){return o(i(t))}),N=Function.prototype.toString,w=Object.prototype.hasOwnProperty,R=N.call(Object),P=(n="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof module?module:Function("return this")(),"function"==typeof(r=n.Symbol)?r.observable?n=r.observable:(n=r("observable"),r.observable=n):n="@@observable",n),$={INIT:"@@redux/INIT"},C=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n,r=arguments[e];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},M=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n,r=arguments[e];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},k=function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)},u=[],G=function(o){return function(r){return function(t){var e={getState:o.getState,dispatch:function(t){return o.dispatch(t)}},n=u.map(function(t){return t(e)});return y.apply(void 0,k(n))(r)(t)}}},L=function(){var t;u=(t=u).concat.apply(t,arguments)},D=function(e){var t=u.findIndex(function(t){return t===e});-1!==t&&(u=[].concat(k(u.slice(0,t)),k(u.slice(t+1))))},F={INITIALIZE:"analyticsInit",HANDLE_PARAMS:"params",SET_CAMPAIGN:"campaign",READY:"ready",REGISTER_INTEGRATION:"integration_init",INTEGRATION_LOADED:"integration_ready",INTEGRATION_FAILED:"integration_failed",ENABLE_INTEGRATION:"enable_integration",DISABLE_INTEGRATION:"disable_integration",PAGE_START:"page_init",PAGE:"page",PAGE_COMPLETE:"page_complete",PAGE_ABORT:"page_abort",TRACK_START:"track_init",TRACK:"track",TRACK_COMPLETE:"track_complete",TRACK_ABORT:"track_abort",IDENTIFY_START:"identify_init",IDENTIFY:"identify",IDENTIFY_COMPLETE:"identify_complete",IDENTIFY_ABORTED:"identify_abort"},Y=function(o){return function(r){return function(t){if(t.type===F.INITIALIZE){var n=function(t){if("undefined"==typeof window)return{};var e,n={},r=/([^&=]+)=?([^&]*)/g;if(!(t=t?(t=t.match(/\?(.*)/))&&t[1]?t[1].split("#")[0]:"":window.location.search.substring(1)))return!1;for(;e=r.exec(t);)if("-1"==e[1].indexOf("["))n[a(e[1])]=a(e[2]);else{var o=e[1].indexOf("["),i=e[1].slice(o+1,e[1].indexOf("]",o));o=a(e[1].slice(0,o)),"object"!==x(n[o])&&(n[a(o)]={},n[a(o)].length=0),i?n[a(o)][a(i)]=a(e[2]):Array.prototype.push.call(n[a(o)],a(e[2]))}return n}();if(n){o.dispatch({type:F.HANDLE_PARAMS,params:n});var e=Object.keys(n).reduce(function(t,e){return e.match(/utm_/)&&(t[e]=n[e]),t},{});Object.keys(e).length&&o.dispatch({type:F.SET_CAMPAIGN,campaign:e})}}return r(t)}}},s="undefined"!=typeof window,B=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return s&&(t=M({title:document.title,url:window.location.href,path:window.location.pathname,hash:window.location.hash,search:window.location.search,width:window.innerWidth,height:window.innerHeight},t),document.referrer&&""!==document.referrer&&(t.referrer=document.referrer)),t},l=B();t=void 0;var K={initialized:!1,app:null,version:null,os:{name:t=function(){if("undefined"==typeof navigator)return!1;var t=navigator.appVersion;return-1!==t.indexOf("Win")?"Windows":-1!==t.indexOf("Mac")?"MacOS":-1!==t.indexOf("X11")?"UNIX":-1!==t.indexOf("Linux")?"Linux":"Unknown OS"}()},userAgent:"undefined"!=typeof navigator?navigator.userAgent:"node",library:{name:"analytics",version:"0.0.6"},campaign:{}},U={},W={event:{},lastEvent:null,history:[]},z="undefined"!=typeof window,H={userId:null,anonymousId:function(){var t=z?localStorage.getItem("analytics_id"):null;if(!t){t=[];for(var e=0;e<256;e++)t[e]=(e<16?"0":"")+e.toString(16);e=4294967295*Math.random()|0;var n=4294967295*Math.random()|0,r=4294967295*Math.random()|0,o=4294967295*Math.random()|0;t=t[255&e]+t[e>>8&255]+t[e>>16&255]+t[e>>24&255]+"-"+t[255&n]+t[n>>8&255]+"-"+t[n>>16&15|64]+t[n>>24&255]+"-"+t[63&r|128]+t[r>>8&255]+"-"+t[r>>16&255]+t[r>>24&255]+t[255&o]+t[o>>8&255]+t[o>>16&255]+t[o>>24&255],z&&localStorage.setItem("analytics_id",t)}return t}(),traits:{}};module.exports=function(t){return e(t)}}(); |
{ | ||
"name": "analytics", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Pluggable analytics library", | ||
@@ -5,0 +5,0 @@ "author": "David Wells", |
Sorry, the diff of this file is too big to display
514501
13041