analytics-utils
Advanced tools
Comparing version 0.4.7 to 0.4.8
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.4.8](https://github.com/DavidWells/analytics/compare/analytics-utils@0.4.7...analytics-utils@0.4.8) (2021-07-28) | ||
**Note:** Version bump only for package analytics-utils | ||
## [0.4.7](https://github.com/DavidWells/analytics/compare/analytics-utils@0.4.6...analytics-utils@0.4.7) (2021-07-26) | ||
@@ -8,0 +16,0 @@ |
@@ -6,47 +6,30 @@ var analyticsUtils = (function (exports) { | ||
var l = "object" == typeof self && self.self === self && self || "object" == typeof global && global.global === global && global || void 0; | ||
var l = "object" == typeof self && self.self === self && self || "object" == typeof global && global.global === global && global || void 0, | ||
e = "undefined"; | ||
function o(o) { | ||
return l[o]; | ||
function o(e) { | ||
return l[e]; | ||
} | ||
function e(o, e) { | ||
return l[o] = e, e; | ||
function f(e, o) { | ||
return l[e] = o, o; | ||
} | ||
function f(l) { | ||
e(l, void 0); | ||
function n(l) { | ||
f(l); | ||
} | ||
var r = "undefined", | ||
a = l$1(); | ||
var i = a(), | ||
r = p, | ||
c = p; | ||
function l$1(t) { | ||
if (void 0 === t && (t = !1), typeof a !== r && !t) return a; | ||
a = !0; | ||
try { | ||
typeof localStorage !== r && typeof JSON !== r || (a = !1), localStorage.setItem("_" + r, "1"), localStorage.removeItem("_" + r); | ||
} catch (t) { | ||
a = !1; | ||
} | ||
return a; | ||
function u(e$$1) { | ||
return i ? p(e$$1, "", -1) : n(e$$1); | ||
} | ||
var n$1 = "undefined", | ||
i = a$1(), | ||
r$1 = d, | ||
c$1 = d; | ||
function a() { | ||
if (typeof i !== e) return i; | ||
function u$1(e$$1) { | ||
return i ? d(e$$1, "", -1) : f(e$$1); | ||
} | ||
function a$1(e$$1) { | ||
if (void 0 === e$$1 && (e$$1 = !1), typeof i !== n$1 && !e$$1) return i; | ||
try { | ||
var o$$1 = "_" + n$1; | ||
d(o$$1, "1"), i = -1 !== document.cookie.indexOf(o$$1), d(o$$1, "", -1); | ||
p(e, "1"), i = -1 !== document.cookie.indexOf(e), u(e); | ||
} catch (e$$1) { | ||
@@ -59,293 +42,124 @@ i = !1; | ||
function d(t, r, c, u, a, d) { | ||
if (typeof window !== n$1) { | ||
var f$$1 = arguments.length > 1; | ||
return i || (f$$1 ? e(t, r) : o(t)), f$$1 ? document.cookie = t + "=" + encodeURIComponent(r) + (c ? "; expires=" + new Date(+new Date() + 1e3 * c).toUTCString() + (u ? "; path=" + u : "") + (a ? "; domain=" + a : "") + (d ? "; secure" : "") : "") : decodeURIComponent((("; " + document.cookie).split("; " + t + "=")[1] || "").split(";")[0]); | ||
function p(t, r, c, u, a, p) { | ||
if (typeof window !== e) { | ||
var d = arguments.length > 1; | ||
return i || (d ? f(t, r) : o(t)), d ? document.cookie = t + "=" + encodeURIComponent(r) + (c ? "; expires=" + new Date(+new Date() + 1e3 * c).toUTCString() + (u ? "; path=" + u : "") + (a ? "; domain=" + a : "") + (p ? "; secure" : "") : "") : decodeURIComponent((("; " + document.cookie).split("; " + t + "=")[1] || "").split(";")[0]); | ||
} | ||
} | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
var a$1 = l$1(); | ||
return _typeof(obj); | ||
} | ||
function l$1() { | ||
if (typeof a$1 !== e) return a$1; | ||
a$1 = !0; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
try { | ||
typeof localStorage !== e && typeof JSON !== e || (a$1 = !1), localStorage.setItem(e, e), localStorage.removeItem(e); | ||
} catch (t) { | ||
a$1 = !1; | ||
} | ||
return obj; | ||
return a$1; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
function c$2(t) { | ||
return void 0 === t; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
function b(t) { | ||
if ("object" != typeof t || null === t) return !1; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(source).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
for (var n = t; null !== Object.getPrototypeOf(n);) n = Object.getPrototypeOf(n); | ||
return target; | ||
return Object.getPrototypeOf(t) === n; | ||
} | ||
function parse(input) { | ||
var value; | ||
function g(o$$1) { | ||
var t$$1 = o$$1; | ||
try { | ||
value = JSON.parse(input); | ||
if ("true" === (t$$1 = JSON.parse(o$$1))) return !0; | ||
if ("false" === t$$1) return !1; | ||
if (b(t$$1)) return t$$1; | ||
parseFloat(t$$1) === t$$1 && (t$$1 = parseFloat(t$$1)); | ||
} catch (o$$1) {} | ||
if (typeof value === 'undefined') { | ||
value = input; | ||
} | ||
if (value === 'true') { | ||
value = true; | ||
} | ||
if (value === 'false') { | ||
value = false; | ||
} | ||
if (parseFloat(value) === value && _typeof(value) !== 'object') { | ||
value = parseFloat(value); | ||
} | ||
} catch (e$$1) { | ||
value = input; | ||
} | ||
return value; | ||
if (null !== t$$1 && "" !== t$$1) return t$$1; | ||
} | ||
var ALL = '*'; | ||
var LOCAL_STORAGE = 'localStorage'; | ||
var COOKIE = 'cookie'; | ||
var GLOBAL = 'global'; // Verify support | ||
var S = l$1(), | ||
k = a(); | ||
var hasStorage = l$1(); | ||
var hasCookiesSupport = a$1(); | ||
/** | ||
* Get storage item from localStorage, cookie, or window | ||
* @param {string} key - key of item to get | ||
* @param {object|string} [options] - storage options. If string location of where to get storage | ||
* @param {string} [options.storage] - Define type of storage to pull from. | ||
* @return {Any} the value of key | ||
*/ | ||
function getItem(key) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!key) return; | ||
var storageType = getStorageType(options); // Get value from all locations | ||
if (storageType === ALL) return getAll(key); | ||
/* 1. Try localStorage */ | ||
if (useLocal(storageType)) { | ||
var value = localStorage.getItem(key); | ||
if (value || storageType === LOCAL_STORAGE) return parse(value); | ||
function y$1(t$$1, r$$1) { | ||
if (t$$1) { | ||
var e$$1 = x(r$$1), | ||
l$$1 = !h(e$$1), | ||
i = C(e$$1) ? g(localStorage.getItem(t$$1)) : void 0; | ||
if (l$$1 && !c$2(i)) return i; | ||
var n$$1 = d(e$$1) ? g(r(t$$1)) : void 0; | ||
if (l$$1 && n$$1) return n$$1; | ||
var c$$1 = o(t$$1); | ||
return l$$1 ? c$$1 : { | ||
localStorage: i, | ||
cookie: n$$1, | ||
global: c$$1 | ||
}; | ||
} | ||
/* 2. Fallback to cookie */ | ||
if (useCookie(storageType)) { | ||
var _value = r$1(key); | ||
if (_value || storageType === COOKIE) return parse(_value); | ||
} | ||
/* 3. Fallback to window/global. */ | ||
return o(key); | ||
} | ||
function getAll(key) { | ||
return { | ||
cookie: parse(r$1(key)), | ||
localStorage: parse(localStorage.getItem(key)), | ||
global: o(key) | ||
}; | ||
} | ||
/** | ||
* Store values in localStorage, cookie, or window | ||
* @param {string} key - key of item to set | ||
* @param {*} value - value of item to set | ||
* @param {object|string} [options] - storage options. If string location of where to get storage | ||
* @param {string} [options.storage] - Define type of storage to pull from. | ||
* @returns {object} returns old value, new values, & location of storage | ||
*/ | ||
function setItem(key, value) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
if (!key || typeof value === 'undefined') { | ||
return; | ||
function b$1(r$$1, e$$1, i) { | ||
if (r$$1 && !c$2(e$$1)) { | ||
var n$$1 = {}, | ||
c$$1 = x(i), | ||
s = JSON.stringify(e$$1), | ||
f$$1 = !h(c$$1); | ||
return C(c$$1) && (n$$1.localStorage = { | ||
location: "localStorage", | ||
current: e$$1, | ||
previous: g(localStorage.getItem(r$$1)) | ||
}, localStorage.setItem(r$$1, s), f$$1) ? n$$1.localStorage : d(c$$1) && (n$$1.cookie = { | ||
location: "cookie", | ||
current: e$$1, | ||
previous: g(r(r$$1)) | ||
}, c(r$$1, s), f$$1) ? n$$1.cookie : (n$$1.global = { | ||
location: "global", | ||
current: e$$1, | ||
previous: o(r$$1) | ||
}, f(r$$1, e$$1), f$$1 ? n$$1.global : n$$1); | ||
} | ||
var data = {}; | ||
var storageType = getStorageType(options); | ||
var saveValue = JSON.stringify(value); | ||
var setAll = storageType === ALL; | ||
/* 1. Try localStorage */ | ||
if (useLocal(storageType)) { | ||
// console.log('SET as localstorage', saveValue) | ||
var values = { | ||
current: value, | ||
previous: parse(localStorage.getItem(key)) // Set LocalStorage item | ||
}; | ||
localStorage.setItem(key, saveValue); | ||
if (!setAll) { | ||
return _objectSpread2({ | ||
location: LOCAL_STORAGE | ||
}, values); | ||
} // Set object | ||
data[LOCAL_STORAGE] = values; | ||
} | ||
/* 2. Fallback to cookie */ | ||
if (useCookie(storageType)) { | ||
// console.log('SET as cookie', saveValue) | ||
var cookieValues = { | ||
current: value, | ||
previous: parse(r$1(key)) // Set Cookie | ||
}; | ||
c$1(key, saveValue); | ||
if (!setAll) { | ||
return _objectSpread2({ | ||
location: COOKIE | ||
}, cookieValues); | ||
} // Set object | ||
data[COOKIE] = cookieValues; | ||
} | ||
/* 3. Fallback to window/global */ | ||
var globalValues = { | ||
current: value, | ||
previous: o(key) // Set global value | ||
}; | ||
e(key, value); | ||
if (!setAll) { | ||
return _objectSpread2({ | ||
location: GLOBAL | ||
}, globalValues); | ||
} // Set object | ||
data[GLOBAL] = globalValues; | ||
return data; | ||
} | ||
/** | ||
* Remove values from localStorage, cookie, or window | ||
* @param {string} key - key of item to set | ||
* @param {object|string} [options] - storage options. If string location of where to get storage | ||
* @param {string} [options.storage] - Define type of storage to pull from. | ||
*/ | ||
function removeItem(key) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!key) return; | ||
var storageType = getStorageType(options); | ||
var removeAll = storageType === ALL; | ||
var locations = []; | ||
if (removeAll || useLocal(storageType)) { | ||
/* 1. Try localStorage */ | ||
localStorage.removeItem(key); | ||
locations.push(LOCAL_STORAGE); | ||
function I(o$$1, t$$1) { | ||
if (o$$1) { | ||
var e$$1 = x(t$$1), | ||
a$$1 = y$1(o$$1, "*"), | ||
l$$1 = {}; | ||
return !c$2(a$$1.localStorage) && C(e$$1) && (localStorage.removeItem(o$$1), l$$1.localStorage = a$$1.localStorage), !c$2(a$$1.cookie) && d(e$$1) && (u(o$$1), l$$1.cookie = a$$1.cookie), !c$2(a$$1.global) && F(e$$1, "global") && (n(o$$1), l$$1.global = a$$1.global), l$$1; | ||
} | ||
if (removeAll || useCookie(storageType)) { | ||
/* 2. Fallback to cookie */ | ||
u$1(key); | ||
locations.push(COOKIE); | ||
} | ||
/* 3. Fallback to window/global */ | ||
if (removeAll || useGlobal(storageType)) { | ||
f(key); | ||
locations.push(GLOBAL); | ||
} | ||
return locations; | ||
} | ||
function getStorageType(options) { | ||
return typeof options === 'string' ? options : options.storage; | ||
function x(o$$1) { | ||
return o$$1 ? "string" == typeof o$$1 ? o$$1 : o$$1.storage : "any"; | ||
} | ||
function useGlobal(storage) { | ||
return useType(storage, GLOBAL); | ||
function C(o$$1) { | ||
return S && F(o$$1, "localStorage"); | ||
} | ||
function useLocal(storage) { | ||
// If has localStorage and storage option not defined, or is set to 'localStorage' or '*' | ||
return hasStorage && useType(storage, LOCAL_STORAGE); | ||
function d(o$$1) { | ||
return k && F(o$$1, "cookie"); | ||
} | ||
function useCookie(storage) { | ||
// If has cookies and storage option not defined, or is set to 'cookies' or '*' | ||
return hasCookiesSupport && useType(storage, COOKIE); | ||
function h(o$$1) { | ||
return "*" === o$$1 || "all" === o$$1; | ||
} | ||
function useType(storage, type) { | ||
return !storage || storage === type || storage === ALL; | ||
function F(o$$1, t$$1) { | ||
return "any" === o$$1 || o$$1 === t$$1 || h(o$$1); | ||
} | ||
var index = { | ||
getItem: getItem, | ||
setItem: setItem, | ||
removeItem: removeItem | ||
var J = { | ||
setItem: b$1, | ||
getItem: y$1, | ||
removeItem: I | ||
}; | ||
@@ -817,9 +631,9 @@ | ||
function _typeof$1(obj) { | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof$1 = function (obj) { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof$1 = function (obj) { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
@@ -829,3 +643,3 @@ }; | ||
return _typeof$1(obj); | ||
return _typeof(obj); | ||
} | ||
@@ -875,3 +689,3 @@ | ||
function isObject(obj) { | ||
if (_typeof$1(obj) !== 'object' || obj === null) return false; | ||
if (_typeof(obj) !== 'object' || obj === null) return false; | ||
var proto = obj; | ||
@@ -886,7 +700,7 @@ | ||
exports.storage = index; | ||
exports.getCookie = r$1; | ||
exports.setCookie = c$1; | ||
exports.storage = J; | ||
exports.getCookie = r; | ||
exports.setCookie = c; | ||
exports.globalContext = l; | ||
exports.removeCookie = u$1; | ||
exports.removeCookie = u; | ||
exports.isFunction = isFunction; | ||
@@ -893,0 +707,0 @@ exports.isString = isString; |
@@ -1,1 +0,1 @@ | ||
var analyticsUtils=function(e){"use strict";var r="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||void 0;function l(e){return r[e]}function s(e,t){return r[e]=t}function i(e){s(e,void 0)}var t="undefined",n=o();function o(e){if(void 0===e&&(e=!1),typeof n!==t&&!e)return n;n=!0;try{typeof localStorage!==t&&typeof JSON!==t||(n=!1),localStorage.setItem("_"+t,"1"),localStorage.removeItem("_"+t)}catch(e){n=!1}return n}var c="undefined",u=f(),p=g,m=g;function a(e){return u?g(e,"",-1):i(e)}function f(e){if(void 0===e&&(e=!1),typeof u!==c&&!e)return u;try{var t="_"+c;g(t,"1"),u=-1!==document.cookie.indexOf(t),g(t,"",-1)}catch(e){u=!1}return u}function g(e,t,r,n,o,i){if(typeof window!==c){var a=1<arguments.length;return u||(a?s(e,t):l(e)),a?document.cookie=e+"="+encodeURIComponent(t)+(r?"; expires="+new Date(+new Date+1e3*r).toUTCString()+(n?"; path="+n:"")+(o?"; domain="+o:"")+(i?"; secure":""):""):decodeURIComponent((("; "+document.cookie).split("; "+e+"=")[1]||"").split(";")[0])}}function v(e){return(v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function y(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function d(o){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?y(i,!0).forEach(function(e){var t,r,n;t=o,n=i[r=e],r in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(i)):y(i).forEach(function(e){Object.defineProperty(o,e,Object.getOwnPropertyDescriptor(i,e))})}return o}function b(t){var r;try{void 0===(r=JSON.parse(t))&&(r=t),"true"===r&&(r=!0),"false"===r&&(r=!1),parseFloat(r)===r&&"object"!==v(r)&&(r=parseFloat(r))}catch(e){r=t}return r}var h="*",x="localStorage",O="cookie",w="global",S=o(),j=f();function P(e){return"string"==typeof e?e:e.storage}function I(e){return S&&D(e,x)}function k(e){return j&&D(e,O)}function D(e,t){return!e||e===t||e===h}var E={getItem:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(e){var r,n=P(t);if(n===h)return{cookie:b(p(r=e)),localStorage:b(localStorage.getItem(r)),global:l(r)};if(I(n)){var o=localStorage.getItem(e);if(o||n===x)return b(o)}if(k(n)){var i=p(e);if(i||n===O)return b(i)}return l(e)}},setItem:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(e&&void 0!==t){var n={},o=P(r),i=JSON.stringify(t),a=o===h;if(I(o)){var c={current:t,previous:b(localStorage.getItem(e))};if(localStorage.setItem(e,i),!a)return d({location:x},c);n[x]=c}if(k(o)){var u={current:t,previous:b(p(e))};if(m(e,i),!a)return d({location:O},u);n[O]=u}var f={current:t,previous:l(e)};return s(e,t),a?(n[w]=f,n):d({location:w},f)}},removeItem:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(e){var r=P(t),n=r===h,o=[];return(n||I(r))&&(localStorage.removeItem(e),o.push(x)),(n||k(r))&&(a(e),o.push(O)),(n||D(r,w))&&(i(e),o.push(w)),o}}};function R(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(e){return null}}var C="undefined"!=typeof document;function q(e){if(!C)return!1;var t=e||document.referrer;if(t){var r=window.document.location.port,n=t.split("/")[2];return r&&(n=n.replace(":".concat(r),"")),n!==window.location.hostname}return!1}function T(e,t){var r=(e.split("?")||[,])[1];if(!r||-1===r.indexOf(t))return e;var n=new RegExp("(\\&|\\?)".concat(t,'([_A-Za-z0-9"+=.\\/\\-@%]+)'),"g"),o="?".concat(r).replace(n,"").replace(/^&/,"?");return e.replace("?".concat(r),o)}function U(e){return function(e){var t,r={},n=/([^&=]+)=?([^&]*)/g;for(;t=n.exec(e);){var o=R(t[1]),i=R(t[2]);"[]"===o.substring(o.length-2)?(o=o.substring(0,o.length-2),(r[o]||(r[o]=[])).push(i)):r[o]=""===i||i}for(var a in r){var c=a.split("[");1<c.length&&(_(r,c.map(function(e){return e.replace(/[?[\]\\ ]/g,"")}),r[a]),delete r[a])}return r}(function(e){if(e){var t=e.match(/\?(.*)/);return t&&t[1]?t[1].split("#")[0]:""}return C&&window.location.search.substring(1)}(e))}function _(e,t,r){for(var n=t.length-1,o=0;o<n;++o){var i=t[o];i in e||(e[i]={}),e=e[i]}e[t[n]]=r}function A(e){if(!C)return null;var t=document.createElement("a");return t.setAttribute("href",e),t.hostname}function B(e){return(A(e)||"").split(".").slice(-2).join(".")}function F(e){var t=e.split(".");return 1<t.length?t.slice(0,-1).join("."):e}var N={trimTld:F,getDomainBase:B,getDomainHost:A},J="google";var L={"daum.net":"q","eniro.se":"search_word","naver.com":"query","yahoo.com":"p","msn.com":"q","aol.com":"q","ask.com":"q","baidu.com":"wd","yandex.com":"text","rambler.ru":"words",google:"q","bing.com":{p:"q",n:"live"}};function Z(e){return(Z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}return e.storage=E,e.getCookie=p,e.setCookie=m,e.globalContext=r,e.removeCookie=a,e.isFunction=function(e){return"function"==typeof e},e.isString=function(e){return"string"==typeof e},e.isArray=function(e){return Array.isArray(e)},e.isObject=function(e){if("object"!==Z(e)||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t},e.isUndefined=function(e){return void 0===e},e.isBoolean=function(e){return"boolean"==typeof e},e.dotProp=function(e,t,r,n,o){for(t=t.split?t.split("."):t,n=0;n<t.length;n++)e=e?e[t[n]]:o;return e===o?r:e},e.decodeUri=R,e.getBrowserLocale=function(){if(C){var e=navigator,t=e.language,r=e.languages,n=e.userLanguage;return n||(r&&r.length?r[0]:t)}},e.getTimeZone=function(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(e){}},e.inBrowser=C,e.isExternalReferrer=q,e.isScriptLoaded=function(r){if(!C)return!0;var n=document.getElementsByTagName("script");return!!Object.keys(n).filter(function(e){var t=n[e].src;return"string"==typeof r?-1!==t.indexOf(r):r instanceof RegExp&&t.match(r)}).length},e.noOp=function(){},e.paramsClean=T,e.paramsGet=function(e,t){return R((RegExp("".concat(e,"=(.+?)(&|$)")).exec(t)||[,""])[1])},e.paramsParse=U,e.paramsRemove=function(o,i){return C?new Promise(function(e,t){if(window.history&&window.history.replaceState){var r=window.location.href,n=T(r,o);r!==n&&history.replaceState({},"",n)}return i&&i(),e()}):Promise.resolve()},e.parseReferrer=function(e,t){if(!C)return!1;var r={source:"(direct)",medium:"(none)",campaign:"(not set)"};e&&q(e)&&(r.referrer=e);var n=function(e){if(!e||!C)return!1;var t=B(e),r=document.createElement("a");if(r.href=e,-1<r.hostname.indexOf(J)&&(t=J),L[t]){var n=L[t],o="string"==typeof n?n:n.p,i=new RegExp(o+"=.*?([^&#]*|$)","gi"),a=r.search.match(i);return{source:n.n||F(t),medium:"organic",term:(a?a[0].split("=")[1]:"")||"(not provided)"}}var c=q(e)?"referral":"internal";return{source:r.hostname,medium:c}}(e);n&&Object.keys(n).length&&(r=Object.assign({},r,n));var o=U(t),i=Object.keys(o);if(!i.length)return r;var a=i.reduce(function(e,t){return t.match(/^utm_/)&&(e["".concat(t.replace(/^utm_/,""))]=o[t]),t.match(/^(d|g)clid/)&&(e.source=J,e.medium=o.gclid?"cpc":"cpm",e[t]=o[t]),e},{});return Object.assign({},r,a)},e.url=N,e.uuid=function(){for(var e="",t=0,r=4294967295*Math.random()|0;t++<36;){var n="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"[t-1],o=15&r;e+="-"==n||"4"==n?n:("x"==n?o:3&o|8).toString(16),r=t%8==0?4294967295*Math.random()|0:r>>4}return e},e.throttle=function(r,n){var o,i,a,c=null,u=0,f=function(){u=new Date,c=null,a=r.apply(o,i)};return function(){var e=new Date;u||(u=e);var t=n-(e-u);return o=this,i=arguments,t<=0?(clearTimeout(c),c=null,u=e,a=r.apply(o,i)):c||(c=setTimeout(f,t)),a}},e}({}); | ||
var analyticsUtils=function(e){"use strict";var r="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||void 0,c="undefined";function u(e){return r[e]}function l(e,t){return r[e]=t}function a(e){l(e)}var f=t(),s=n,g=n;function i(e){return f?n(e,"",-1):a(e)}function t(){if(typeof f!==c)return f;try{n(c,"1"),f=-1!==document.cookie.indexOf(c),i(c)}catch(e){f=!1}return f}function n(e,t,r,n,o,a){if(typeof window!==c){var i=1<arguments.length;return f||(i?l(e,t):u(e)),i?document.cookie=e+"="+encodeURIComponent(t)+(r?"; expires="+new Date(+new Date+1e3*r).toUTCString()+(n?"; path="+n:"")+(o?"; domain="+o:"")+(a?"; secure":""):""):decodeURIComponent((("; "+document.cookie).split("; "+e+"=")[1]||"").split(";")[0])}}var o=m();function m(){if(typeof o!==c)return o;o=!0;try{typeof localStorage!==c&&typeof JSON!==c||(o=!1),localStorage.setItem(c,c),localStorage.removeItem(c)}catch(e){o=!1}return o}function p(e){return void 0===e}function v(e){var t=e;try{if("true"===(t=JSON.parse(e)))return!0;if("false"===t)return!1;if(function(e){if("object"!=typeof e||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}(t))return t;parseFloat(t)===t&&(t=parseFloat(t))}catch(e){}if(null!==t&&""!==t)return t}var d=m(),y=t();function x(e,t){if(e){var r=b(t),n=!O(r),o=h(r)?v(localStorage.getItem(e)):void 0;if(n&&!p(o))return o;var a=S(r)?v(s(e)):void 0;if(n&&a)return a;var i=u(e);return n?i:{localStorage:o,cookie:a,global:i}}}function b(e){return e?"string"==typeof e?e:e.storage:"any"}function h(e){return d&&w(e,"localStorage")}function S(e){return y&&w(e,"cookie")}function O(e){return"*"===e||"all"===e}function w(e,t){return"any"===e||e===t||O(e)}var j={setItem:function(e,t,r){if(e&&!p(t)){var n={},o=b(r),a=JSON.stringify(t),i=!O(o);return h(o)&&(n.localStorage={location:"localStorage",current:t,previous:v(localStorage.getItem(e))},localStorage.setItem(e,a),i)?n.localStorage:S(o)&&(n.cookie={location:"cookie",current:t,previous:v(s(e))},g(e,a),i)?n.cookie:(n.global={location:"global",current:t,previous:u(e)},l(e,t),i?n.global:n)}},getItem:x,removeItem:function(e,t){if(e){var r=b(t),n=x(e,"*"),o={};return!p(n.localStorage)&&h(r)&&(localStorage.removeItem(e),o.localStorage=n.localStorage),!p(n.cookie)&&S(r)&&(i(e),o.cookie=n.cookie),!p(n.global)&&w(r,"global")&&(a(e),o.global=n.global),o}}};function k(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(e){return null}}var I="undefined"!=typeof document;function P(e){if(!I)return!1;var t=e||document.referrer;if(t){var r=window.document.location.port,n=t.split("/")[2];return r&&(n=n.replace(":".concat(r),"")),n!==window.location.hostname}return!1}function R(e,t){var r=(e.split("?")||[,])[1];if(!r||-1===r.indexOf(t))return e;var n=new RegExp("(\\&|\\?)".concat(t,'([_A-Za-z0-9"+=.\\/\\-@%]+)'),"g"),o="?".concat(r).replace(n,"").replace(/^&/,"?");return e.replace("?".concat(r),o)}function C(e){return function(e){var t,r={},n=/([^&=]+)=?([^&]*)/g;for(;t=n.exec(e);){var o=k(t[1]),a=k(t[2]);"[]"===o.substring(o.length-2)?(o=o.substring(0,o.length-2),(r[o]||(r[o]=[])).push(a)):r[o]=""===a||a}for(var i in r){var c=i.split("[");1<c.length&&(E(r,c.map(function(e){return e.replace(/[?[\]\\ ]/g,"")}),r[i]),delete r[i])}return r}(function(e){if(e){var t=e.match(/\?(.*)/);return t&&t[1]?t[1].split("#")[0]:""}return I&&window.location.search.substring(1)}(e))}function E(e,t,r){for(var n=t.length-1,o=0;o<n;++o){var a=t[o];a in e||(e[a]={}),e=e[a]}e[t[n]]=r}function D(e){if(!I)return null;var t=document.createElement("a");return t.setAttribute("href",e),t.hostname}function T(e){return(D(e)||"").split(".").slice(-2).join(".")}function U(e){var t=e.split(".");return 1<t.length?t.slice(0,-1).join("."):e}var A={trimTld:U,getDomainBase:T,getDomainHost:D},B="google";var F="q",N={"daum.net":F,"eniro.se":"search_word","naver.com":"query","yahoo.com":"p","msn.com":F,"aol.com":F,"ask.com":F,"baidu.com":"wd","yandex.com":"text","rambler.ru":"words",google:F,"bing.com":{p:F,n:"live"}};function _(e){return(_="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}return e.storage=j,e.getCookie=s,e.setCookie=g,e.globalContext=r,e.removeCookie=i,e.isFunction=function(e){return"function"==typeof e},e.isString=function(e){return"string"==typeof e},e.isArray=function(e){return Array.isArray(e)},e.isObject=function(e){if("object"!==_(e)||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t},e.isUndefined=function(e){return void 0===e},e.isBoolean=function(e){return"boolean"==typeof e},e.dotProp=function(e,t,r,n,o){for(t=t.split?t.split("."):t,n=0;n<t.length;n++)e=e?e[t[n]]:o;return e===o?r:e},e.decodeUri=k,e.getBrowserLocale=function(){if(I){var e=navigator,t=e.language,r=e.languages,n=e.userLanguage;return n||(r&&r.length?r[0]:t)}},e.getTimeZone=function(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(e){}},e.inBrowser=I,e.isExternalReferrer=P,e.isScriptLoaded=function(r){if(!I)return!0;var n=document.getElementsByTagName("script");return!!Object.keys(n).filter(function(e){var t=n[e].src;return"string"==typeof r?-1!==t.indexOf(r):r instanceof RegExp&&t.match(r)}).length},e.noOp=function(){},e.paramsClean=R,e.paramsGet=function(e,t){return k((RegExp("".concat(e,"=(.+?)(&|$)")).exec(t)||[,""])[1])},e.paramsParse=C,e.paramsRemove=function(o,a){return I?new Promise(function(e,t){if(window.history&&window.history.replaceState){var r=window.location.href,n=R(r,o);r!==n&&history.replaceState({},"",n)}return a&&a(),e()}):Promise.resolve()},e.parseReferrer=function(e,t){if(!I)return!1;var r={source:"(direct)",medium:"(none)",campaign:"(not set)"};e&&P(e)&&(r.referrer=e);var n=function(e){if(!e||!I)return!1;var t=T(e),r=document.createElement("a");if(r.href=e,-1<r.hostname.indexOf(B)&&(t=B),N[t]){var n=N[t],o="string"==typeof n?n:n.p,a=new RegExp(o+"=.*?([^&#]*|$)","gi"),i=r.search.match(a);return{source:n.n||U(t),medium:"organic",term:(i?i[0].split("=")[1]:"")||"(not provided)"}}var c=P(e)?"referral":"internal";return{source:r.hostname,medium:c}}(e);n&&Object.keys(n).length&&(r=Object.assign({},r,n));var o=C(t),a=Object.keys(o);if(!a.length)return r;var i=a.reduce(function(e,t){return t.match(/^utm_/)&&(e["".concat(t.replace(/^utm_/,""))]=o[t]),t.match(/^(d|g)clid/)&&(e.source=B,e.medium=o.gclid?"cpc":"cpm",e[t]=o[t]),e},{});return Object.assign({},r,i)},e.url=A,e.uuid=function(){for(var e="",t=0,r=4294967295*Math.random()|0;t++<36;){var n="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"[t-1],o=15&r;e+="-"==n||"4"==n?n:("x"==n?o:3&o|8).toString(16),r=t%8==0?4294967295*Math.random()|0:r>>4}return e},e.throttle=function(r,n){var o,a,i,c=null,u=0,l=function(){u=new Date,c=null,i=r.apply(o,a)};return function(){var e=new Date;u||(u=e);var t=n-(e-u);return o=this,a=arguments,t<=0?(clearTimeout(c),c=null,u=e,i=r.apply(o,a)):c||(c=setTimeout(l,t)),i}},e}({}); |
{ | ||
"name": "analytics-utils", | ||
"version": "0.4.7", | ||
"version": "0.4.8", | ||
"description": "Analytics utility functions used by 'analytics' module", | ||
@@ -69,3 +69,3 @@ "author": "David Wells <hello@davidwells.io>", | ||
"dependencies": { | ||
"@analytics/storage-utils": "^0.2.8", | ||
"@analytics/storage-utils": "^0.2.9", | ||
"dlv": "^1.1.3" | ||
@@ -76,3 +76,3 @@ }, | ||
}, | ||
"gitHead": "285f64dc43c4a332de48785c22a452dc6805f993" | ||
"gitHead": "73afae2f710821b7cec2c41d949aad4633f38afa" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96914
2651