New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

analytics-utils

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

analytics-utils - npm Package Compare versions

Comparing version

to
0.0.19

179

dist/analytics-utils.js
var analyticsUtils = (function (exports) {
'use strict';
var isInBrowser = typeof window !== 'undefined';
var inBrowser = typeof window !== 'undefined';

@@ -14,8 +14,9 @@ /**

try {
if (!isInBrowser) return false; // Try to set cookie
if (!inBrowser) return false;
var key = 'cookietest='; // Try to set cookie
document.cookie = 'cookietest=1';
var cookiesEnabled = document.cookie.indexOf('cookietest=') !== -1; // Cleanup cookie
document.cookie = "".concat(key, "1");
var cookiesEnabled = document.cookie.indexOf(key) !== -1; // Cleanup cookie
document.cookie = 'cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
document.cookie = "".concat(key, "1; expires=Thu, 01-Jan-1970 00:00:01 GMT");
return cookiesEnabled;

@@ -74,6 +75,3 @@ } catch (e) {

function getBrowserLocale() {
if (!isInBrowser) {
return null;
}
if (!inBrowser) return null;
var _navigator = navigator,

@@ -114,3 +112,3 @@ language = _navigator.language,

function isExternalReferrer(ref) {
if (!isInBrowser) return false;
if (!inBrowser) return false;
var referrer = ref || document.referrer;

@@ -132,4 +130,10 @@

/**
* Check if a script is loaded
* @param {String|RegExp} script - Script src as string or regex
* @return {Boolean} is script loaded
*/
function isScriptLoaded(script) {
if (!isInBrowser) return true;
if (!inBrowser) return true;
var scripts = document.getElementsByTagName('script');

@@ -159,3 +163,3 @@ return !!Object.keys(scripts).filter(function (key) {

var regex = new RegExp("(\\&|\\?)".concat(param, "([_A-Za-z0-9=.%]+)"), 'g');
var regex = new RegExp("(\\&|\\?)".concat(param, "([_A-Za-z0-9\"+=.%]+)"), 'g');
var cleanSearch = "?".concat(search).replace(regex, '').replace(/^&/, '?'); // replace search params with clean params

@@ -168,6 +172,19 @@

function getValueParamValue(name, string) {
return decode((RegExp("".concat(name, "=(.+?)(&|$)")).exec(string) || [, ''])[1]);
/**
* Get a given query parameter value
* @param {string} param - Key of parameter to find
* @param {string} url - url to search
* @return {string} match
*/
function getValueParamValue(param, url) {
return decode((RegExp("".concat(param, "=(.+?)(&|$)")).exec(url) || [, ''])[1]);
}
/**
* Get search string from given url
* @param {string} [url] - optional url string. If no url, window.location.search will be used
* @return {string} url search string
*/
function getSearchString(url) {

@@ -179,5 +196,11 @@ if (url) {

return isInBrowser && window.location.search.substring(1);
return inBrowser && window.location.search.substring(1);
}
/**
* Parse url parameters into javascript object
* @param {string} [url] - URI to parse. If no url supplied window.location will be used
* @return {object} parsed url parameters
*/
function paramsParse(url) {

@@ -248,4 +271,4 @@ var searchString = getSearchString(url);

* Removes params from url in browser
* @param {string} param - param string to remove
* @param {function} [callback] - callback function to run
* @param {string} param - param key to remove from current URL
* @param {function} [callback] - callback function to run. Only runs in browser
* @return {promise}

@@ -255,4 +278,5 @@ */

function paramsRemove(param, callback) {
if (!inBrowser) return Promise.resolve();
return new Promise(function (resolve, reject) {
if (isInBrowser && window.history && window.history.replaceState) {
if (window.history && window.history.replaceState) {
var url = window.location.href;

@@ -262,11 +286,9 @@ var cleanUrl = paramsClean(url, param);

if (url !== cleanUrl) {
// replace URL
history.replaceState({}, '', cleanUrl); // eslint-disable-line
/* replace URL with history API */
// eslint-disable-next-line no-restricted-globals
history.replaceState({}, '', cleanUrl);
}
}
if (callback) {
callback();
}
if (callback) callback();
return resolve();

@@ -287,3 +309,3 @@ });

function getDomainHost(url) {
if (!isInBrowser) return null;
if (!inBrowser) return null;
var a = document.createElement('a');

@@ -319,4 +341,3 @@ a.setAttribute('href', url);

return arr.length > 1 ? arr.slice(0, -1).join('.') : baseDomain;
} //*
}
var url = {

@@ -326,6 +347,5 @@ trimTld: trimTld,

getDomainHost: getDomainHost
/**/
};
var googleKey = 'google';
/**

@@ -339,3 +359,3 @@ * Checks a given url and parses referrer data

function parseReferrer(referrer, currentUrl) {
if (!isInBrowser) return false; // default referral data
if (!inBrowser) return false; // default referral data

@@ -375,3 +395,3 @@ var refData = {

if (key.match(/^(d|g)clid/)) {
acc['source'] = 'google';
acc['source'] = googleKey;
acc['medium'] = params.gclid ? 'cpc' : 'cpm';

@@ -386,3 +406,3 @@ acc[key] = params[key];

if (params.dclid || params.gclid) {
refData['source'] = 'google';
refData['source'] = googleKey;
refData['medium'] = params.gclid ? 'cpc' : 'cpm';

@@ -401,3 +421,3 @@ }

function parseDomain(referrer) {
if (!referrer || !isInBrowser) return false;
if (!referrer || !inBrowser) return false;
var referringDomain = getDomainBase(referrer);

@@ -407,4 +427,4 @@ var a = document.createElement('a');

if (a.hostname.indexOf('google') > -1) {
referringDomain = 'google';
if (a.hostname.indexOf(googleKey) > -1) {
referringDomain = googleKey;
} // If is search engine

@@ -479,10 +499,10 @@

function parse(result) {
function parse(input) {
var value;
try {
value = JSON.parse(result);
value = JSON.parse(input);
if (typeof value === 'undefined') {
value = result;
value = input;
}

@@ -502,3 +522,3 @@

} catch (e) {
value = result;
value = input;
}

@@ -509,18 +529,2 @@

function hasLocalStorage() {
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_test_', '1');
localStorage.removeItem('_test_');
} catch (err) {
return false;
}
return true;
}
// const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line

@@ -531,7 +535,10 @@ // (typeof global === 'object' && global.global === global && global) ||

// export default context
/* global self globalThis */
var getGlobal = function getGlobal() {
/* eslint-disable */
if (typeof self !== 'undefined' && self) {
return self;
}
/* istanbul ignore next */
/* eslint-enable */

@@ -554,3 +561,28 @@

/**
* Check if browser has access to LocalStorage
*
* @returns {Boolean}
*/
function hasLocalStorage() {
if (!inBrowser) return false;
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_test_', '1');
localStorage.removeItem('_test_');
} catch (err) {
return false;
}
return true;
}
var hasLocalStorage$1 = hasLocalStorage();
/**

@@ -570,3 +602,3 @@ * Get storage item from localStorage, cookie, or window

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
var value = localStorage.getItem(key);

@@ -578,3 +610,3 @@ if (value || storage === 'localStorage') return parse(value);

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
var _value = getCookie(key);

@@ -604,3 +636,3 @@

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
// console.log('SET as localstorage', saveValue)

@@ -619,3 +651,3 @@ var _oldValue = parse(localStorage.getItem(key));

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
// console.log('SET as cookie', saveValue)

@@ -656,3 +688,3 @@ var _oldValue2 = parse(getCookie(key));

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
localStorage.removeItem(key);

@@ -664,3 +696,3 @@ return null;

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
removeCookie(key);

@@ -675,2 +707,11 @@ return null;

}
function useLocal(storage) {
return hasLocalStorage$1 && (!storage || storage === 'localStorage');
}
function useCookie(storage) {
return cookiesSupported && (!storage || storage === 'cookie');
}
var index = {

@@ -690,6 +731,6 @@ getItem: getItem,

return function () {
var d0 = Math.random() * 0xffffffff | 0;
var d1 = Math.random() * 0xffffffff | 0;
var d2 = Math.random() * 0xffffffff | 0;
var d3 = Math.random() * 0xffffffff | 0;
var d0 = genNumber();
var d1 = genNumber();
var d2 = genNumber();
var d3 = genNumber();
/* eslint-disable */

@@ -702,2 +743,6 @@

function genNumber() {
return Math.random() * 0xffffffff | 0;
}
exports.cookie = cookie;

@@ -707,3 +752,3 @@ exports.decodeUri = decode;

exports.getTimeZone = getTimeZone;
exports.inBrowser = isInBrowser;
exports.inBrowser = inBrowser;
exports.isExternalReferrer = isExternalReferrer;

@@ -710,0 +755,0 @@ exports.isScriptLoaded = isScriptLoaded;

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

var analyticsUtils=function(e){"use strict";var u="undefined"!=typeof window;var l=function(){try{if(!u)return!1;document.cookie="cookietest=1";var e=-1!==document.cookie.indexOf("cookietest=");return document.cookie="cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT",e}catch(e){return!1}}();function f(e,t,r){if(!l)return!1;var n="";if(r){var o=new Date;o.setTime(o.getTime()+24*r*60*60*1e3),n="; expires=".concat(o.toGMTString())}document.cookie="".concat(e,"=").concat(t).concat(n,"; path=/")}function s(e){if(!l)return!1;for(var t="".concat(e,"="),r=document.cookie.split(";"),n=0;n<r.length;n++){for(var o=r[n];" "===o.charAt(0);)o=o.substring(1,o.length);if(0===o.indexOf(t))return o.substring(t.length,o.length)}return null}function n(e){if(!l)return!1;f(e,"",-1)}var t={getCookie:s,setCookie:f,removeCookie:n};function m(e){return decodeURIComponent(e).replace(/\+/g," ")}function g(e){if(!u)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 c(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 i(e){var t=function(e){if(e){var t=e.match(/\?(.*)/);return t&&t[1]?t[1].split("#")[0]:""}return u&&window.location.search.substring(1)}(e);return t?function(e){var t,r=/([^&=]+)=?([^&]*)/g,n={};for(;t=r.exec(e);){var o=m(t[1]),a=m(t[2]);if("[]"===o.substring(o.length-2))o=o.substring(0,o.length-2),(n[o]||(n[o]=[])).push(a);else{var c=""===a||a;n[o]=c}}for(var i in n){var u=i.split("[");if(1<u.length){var l=[];u.forEach(function(e,t){var r=e.replace(/[?[\]\\ ]/g,"");l.push(r)}),d(n,l,n[i]),delete n[i]}}return n}(t):{}}function d(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 r(e){if(!u)return null;var t=document.createElement("a");return t.setAttribute("href",e),t.hostname}function v(e){return(r(e)||"").split(".").slice(-2).join(".")}function p(e){var t=e.split(".");return 1<t.length?t.slice(0,-1).join("."):e}var o={trimTld:p,getDomainBase:v,getDomainHost:r};var h={"daum.net":"q","eniro.se":"search_word","naver.com":"query","yahoo.com":"p","msn.com":"q","aol.com":"q","lycos.com":"q","ask.com":"q","cnn.com":"query","about.com":"terms","baidu.com":"wd","yandex.com":"text","seznam.cz":"q","search.com":"q","yam.com":"k","kvasir.no":"q","terra.com":"query","mynet.com":"q","rambler.ru":"words",google:"q","bing.com":{p:"q",n:"live"}};function a(e){return(a="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){var r;try{void 0===(r=JSON.parse(t))&&(r=t),"true"===r&&(r=!0),"false"===r&&(r=!1),parseFloat(r)===r&&"object"!==a(r)&&(r=parseFloat(r))}catch(e){r=t}return r}var w="undefined"!=typeof self&&self?self:"undefined"!=typeof window&&window?window:"undefined"!=typeof global&&global?global:"undefined"!=typeof globalThis&&globalThis?globalThis:void 0,b=function(){try{if("undefined"==typeof localStorage||"undefined"==typeof JSON)return!1;localStorage.setItem("_test_","1"),localStorage.removeItem("_test_")}catch(e){return!1}return!0}();var S={getItem:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!e)return null;var r=t.storage;if(b&&(!r||"localStorage"===r)){var n=localStorage.getItem(e);if(n||"localStorage"===r)return y(n)}if(l&&(!r||"cookie"===r)){var o=s(e);if(o||"cookie"===r)return y(o)}return w[e]||null},setItem:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(!e||!t)return!1;var n=r.storage,o=JSON.stringify(t);if(b&&(!n||"localStorage"===n)){var a=y(localStorage.getItem(e));return localStorage.setItem(e,o),{value:t,oldValue:a,type:"localStorage"}}if(l&&(!n||"cookie"===n)){var c=y(s(e));return f(e,o),{value:t,oldValue:c,type:"cookie"}}var i=w[e];return{value:w[e]=t,oldValue:i,type:"window"}},removeItem:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!e)return!1;var r=t.storage;return!b||r&&"localStorage"!==r?!l||r&&"cookie"!==r?w[e]=null:(n(e),null):(localStorage.removeItem(e),null)}};return e.cookie=t,e.decodeUri=m,e.getBrowserLocale=function(){if(!u)return null;var e=navigator,t=e.language,r=e.languages,n=e.userLanguage;return r&&r.length?r[0]:n||t},e.getTimeZone=function(){return"undefined"==typeof Intl||"function"!=typeof Intl.DateTimeFormat||"function"!=typeof Intl.DateTimeFormat().resolvedOptions?null:Intl.DateTimeFormat().resolvedOptions().timeZone},e.inBrowser=u,e.isExternalReferrer=g,e.isScriptLoaded=function(r){if(!u)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=c,e.paramsGet=function(e,t){return m((RegExp("".concat(e,"=(.+?)(&|$)")).exec(t)||[,""])[1])},e.paramsParse=i,e.paramsRemove=function(o,a){return new Promise(function(e,t){if(u&&window.history&&window.history.replaceState){var r=window.location.href,n=c(r,o);r!==n&&history.replaceState({},"",n)}return a&&a(),e()})},e.parseReferrer=function(e,t){if(!u)return!1;var r={source:"(direct)",medium:"(none)",campaign:"(not set)"};e&&g(e)&&(r.referrer=e);var n=function(e){if(!e||!u)return!1;var t=v(e),r=document.createElement("a");if(r.href=e,-1<r.hostname.indexOf("google")&&(t="google"),h[t]){var n=h[t],o="string"==typeof n?n:n.p,a=new RegExp(o+"=.*?([^&#]*|$)","gi"),c=r.search.match(a);return{source:n.n||p(t),medium:"organic",term:(c?c[0].split("=")[1]:"")||"(not provided)"}}var i=g(e)?"referral":"internal";return{source:r.hostname,medium:i}}(e);n&&Object.keys(n).length&&(r=Object.assign({},r,n));var o=i(t),a=Object.keys(o);if(a.length){var c=a.reduce(function(e,t){return t.match(/^utm_/)&&(e["".concat(t.replace(/^utm_/,""))]=o[t]),t.match(/^(d|g)clid/)&&(e.source="google",e.medium=o.gclid?"cpc":"cpm",e[t]=o[t]),e},{});r=Object.assign({},r,c),(o.dclid||o.gclid)&&(r.source="google",r.medium=o.gclid?"cpc":"cpm")}return r},e.storage=S,e.url=o,e.uuid=function(){for(var e,t,r,n,o=[],a=0;a<256;a++)o[a]=(a<16?"0":"")+a.toString(16);return e=4294967295*Math.random()|0,t=4294967295*Math.random()|0,r=4294967295*Math.random()|0,n=4294967295*Math.random()|0,"".concat(o[255&e]+o[e>>8&255]+o[e>>16&255]+o[e>>24&255],"-").concat(o[255&t]).concat(o[t>>8&255],"-").concat(o[t>>16&15|64]).concat(o[t>>24&255],"-").concat(o[63&r|128]).concat(o[r>>8&255],"-").concat(o[r>>16&255]).concat(o[r>>24&255]).concat(o[255&n]).concat(o[n>>8&255]).concat(o[n>>16&255]).concat(o[n>>24&255])},e.globalContext=w,e}({});
var analyticsUtils=function(e){"use strict";var u="undefined"!=typeof window;var a=function(){try{if(!u)return!1;var e="cookietest=";document.cookie="".concat(e,"1");var t=-1!==document.cookie.indexOf(e);return document.cookie="".concat(e,"1; expires=Thu, 01-Jan-1970 00:00:01 GMT"),t}catch(e){return!1}}();function l(e,t,r){if(!a)return!1;var n="";if(r){var o=new Date;o.setTime(o.getTime()+24*r*60*60*1e3),n="; expires=".concat(o.toGMTString())}document.cookie="".concat(e,"=").concat(t).concat(n,"; path=/")}function f(e){if(!a)return!1;for(var t="".concat(e,"="),r=document.cookie.split(";"),n=0;n<r.length;n++){for(var o=r[n];" "===o.charAt(0);)o=o.substring(1,o.length);if(0===o.indexOf(t))return o.substring(t.length,o.length)}return null}function n(e){if(!a)return!1;l(e,"",-1)}var t={getCookie:f,setCookie:l,removeCookie:n};function s(e){return decodeURIComponent(e).replace(/\+/g," ")}function m(e){if(!u)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 c(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 i(e){var t=function(e){if(e){var t=e.match(/\?(.*)/);return t&&t[1]?t[1].split("#")[0]:""}return u&&window.location.search.substring(1)}(e);return t?function(e){var t,r=/([^&=]+)=?([^&]*)/g,n={};for(;t=r.exec(e);){var o=s(t[1]),a=s(t[2]);if("[]"===o.substring(o.length-2))o=o.substring(0,o.length-2),(n[o]||(n[o]=[])).push(a);else{var c=""===a||a;n[o]=c}}for(var i in n){var u=i.split("[");if(1<u.length){var l=[];u.forEach(function(e,t){var r=e.replace(/[?[\]\\ ]/g,"");l.push(r)}),g(n,l,n[i]),delete n[i]}}return n}(t):{}}function g(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 r(e){if(!u)return null;var t=document.createElement("a");return t.setAttribute("href",e),t.hostname}function d(e){return(r(e)||"").split(".").slice(-2).join(".")}function v(e){var t=e.split(".");return 1<t.length?t.slice(0,-1).join("."):e}var o={trimTld:v,getDomainBase:d,getDomainHost:r},p="google";var h={"daum.net":"q","eniro.se":"search_word","naver.com":"query","yahoo.com":"p","msn.com":"q","aol.com":"q","lycos.com":"q","ask.com":"q","cnn.com":"query","about.com":"terms","baidu.com":"wd","yandex.com":"text","seznam.cz":"q","search.com":"q","yam.com":"k","kvasir.no":"q","terra.com":"query","mynet.com":"q","rambler.ru":"words",google:"q","bing.com":{p:"q",n:"live"}};function y(e){return(y="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 w(t){var r;try{void 0===(r=JSON.parse(t))&&(r=t),"true"===r&&(r=!0),"false"===r&&(r=!1),parseFloat(r)===r&&"object"!==y(r)&&(r=parseFloat(r))}catch(e){r=t}return r}var b="undefined"!=typeof self&&self?self:"undefined"!=typeof window&&window?window:"undefined"!=typeof global&&global?global:"undefined"!=typeof globalThis&&globalThis?globalThis:void 0;var S=function(){if(!u)return!1;try{if("undefined"==typeof localStorage||"undefined"==typeof JSON)return!1;localStorage.setItem("_test_","1"),localStorage.removeItem("_test_")}catch(e){return!1}return!0}();function k(e){return S&&(!e||"localStorage"===e)}function x(e){return a&&(!e||"cookie"===e)}var O={getItem:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!e)return null;var r=t.storage;if(k(r)){var n=localStorage.getItem(e);if(n||"localStorage"===r)return w(n)}if(x(r)){var o=f(e);if(o||"cookie"===r)return w(o)}return b[e]||null},setItem:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(!e||!t)return!1;var n=r.storage,o=JSON.stringify(t);if(k(n)){var a=w(localStorage.getItem(e));return localStorage.setItem(e,o),{value:t,oldValue:a,type:"localStorage"}}if(x(n)){var c=w(f(e));return l(e,o),{value:t,oldValue:c,type:"cookie"}}var i=b[e];return{value:b[e]=t,oldValue:i,type:"window"}},removeItem:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!e)return!1;var r=t.storage;return k(r)?(localStorage.removeItem(e),null):x(r)?(n(e),null):b[e]=null}};function q(){return 4294967295*Math.random()|0}return e.cookie=t,e.decodeUri=s,e.getBrowserLocale=function(){if(!u)return null;var e=navigator,t=e.language,r=e.languages,n=e.userLanguage;return r&&r.length?r[0]:n||t},e.getTimeZone=function(){return"undefined"==typeof Intl||"function"!=typeof Intl.DateTimeFormat||"function"!=typeof Intl.DateTimeFormat().resolvedOptions?null:Intl.DateTimeFormat().resolvedOptions().timeZone},e.inBrowser=u,e.isExternalReferrer=m,e.isScriptLoaded=function(r){if(!u)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=c,e.paramsGet=function(e,t){return s((RegExp("".concat(e,"=(.+?)(&|$)")).exec(t)||[,""])[1])},e.paramsParse=i,e.paramsRemove=function(o,a){return u?new Promise(function(e,t){if(window.history&&window.history.replaceState){var r=window.location.href,n=c(r,o);r!==n&&history.replaceState({},"",n)}return a&&a(),e()}):Promise.resolve()},e.parseReferrer=function(e,t){if(!u)return!1;var r={source:"(direct)",medium:"(none)",campaign:"(not set)"};e&&m(e)&&(r.referrer=e);var n=function(e){if(!e||!u)return!1;var t=d(e),r=document.createElement("a");if(r.href=e,-1<r.hostname.indexOf(p)&&(t=p),h[t]){var n=h[t],o="string"==typeof n?n:n.p,a=new RegExp(o+"=.*?([^&#]*|$)","gi"),c=r.search.match(a);return{source:n.n||v(t),medium:"organic",term:(c?c[0].split("=")[1]:"")||"(not provided)"}}var i=m(e)?"referral":"internal";return{source:r.hostname,medium:i}}(e);n&&Object.keys(n).length&&(r=Object.assign({},r,n));var o=i(t),a=Object.keys(o);if(a.length){var c=a.reduce(function(e,t){return t.match(/^utm_/)&&(e["".concat(t.replace(/^utm_/,""))]=o[t]),t.match(/^(d|g)clid/)&&(e.source=p,e.medium=o.gclid?"cpc":"cpm",e[t]=o[t]),e},{});r=Object.assign({},r,c),(o.dclid||o.gclid)&&(r.source=p,r.medium=o.gclid?"cpc":"cpm")}return r},e.storage=O,e.url=o,e.uuid=function(){for(var e,t,r,n,o=[],a=0;a<256;a++)o[a]=(a<16?"0":"")+a.toString(16);return e=q(),t=q(),r=q(),n=q(),"".concat(o[255&e]+o[e>>8&255]+o[e>>16&255]+o[e>>24&255],"-").concat(o[255&t]).concat(o[t>>8&255],"-").concat(o[t>>16&15|64]).concat(o[t>>24&255],"-").concat(o[63&r|128]).concat(o[r>>8&255],"-").concat(o[r>>16&255]).concat(o[r>>24&255]).concat(o[255&n]).concat(o[n>>8&255]).concat(o[n>>16&255]).concat(o[n>>24&255])},e.globalContext=b,e}({});

@@ -5,3 +5,3 @@ 'use strict';

var isInBrowser = typeof window !== 'undefined';
var inBrowser = typeof window !== 'undefined';

@@ -16,8 +16,9 @@ /**

try {
if (!isInBrowser) return false; // Try to set cookie
if (!inBrowser) return false;
var key = 'cookietest='; // Try to set cookie
document.cookie = 'cookietest=1';
var cookiesEnabled = document.cookie.indexOf('cookietest=') !== -1; // Cleanup cookie
document.cookie = "".concat(key, "1");
var cookiesEnabled = document.cookie.indexOf(key) !== -1; // Cleanup cookie
document.cookie = 'cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
document.cookie = "".concat(key, "1; expires=Thu, 01-Jan-1970 00:00:01 GMT");
return cookiesEnabled;

@@ -76,6 +77,3 @@ } catch (e) {

function getBrowserLocale() {
if (!isInBrowser) {
return null;
}
if (!inBrowser) return null;
var _navigator = navigator,

@@ -116,3 +114,3 @@ language = _navigator.language,

function isExternalReferrer(ref) {
if (!isInBrowser) return false;
if (!inBrowser) return false;
var referrer = ref || document.referrer;

@@ -134,4 +132,10 @@

/**
* Check if a script is loaded
* @param {String|RegExp} script - Script src as string or regex
* @return {Boolean} is script loaded
*/
function isScriptLoaded(script) {
if (!isInBrowser) return true;
if (!inBrowser) return true;
var scripts = document.getElementsByTagName('script');

@@ -161,3 +165,3 @@ return !!Object.keys(scripts).filter(function (key) {

var regex = new RegExp("(\\&|\\?)".concat(param, "([_A-Za-z0-9=.%]+)"), 'g');
var regex = new RegExp("(\\&|\\?)".concat(param, "([_A-Za-z0-9\"+=.%]+)"), 'g');
var cleanSearch = "?".concat(search).replace(regex, '').replace(/^&/, '?'); // replace search params with clean params

@@ -170,6 +174,19 @@

function getValueParamValue(name, string) {
return decode((RegExp("".concat(name, "=(.+?)(&|$)")).exec(string) || [, ''])[1]);
/**
* Get a given query parameter value
* @param {string} param - Key of parameter to find
* @param {string} url - url to search
* @return {string} match
*/
function getValueParamValue(param, url) {
return decode((RegExp("".concat(param, "=(.+?)(&|$)")).exec(url) || [, ''])[1]);
}
/**
* Get search string from given url
* @param {string} [url] - optional url string. If no url, window.location.search will be used
* @return {string} url search string
*/
function getSearchString(url) {

@@ -181,5 +198,11 @@ if (url) {

return isInBrowser && window.location.search.substring(1);
return inBrowser && window.location.search.substring(1);
}
/**
* Parse url parameters into javascript object
* @param {string} [url] - URI to parse. If no url supplied window.location will be used
* @return {object} parsed url parameters
*/
function paramsParse(url) {

@@ -250,4 +273,4 @@ var searchString = getSearchString(url);

* Removes params from url in browser
* @param {string} param - param string to remove
* @param {function} [callback] - callback function to run
* @param {string} param - param key to remove from current URL
* @param {function} [callback] - callback function to run. Only runs in browser
* @return {promise}

@@ -257,4 +280,5 @@ */

function paramsRemove(param, callback) {
if (!inBrowser) return Promise.resolve();
return new Promise(function (resolve, reject) {
if (isInBrowser && window.history && window.history.replaceState) {
if (window.history && window.history.replaceState) {
var url = window.location.href;

@@ -264,11 +288,9 @@ var cleanUrl = paramsClean(url, param);

if (url !== cleanUrl) {
// replace URL
history.replaceState({}, '', cleanUrl); // eslint-disable-line
/* replace URL with history API */
// eslint-disable-next-line no-restricted-globals
history.replaceState({}, '', cleanUrl);
}
}
if (callback) {
callback();
}
if (callback) callback();
return resolve();

@@ -289,3 +311,3 @@ });

function getDomainHost(url) {
if (!isInBrowser) return null;
if (!inBrowser) return null;
var a = document.createElement('a');

@@ -321,4 +343,3 @@ a.setAttribute('href', url);

return arr.length > 1 ? arr.slice(0, -1).join('.') : baseDomain;
} //*
}
var url = {

@@ -328,6 +349,5 @@ trimTld: trimTld,

getDomainHost: getDomainHost
/**/
};
var googleKey = 'google';
/**

@@ -341,3 +361,3 @@ * Checks a given url and parses referrer data

function parseReferrer(referrer, currentUrl) {
if (!isInBrowser) return false; // default referral data
if (!inBrowser) return false; // default referral data

@@ -377,3 +397,3 @@ var refData = {

if (key.match(/^(d|g)clid/)) {
acc['source'] = 'google';
acc['source'] = googleKey;
acc['medium'] = params.gclid ? 'cpc' : 'cpm';

@@ -388,3 +408,3 @@ acc[key] = params[key];

if (params.dclid || params.gclid) {
refData['source'] = 'google';
refData['source'] = googleKey;
refData['medium'] = params.gclid ? 'cpc' : 'cpm';

@@ -403,3 +423,3 @@ }

function parseDomain(referrer) {
if (!referrer || !isInBrowser) return false;
if (!referrer || !inBrowser) return false;
var referringDomain = getDomainBase(referrer);

@@ -409,4 +429,4 @@ var a = document.createElement('a');

if (a.hostname.indexOf('google') > -1) {
referringDomain = 'google';
if (a.hostname.indexOf(googleKey) > -1) {
referringDomain = googleKey;
} // If is search engine

@@ -481,10 +501,10 @@

function parse(result) {
function parse(input) {
var value;
try {
value = JSON.parse(result);
value = JSON.parse(input);
if (typeof value === 'undefined') {
value = result;
value = input;
}

@@ -504,3 +524,3 @@

} catch (e) {
value = result;
value = input;
}

@@ -511,18 +531,2 @@

function hasLocalStorage() {
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_test_', '1');
localStorage.removeItem('_test_');
} catch (err) {
return false;
}
return true;
}
// const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line

@@ -533,7 +537,10 @@ // (typeof global === 'object' && global.global === global && global) ||

// export default context
/* global self globalThis */
var getGlobal = function getGlobal() {
/* eslint-disable */
if (typeof self !== 'undefined' && self) {
return self;
}
/* istanbul ignore next */
/* eslint-enable */

@@ -556,3 +563,28 @@

/**
* Check if browser has access to LocalStorage
*
* @returns {Boolean}
*/
function hasLocalStorage() {
if (!inBrowser) return false;
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_test_', '1');
localStorage.removeItem('_test_');
} catch (err) {
return false;
}
return true;
}
var hasLocalStorage$1 = hasLocalStorage();
/**

@@ -572,3 +604,3 @@ * Get storage item from localStorage, cookie, or window

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
var value = localStorage.getItem(key);

@@ -580,3 +612,3 @@ if (value || storage === 'localStorage') return parse(value);

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
var _value = getCookie(key);

@@ -606,3 +638,3 @@

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
// console.log('SET as localstorage', saveValue)

@@ -621,3 +653,3 @@ var _oldValue = parse(localStorage.getItem(key));

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
// console.log('SET as cookie', saveValue)

@@ -658,3 +690,3 @@ var _oldValue2 = parse(getCookie(key));

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
localStorage.removeItem(key);

@@ -666,3 +698,3 @@ return null;

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
removeCookie(key);

@@ -677,2 +709,11 @@ return null;

}
function useLocal(storage) {
return hasLocalStorage$1 && (!storage || storage === 'localStorage');
}
function useCookie(storage) {
return cookiesSupported && (!storage || storage === 'cookie');
}
var index = {

@@ -692,6 +733,6 @@ getItem: getItem,

return function () {
var d0 = Math.random() * 0xffffffff | 0;
var d1 = Math.random() * 0xffffffff | 0;
var d2 = Math.random() * 0xffffffff | 0;
var d3 = Math.random() * 0xffffffff | 0;
var d0 = genNumber();
var d1 = genNumber();
var d2 = genNumber();
var d3 = genNumber();
/* eslint-disable */

@@ -704,2 +745,6 @@

function genNumber() {
return Math.random() * 0xffffffff | 0;
}
exports.cookie = cookie;

@@ -709,3 +754,3 @@ exports.decodeUri = decode;

exports.getTimeZone = getTimeZone;
exports.inBrowser = isInBrowser;
exports.inBrowser = inBrowser;
exports.isExternalReferrer = isExternalReferrer;

@@ -712,0 +757,0 @@ exports.isScriptLoaded = isScriptLoaded;

@@ -1,2 +0,2 @@

var isInBrowser = typeof window !== 'undefined';
var inBrowser = typeof window !== 'undefined';

@@ -11,8 +11,9 @@ /**

try {
if (!isInBrowser) return false; // Try to set cookie
if (!inBrowser) return false;
var key = 'cookietest='; // Try to set cookie
document.cookie = 'cookietest=1';
var cookiesEnabled = document.cookie.indexOf('cookietest=') !== -1; // Cleanup cookie
document.cookie = "".concat(key, "1");
var cookiesEnabled = document.cookie.indexOf(key) !== -1; // Cleanup cookie
document.cookie = 'cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
document.cookie = "".concat(key, "1; expires=Thu, 01-Jan-1970 00:00:01 GMT");
return cookiesEnabled;

@@ -71,6 +72,3 @@ } catch (e) {

function getBrowserLocale() {
if (!isInBrowser) {
return null;
}
if (!inBrowser) return null;
var _navigator = navigator,

@@ -111,3 +109,3 @@ language = _navigator.language,

function isExternalReferrer(ref) {
if (!isInBrowser) return false;
if (!inBrowser) return false;
var referrer = ref || document.referrer;

@@ -129,4 +127,10 @@

/**
* Check if a script is loaded
* @param {String|RegExp} script - Script src as string or regex
* @return {Boolean} is script loaded
*/
function isScriptLoaded(script) {
if (!isInBrowser) return true;
if (!inBrowser) return true;
var scripts = document.getElementsByTagName('script');

@@ -156,3 +160,3 @@ return !!Object.keys(scripts).filter(function (key) {

var regex = new RegExp("(\\&|\\?)".concat(param, "([_A-Za-z0-9=.%]+)"), 'g');
var regex = new RegExp("(\\&|\\?)".concat(param, "([_A-Za-z0-9\"+=.%]+)"), 'g');
var cleanSearch = "?".concat(search).replace(regex, '').replace(/^&/, '?'); // replace search params with clean params

@@ -165,6 +169,19 @@

function getValueParamValue(name, string) {
return decode((RegExp("".concat(name, "=(.+?)(&|$)")).exec(string) || [, ''])[1]);
/**
* Get a given query parameter value
* @param {string} param - Key of parameter to find
* @param {string} url - url to search
* @return {string} match
*/
function getValueParamValue(param, url) {
return decode((RegExp("".concat(param, "=(.+?)(&|$)")).exec(url) || [, ''])[1]);
}
/**
* Get search string from given url
* @param {string} [url] - optional url string. If no url, window.location.search will be used
* @return {string} url search string
*/
function getSearchString(url) {

@@ -176,5 +193,11 @@ if (url) {

return isInBrowser && window.location.search.substring(1);
return inBrowser && window.location.search.substring(1);
}
/**
* Parse url parameters into javascript object
* @param {string} [url] - URI to parse. If no url supplied window.location will be used
* @return {object} parsed url parameters
*/
function paramsParse(url) {

@@ -245,4 +268,4 @@ var searchString = getSearchString(url);

* Removes params from url in browser
* @param {string} param - param string to remove
* @param {function} [callback] - callback function to run
* @param {string} param - param key to remove from current URL
* @param {function} [callback] - callback function to run. Only runs in browser
* @return {promise}

@@ -252,4 +275,5 @@ */

function paramsRemove(param, callback) {
if (!inBrowser) return Promise.resolve();
return new Promise(function (resolve, reject) {
if (isInBrowser && window.history && window.history.replaceState) {
if (window.history && window.history.replaceState) {
var url = window.location.href;

@@ -259,11 +283,9 @@ var cleanUrl = paramsClean(url, param);

if (url !== cleanUrl) {
// replace URL
history.replaceState({}, '', cleanUrl); // eslint-disable-line
/* replace URL with history API */
// eslint-disable-next-line no-restricted-globals
history.replaceState({}, '', cleanUrl);
}
}
if (callback) {
callback();
}
if (callback) callback();
return resolve();

@@ -284,3 +306,3 @@ });

function getDomainHost(url) {
if (!isInBrowser) return null;
if (!inBrowser) return null;
var a = document.createElement('a');

@@ -316,4 +338,3 @@ a.setAttribute('href', url);

return arr.length > 1 ? arr.slice(0, -1).join('.') : baseDomain;
} //*
}
var url = {

@@ -323,6 +344,5 @@ trimTld: trimTld,

getDomainHost: getDomainHost
/**/
};
var googleKey = 'google';
/**

@@ -336,3 +356,3 @@ * Checks a given url and parses referrer data

function parseReferrer(referrer, currentUrl) {
if (!isInBrowser) return false; // default referral data
if (!inBrowser) return false; // default referral data

@@ -372,3 +392,3 @@ var refData = {

if (key.match(/^(d|g)clid/)) {
acc['source'] = 'google';
acc['source'] = googleKey;
acc['medium'] = params.gclid ? 'cpc' : 'cpm';

@@ -383,3 +403,3 @@ acc[key] = params[key];

if (params.dclid || params.gclid) {
refData['source'] = 'google';
refData['source'] = googleKey;
refData['medium'] = params.gclid ? 'cpc' : 'cpm';

@@ -398,3 +418,3 @@ }

function parseDomain(referrer) {
if (!referrer || !isInBrowser) return false;
if (!referrer || !inBrowser) return false;
var referringDomain = getDomainBase(referrer);

@@ -404,4 +424,4 @@ var a = document.createElement('a');

if (a.hostname.indexOf('google') > -1) {
referringDomain = 'google';
if (a.hostname.indexOf(googleKey) > -1) {
referringDomain = googleKey;
} // If is search engine

@@ -476,10 +496,10 @@

function parse(result) {
function parse(input) {
var value;
try {
value = JSON.parse(result);
value = JSON.parse(input);
if (typeof value === 'undefined') {
value = result;
value = input;
}

@@ -499,3 +519,3 @@

} catch (e) {
value = result;
value = input;
}

@@ -506,18 +526,2 @@

function hasLocalStorage() {
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_test_', '1');
localStorage.removeItem('_test_');
} catch (err) {
return false;
}
return true;
}
// const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line

@@ -528,7 +532,10 @@ // (typeof global === 'object' && global.global === global && global) ||

// export default context
/* global self globalThis */
var getGlobal = function getGlobal() {
/* eslint-disable */
if (typeof self !== 'undefined' && self) {
return self;
}
/* istanbul ignore next */
/* eslint-enable */

@@ -551,3 +558,28 @@

/**
* Check if browser has access to LocalStorage
*
* @returns {Boolean}
*/
function hasLocalStorage() {
if (!inBrowser) return false;
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_test_', '1');
localStorage.removeItem('_test_');
} catch (err) {
return false;
}
return true;
}
var hasLocalStorage$1 = hasLocalStorage();
/**

@@ -567,3 +599,3 @@ * Get storage item from localStorage, cookie, or window

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
var value = localStorage.getItem(key);

@@ -575,3 +607,3 @@ if (value || storage === 'localStorage') return parse(value);

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
var _value = getCookie(key);

@@ -601,3 +633,3 @@

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
// console.log('SET as localstorage', saveValue)

@@ -616,3 +648,3 @@ var _oldValue = parse(localStorage.getItem(key));

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
// console.log('SET as cookie', saveValue)

@@ -653,3 +685,3 @@ var _oldValue2 = parse(getCookie(key));

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
localStorage.removeItem(key);

@@ -661,3 +693,3 @@ return null;

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
removeCookie(key);

@@ -672,2 +704,11 @@ return null;

}
function useLocal(storage) {
return hasLocalStorage$1 && (!storage || storage === 'localStorage');
}
function useCookie(storage) {
return cookiesSupported && (!storage || storage === 'cookie');
}
var index = {

@@ -687,6 +728,6 @@ getItem: getItem,

return function () {
var d0 = Math.random() * 0xffffffff | 0;
var d1 = Math.random() * 0xffffffff | 0;
var d2 = Math.random() * 0xffffffff | 0;
var d3 = Math.random() * 0xffffffff | 0;
var d0 = genNumber();
var d1 = genNumber();
var d2 = genNumber();
var d3 = genNumber();
/* eslint-disable */

@@ -699,2 +740,6 @@

export { cookie, decode as decodeUri, getBrowserLocale, getTimeZone, isInBrowser as inBrowser, isExternalReferrer, isScriptLoaded, noOp, paramsClean, getValueParamValue as paramsGet, paramsParse, paramsRemove, parseReferrer, index as storage, url, uuid, globalContext };
function genNumber() {
return Math.random() * 0xffffffff | 0;
}
export { cookie, decode as decodeUri, getBrowserLocale, getTimeZone, inBrowser, isExternalReferrer, isScriptLoaded, noOp, paramsClean, getValueParamValue as paramsGet, paramsParse, paramsRemove, parseReferrer, index as storage, url, uuid, globalContext };

@@ -5,3 +5,3 @@ 'use strict';

var isInBrowser = typeof window !== 'undefined';
var inBrowser = typeof window !== 'undefined';

@@ -16,8 +16,9 @@ /**

try {
if (!isInBrowser) return false; // Try to set cookie
if (!inBrowser) return false;
var key = 'cookietest='; // Try to set cookie
document.cookie = 'cookietest=1';
var cookiesEnabled = document.cookie.indexOf('cookietest=') !== -1; // Cleanup cookie
document.cookie = "".concat(key, "1");
var cookiesEnabled = document.cookie.indexOf(key) !== -1; // Cleanup cookie
document.cookie = 'cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
document.cookie = "".concat(key, "1; expires=Thu, 01-Jan-1970 00:00:01 GMT");
return cookiesEnabled;

@@ -76,6 +77,3 @@ } catch (e) {

function getBrowserLocale() {
if (!isInBrowser) {
return null;
}
if (!inBrowser) return null;
var _navigator = navigator,

@@ -116,3 +114,3 @@ language = _navigator.language,

function isExternalReferrer(ref) {
if (!isInBrowser) return false;
if (!inBrowser) return false;
var referrer = ref || document.referrer;

@@ -134,4 +132,10 @@

/**
* Check if a script is loaded
* @param {String|RegExp} script - Script src as string or regex
* @return {Boolean} is script loaded
*/
function isScriptLoaded(script) {
if (!isInBrowser) return true;
if (!inBrowser) return true;
var scripts = document.getElementsByTagName('script');

@@ -161,3 +165,3 @@ return !!Object.keys(scripts).filter(function (key) {

var regex = new RegExp("(\\&|\\?)".concat(param, "([_A-Za-z0-9=.%]+)"), 'g');
var regex = new RegExp("(\\&|\\?)".concat(param, "([_A-Za-z0-9\"+=.%]+)"), 'g');
var cleanSearch = "?".concat(search).replace(regex, '').replace(/^&/, '?'); // replace search params with clean params

@@ -170,6 +174,19 @@

function getValueParamValue(name, string) {
return decode((RegExp("".concat(name, "=(.+?)(&|$)")).exec(string) || [, ''])[1]);
/**
* Get a given query parameter value
* @param {string} param - Key of parameter to find
* @param {string} url - url to search
* @return {string} match
*/
function getValueParamValue(param, url) {
return decode((RegExp("".concat(param, "=(.+?)(&|$)")).exec(url) || [, ''])[1]);
}
/**
* Get search string from given url
* @param {string} [url] - optional url string. If no url, window.location.search will be used
* @return {string} url search string
*/
function getSearchString(url) {

@@ -181,5 +198,11 @@ if (url) {

return isInBrowser && window.location.search.substring(1);
return inBrowser && window.location.search.substring(1);
}
/**
* Parse url parameters into javascript object
* @param {string} [url] - URI to parse. If no url supplied window.location will be used
* @return {object} parsed url parameters
*/
function paramsParse(url) {

@@ -250,4 +273,4 @@ var searchString = getSearchString(url);

* Removes params from url in browser
* @param {string} param - param string to remove
* @param {function} [callback] - callback function to run
* @param {string} param - param key to remove from current URL
* @param {function} [callback] - callback function to run. Only runs in browser
* @return {promise}

@@ -257,4 +280,5 @@ */

function paramsRemove(param, callback) {
if (!inBrowser) return Promise.resolve();
return new Promise(function (resolve, reject) {
if (isInBrowser && window.history && window.history.replaceState) {
if (window.history && window.history.replaceState) {
var url = window.location.href;

@@ -264,11 +288,9 @@ var cleanUrl = paramsClean(url, param);

if (url !== cleanUrl) {
// replace URL
history.replaceState({}, '', cleanUrl); // eslint-disable-line
/* replace URL with history API */
// eslint-disable-next-line no-restricted-globals
history.replaceState({}, '', cleanUrl);
}
}
if (callback) {
callback();
}
if (callback) callback();
return resolve();

@@ -289,3 +311,3 @@ });

function getDomainHost(url) {
if (!isInBrowser) return null;
if (!inBrowser) return null;
var a = document.createElement('a');

@@ -321,4 +343,3 @@ a.setAttribute('href', url);

return arr.length > 1 ? arr.slice(0, -1).join('.') : baseDomain;
} //*
}
var url = {

@@ -328,6 +349,5 @@ trimTld: trimTld,

getDomainHost: getDomainHost
/**/
};
var googleKey = 'google';
/**

@@ -341,3 +361,3 @@ * Checks a given url and parses referrer data

function parseReferrer(referrer, currentUrl) {
if (!isInBrowser) return false; // default referral data
if (!inBrowser) return false; // default referral data

@@ -377,3 +397,3 @@ var refData = {

if (key.match(/^(d|g)clid/)) {
acc['source'] = 'google';
acc['source'] = googleKey;
acc['medium'] = params.gclid ? 'cpc' : 'cpm';

@@ -388,3 +408,3 @@ acc[key] = params[key];

if (params.dclid || params.gclid) {
refData['source'] = 'google';
refData['source'] = googleKey;
refData['medium'] = params.gclid ? 'cpc' : 'cpm';

@@ -403,3 +423,3 @@ }

function parseDomain(referrer) {
if (!referrer || !isInBrowser) return false;
if (!referrer || !inBrowser) return false;
var referringDomain = getDomainBase(referrer);

@@ -409,4 +429,4 @@ var a = document.createElement('a');

if (a.hostname.indexOf('google') > -1) {
referringDomain = 'google';
if (a.hostname.indexOf(googleKey) > -1) {
referringDomain = googleKey;
} // If is search engine

@@ -481,10 +501,10 @@

function parse(result) {
function parse(input) {
var value;
try {
value = JSON.parse(result);
value = JSON.parse(input);
if (typeof value === 'undefined') {
value = result;
value = input;
}

@@ -504,3 +524,3 @@

} catch (e) {
value = result;
value = input;
}

@@ -511,18 +531,2 @@

function hasLocalStorage() {
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_test_', '1');
localStorage.removeItem('_test_');
} catch (err) {
return false;
}
return true;
}
// const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line

@@ -533,7 +537,10 @@ // (typeof global === 'object' && global.global === global && global) ||

// export default context
/* global self globalThis */
var getGlobal = function getGlobal() {
/* eslint-disable */
if (typeof self !== 'undefined' && self) {
return self;
}
/* istanbul ignore next */
/* eslint-enable */

@@ -556,3 +563,28 @@

/**
* Check if browser has access to LocalStorage
*
* @returns {Boolean}
*/
function hasLocalStorage() {
if (!inBrowser) return false;
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_test_', '1');
localStorage.removeItem('_test_');
} catch (err) {
return false;
}
return true;
}
var hasLocalStorage$1 = hasLocalStorage();
/**

@@ -572,3 +604,3 @@ * Get storage item from localStorage, cookie, or window

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
var value = localStorage.getItem(key);

@@ -580,3 +612,3 @@ if (value || storage === 'localStorage') return parse(value);

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
var _value = getCookie(key);

@@ -606,3 +638,3 @@

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
// console.log('SET as localstorage', saveValue)

@@ -621,3 +653,3 @@ var _oldValue = parse(localStorage.getItem(key));

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
// console.log('SET as cookie', saveValue)

@@ -658,3 +690,3 @@ var _oldValue2 = parse(getCookie(key));

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
localStorage.removeItem(key);

@@ -666,3 +698,3 @@ return null;

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
removeCookie(key);

@@ -677,2 +709,11 @@ return null;

}
function useLocal(storage) {
return hasLocalStorage$1 && (!storage || storage === 'localStorage');
}
function useCookie(storage) {
return cookiesSupported && (!storage || storage === 'cookie');
}
var index = {

@@ -692,6 +733,6 @@ getItem: getItem,

return function () {
var d0 = Math.random() * 0xffffffff | 0;
var d1 = Math.random() * 0xffffffff | 0;
var d2 = Math.random() * 0xffffffff | 0;
var d3 = Math.random() * 0xffffffff | 0;
var d0 = genNumber();
var d1 = genNumber();
var d2 = genNumber();
var d3 = genNumber();
/* eslint-disable */

@@ -704,2 +745,6 @@

function genNumber() {
return Math.random() * 0xffffffff | 0;
}
exports.cookie = cookie;

@@ -709,3 +754,3 @@ exports.decodeUri = decode;

exports.getTimeZone = getTimeZone;
exports.inBrowser = isInBrowser;
exports.inBrowser = inBrowser;
exports.isExternalReferrer = isExternalReferrer;

@@ -712,0 +757,0 @@ exports.isScriptLoaded = isScriptLoaded;

@@ -1,2 +0,2 @@

var isInBrowser = typeof window !== 'undefined';
var inBrowser = typeof window !== 'undefined';

@@ -11,8 +11,9 @@ /**

try {
if (!isInBrowser) return false; // Try to set cookie
if (!inBrowser) return false;
var key = 'cookietest='; // Try to set cookie
document.cookie = 'cookietest=1';
var cookiesEnabled = document.cookie.indexOf('cookietest=') !== -1; // Cleanup cookie
document.cookie = "".concat(key, "1");
var cookiesEnabled = document.cookie.indexOf(key) !== -1; // Cleanup cookie
document.cookie = 'cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
document.cookie = "".concat(key, "1; expires=Thu, 01-Jan-1970 00:00:01 GMT");
return cookiesEnabled;

@@ -71,6 +72,3 @@ } catch (e) {

function getBrowserLocale() {
if (!isInBrowser) {
return null;
}
if (!inBrowser) return null;
var _navigator = navigator,

@@ -111,3 +109,3 @@ language = _navigator.language,

function isExternalReferrer(ref) {
if (!isInBrowser) return false;
if (!inBrowser) return false;
var referrer = ref || document.referrer;

@@ -129,4 +127,10 @@

/**
* Check if a script is loaded
* @param {String|RegExp} script - Script src as string or regex
* @return {Boolean} is script loaded
*/
function isScriptLoaded(script) {
if (!isInBrowser) return true;
if (!inBrowser) return true;
var scripts = document.getElementsByTagName('script');

@@ -156,3 +160,3 @@ return !!Object.keys(scripts).filter(function (key) {

var regex = new RegExp("(\\&|\\?)".concat(param, "([_A-Za-z0-9=.%]+)"), 'g');
var regex = new RegExp("(\\&|\\?)".concat(param, "([_A-Za-z0-9\"+=.%]+)"), 'g');
var cleanSearch = "?".concat(search).replace(regex, '').replace(/^&/, '?'); // replace search params with clean params

@@ -165,6 +169,19 @@

function getValueParamValue(name, string) {
return decode((RegExp("".concat(name, "=(.+?)(&|$)")).exec(string) || [, ''])[1]);
/**
* Get a given query parameter value
* @param {string} param - Key of parameter to find
* @param {string} url - url to search
* @return {string} match
*/
function getValueParamValue(param, url) {
return decode((RegExp("".concat(param, "=(.+?)(&|$)")).exec(url) || [, ''])[1]);
}
/**
* Get search string from given url
* @param {string} [url] - optional url string. If no url, window.location.search will be used
* @return {string} url search string
*/
function getSearchString(url) {

@@ -176,5 +193,11 @@ if (url) {

return isInBrowser && window.location.search.substring(1);
return inBrowser && window.location.search.substring(1);
}
/**
* Parse url parameters into javascript object
* @param {string} [url] - URI to parse. If no url supplied window.location will be used
* @return {object} parsed url parameters
*/
function paramsParse(url) {

@@ -245,4 +268,4 @@ var searchString = getSearchString(url);

* Removes params from url in browser
* @param {string} param - param string to remove
* @param {function} [callback] - callback function to run
* @param {string} param - param key to remove from current URL
* @param {function} [callback] - callback function to run. Only runs in browser
* @return {promise}

@@ -252,4 +275,5 @@ */

function paramsRemove(param, callback) {
if (!inBrowser) return Promise.resolve();
return new Promise(function (resolve, reject) {
if (isInBrowser && window.history && window.history.replaceState) {
if (window.history && window.history.replaceState) {
var url = window.location.href;

@@ -259,11 +283,9 @@ var cleanUrl = paramsClean(url, param);

if (url !== cleanUrl) {
// replace URL
history.replaceState({}, '', cleanUrl); // eslint-disable-line
/* replace URL with history API */
// eslint-disable-next-line no-restricted-globals
history.replaceState({}, '', cleanUrl);
}
}
if (callback) {
callback();
}
if (callback) callback();
return resolve();

@@ -284,3 +306,3 @@ });

function getDomainHost(url) {
if (!isInBrowser) return null;
if (!inBrowser) return null;
var a = document.createElement('a');

@@ -316,4 +338,3 @@ a.setAttribute('href', url);

return arr.length > 1 ? arr.slice(0, -1).join('.') : baseDomain;
} //*
}
var url = {

@@ -323,6 +344,5 @@ trimTld: trimTld,

getDomainHost: getDomainHost
/**/
};
var googleKey = 'google';
/**

@@ -336,3 +356,3 @@ * Checks a given url and parses referrer data

function parseReferrer(referrer, currentUrl) {
if (!isInBrowser) return false; // default referral data
if (!inBrowser) return false; // default referral data

@@ -372,3 +392,3 @@ var refData = {

if (key.match(/^(d|g)clid/)) {
acc['source'] = 'google';
acc['source'] = googleKey;
acc['medium'] = params.gclid ? 'cpc' : 'cpm';

@@ -383,3 +403,3 @@ acc[key] = params[key];

if (params.dclid || params.gclid) {
refData['source'] = 'google';
refData['source'] = googleKey;
refData['medium'] = params.gclid ? 'cpc' : 'cpm';

@@ -398,3 +418,3 @@ }

function parseDomain(referrer) {
if (!referrer || !isInBrowser) return false;
if (!referrer || !inBrowser) return false;
var referringDomain = getDomainBase(referrer);

@@ -404,4 +424,4 @@ var a = document.createElement('a');

if (a.hostname.indexOf('google') > -1) {
referringDomain = 'google';
if (a.hostname.indexOf(googleKey) > -1) {
referringDomain = googleKey;
} // If is search engine

@@ -476,10 +496,10 @@

function parse(result) {
function parse(input) {
var value;
try {
value = JSON.parse(result);
value = JSON.parse(input);
if (typeof value === 'undefined') {
value = result;
value = input;
}

@@ -499,3 +519,3 @@

} catch (e) {
value = result;
value = input;
}

@@ -506,18 +526,2 @@

function hasLocalStorage() {
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_test_', '1');
localStorage.removeItem('_test_');
} catch (err) {
return false;
}
return true;
}
// const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line

@@ -528,7 +532,10 @@ // (typeof global === 'object' && global.global === global && global) ||

// export default context
/* global self globalThis */
var getGlobal = function getGlobal() {
/* eslint-disable */
if (typeof self !== 'undefined' && self) {
return self;
}
/* istanbul ignore next */
/* eslint-enable */

@@ -551,3 +558,28 @@

/**
* Check if browser has access to LocalStorage
*
* @returns {Boolean}
*/
function hasLocalStorage() {
if (!inBrowser) return false;
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_test_', '1');
localStorage.removeItem('_test_');
} catch (err) {
return false;
}
return true;
}
var hasLocalStorage$1 = hasLocalStorage();
/**

@@ -567,3 +599,3 @@ * Get storage item from localStorage, cookie, or window

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
var value = localStorage.getItem(key);

@@ -575,3 +607,3 @@ if (value || storage === 'localStorage') return parse(value);

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
var _value = getCookie(key);

@@ -601,3 +633,3 @@

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
// console.log('SET as localstorage', saveValue)

@@ -616,3 +648,3 @@ var _oldValue = parse(localStorage.getItem(key));

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
// console.log('SET as cookie', saveValue)

@@ -653,3 +685,3 @@ var _oldValue2 = parse(getCookie(key));

if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {
if (useLocal(storage)) {
localStorage.removeItem(key);

@@ -661,3 +693,3 @@ return null;

if (cookiesSupported && (!storage || storage === 'cookie')) {
if (useCookie(storage)) {
removeCookie(key);

@@ -672,2 +704,11 @@ return null;

}
function useLocal(storage) {
return hasLocalStorage$1 && (!storage || storage === 'localStorage');
}
function useCookie(storage) {
return cookiesSupported && (!storage || storage === 'cookie');
}
var index = {

@@ -687,6 +728,6 @@ getItem: getItem,

return function () {
var d0 = Math.random() * 0xffffffff | 0;
var d1 = Math.random() * 0xffffffff | 0;
var d2 = Math.random() * 0xffffffff | 0;
var d3 = Math.random() * 0xffffffff | 0;
var d0 = genNumber();
var d1 = genNumber();
var d2 = genNumber();
var d3 = genNumber();
/* eslint-disable */

@@ -699,2 +740,6 @@

export { cookie, decode as decodeUri, getBrowserLocale, getTimeZone, isInBrowser as inBrowser, isExternalReferrer, isScriptLoaded, noOp, paramsClean, getValueParamValue as paramsGet, paramsParse, paramsRemove, parseReferrer, index as storage, url, uuid, globalContext };
function genNumber() {
return Math.random() * 0xffffffff | 0;
}
export { cookie, decode as decodeUri, getBrowserLocale, getTimeZone, inBrowser, isExternalReferrer, isScriptLoaded, noOp, paramsClean, getValueParamValue as paramsGet, paramsParse, paramsRemove, parseReferrer, index as storage, url, uuid, globalContext };
{
"name": "analytics-utils",
"version": "0.0.18",
"version": "0.0.19",
"description": "Analytics utility functions",

@@ -57,3 +57,3 @@ "author": "David Wells <hello@davidwells.io>",

},
"gitHead": "0ffae15536723604d69310cdf98142184d41da34"
"gitHead": "f224554ce7e0afb287944ed95ef513587df0f7dd"
}