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

@livechat/store-metrics

Package Overview
Dependencies
Maintainers
5
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@livechat/store-metrics - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

739

dist/store-metrics.min.js

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.storeMetrics=t()}(this,function(){"use strict";!function(e){function t(t){return!!t&&("Symbol"in e&&"iterator"in e.Symbol&&"function"==typeof t[Symbol.iterator]||!!Array.isArray(t))}function n(e){return"from"in Array?Array.from(e):Array.prototype.slice.call(e)}!function(){function r(e){var t="",n=!0;return e.forEach(function(e){var r=encodeURIComponent(e.name),o=encodeURIComponent(e.value);n||(t+="&"),t+=r+"="+o,n=!1}),t.replace(/%20/g,"+")}function o(e,t){var n=e.split("&");t&&-1===n[0].indexOf("=")&&(n[0]="="+n[0]);var r=[];n.forEach(function(e){if(0!==e.length){var t=e.indexOf("=");if(-1!==t)var n=e.substring(0,t),o=e.substring(t+1);else n=e,o="";n=n.replace(/\+/g," "),o=o.replace(/\+/g," "),r.push({name:n,value:o})}});var o=[];return r.forEach(function(e){o.push({name:decodeURIComponent(e.name),value:decodeURIComponent(e.value)})}),o}function a(e){var i=this;this._list=[],void 0===e||null===e||(e instanceof a?this._list=o(String(e)):"object"==typeof e&&t(e)?n(e).forEach(function(e){if(!t(e))throw TypeError();var r=n(e);if(2!==r.length)throw TypeError();i._list.push({name:String(r[0]),value:String(r[1])})}):"object"==typeof e&&e?Object.keys(e).forEach(function(t){i._list.push({name:String(t),value:String(e[t])})}):("?"===(e=String(e)).substring(0,1)&&(e=e.substring(1)),this._list=o(e))),this._url_object=null,this._setList=function(e){u||(i._list=e)};var u=!1;this._update_steps=function(){u||(u=!0,i._url_object&&("about:"===i._url_object.protocol&&-1!==i._url_object.pathname.indexOf("?")&&(i._url_object.pathname=i._url_object.pathname.split("?")[0]),i._url_object.search=r(i._list),u=!1))}}function i(e,t){var n=0;this.next=function(){if(n>=e.length)return{done:!0,value:void 0};var r=e[n++];return{done:!1,value:"key"===t?r.name:"value"===t?r.value:[r.name,r.value]}}}function u(t,n){function r(){var e=u.href.replace(/#$|\?$|\?(?=#)/g,"");u.href!==e&&(u.href=e)}function i(){f._setList(u.search?o(u.search.substring(1)):[]),f._update_steps()}if(!(this instanceof e.URL))throw new TypeError("Failed to construct 'URL': Please use the 'new' operator.");n&&(t=function(){if(c)return new l(t,n).href;var e;try{var r;if("[object OperaMini]"===Object.prototype.toString.call(window.operamini)?((e=document.createElement("iframe")).style.display="none",document.documentElement.appendChild(e),r=e.contentWindow.document):document.implementation&&document.implementation.createHTMLDocument?r=document.implementation.createHTMLDocument(""):document.implementation&&document.implementation.createDocument?((r=document.implementation.createDocument("http://www.w3.org/1999/xhtml","html",null)).documentElement.appendChild(r.createElement("head")),r.documentElement.appendChild(r.createElement("body"))):window.ActiveXObject&&((r=new window.ActiveXObject("htmlfile")).write("<head></head><body></body>"),r.close()),!r)throw Error("base not supported");var o=r.createElement("base");o.href=n,r.getElementsByTagName("head")[0].appendChild(o);var a=r.createElement("a");return a.href=t,a.href}finally{e&&e.parentNode.removeChild(e)}}());var u=function(e){if(c)return new l(e);var t=document.createElement("a");return t.href=e,t}(t||""),s=function(){if(!("defineProperties"in Object))return!1;try{var e={};return Object.defineProperties(e,{prop:{get:function(){return!0}}}),e.prop}catch(e){return!1}}()?this:document.createElement("a"),f=new a(u.search?u.search.substring(1):null);return f._url_object=s,Object.defineProperties(s,{href:{get:function(){return u.href},set:function(e){u.href=e,r(),i()},enumerable:!0,configurable:!0},origin:{get:function(){return"origin"in u?u.origin:this.protocol+"//"+this.host},enumerable:!0,configurable:!0},protocol:{get:function(){return u.protocol},set:function(e){u.protocol=e},enumerable:!0,configurable:!0},username:{get:function(){return u.username},set:function(e){u.username=e},enumerable:!0,configurable:!0},password:{get:function(){return u.password},set:function(e){u.password=e},enumerable:!0,configurable:!0},host:{get:function(){var e={"http:":/:80$/,"https:":/:443$/,"ftp:":/:21$/}[u.protocol];return e?u.host.replace(e,""):u.host},set:function(e){u.host=e},enumerable:!0,configurable:!0},hostname:{get:function(){return u.hostname},set:function(e){u.hostname=e},enumerable:!0,configurable:!0},port:{get:function(){return u.port},set:function(e){u.port=e},enumerable:!0,configurable:!0},pathname:{get:function(){return"/"!==u.pathname.charAt(0)?"/"+u.pathname:u.pathname},set:function(e){u.pathname=e},enumerable:!0,configurable:!0},search:{get:function(){return u.search},set:function(e){u.search!==e&&(u.search=e,r(),i())},enumerable:!0,configurable:!0},searchParams:{get:function(){return f},enumerable:!0,configurable:!0},hash:{get:function(){return u.hash},set:function(e){u.hash=e,r()},enumerable:!0,configurable:!0},toString:{value:function(){return u.toString()},enumerable:!1,configurable:!0},valueOf:{value:function(){return u.valueOf()},enumerable:!1,configurable:!0}}),s}var c,l=e.URL;try{if(l){if("searchParams"in(c=new e.URL("http://example.com")))return;"href"in c||(c=void 0)}}catch(e){}if(Object.defineProperties(a.prototype,{append:{value:function(e,t){this._list.push({name:e,value:t}),this._update_steps()},writable:!0,enumerable:!0,configurable:!0},delete:{value:function(e){for(var t=0;t<this._list.length;)this._list[t].name===e?this._list.splice(t,1):++t;this._update_steps()},writable:!0,enumerable:!0,configurable:!0},get:{value:function(e){for(var t=0;t<this._list.length;++t)if(this._list[t].name===e)return this._list[t].value;return null},writable:!0,enumerable:!0,configurable:!0},getAll:{value:function(e){for(var t=[],n=0;n<this._list.length;++n)this._list[n].name===e&&t.push(this._list[n].value);return t},writable:!0,enumerable:!0,configurable:!0},has:{value:function(e){for(var t=0;t<this._list.length;++t)if(this._list[t].name===e)return!0;return!1},writable:!0,enumerable:!0,configurable:!0},set:{value:function(e,t){for(var n=!1,r=0;r<this._list.length;)this._list[r].name===e?n?this._list.splice(r,1):(this._list[r].value=t,n=!0,++r):++r;n||this._list.push({name:e,value:t}),this._update_steps()},writable:!0,enumerable:!0,configurable:!0},entries:{value:function(){return new i(this._list,"key+value")},writable:!0,enumerable:!0,configurable:!0},keys:{value:function(){return new i(this._list,"key")},writable:!0,enumerable:!0,configurable:!0},values:{value:function(){return new i(this._list,"value")},writable:!0,enumerable:!0,configurable:!0},forEach:{value:function(e){var t=arguments.length>1?arguments[1]:void 0;this._list.forEach(function(n,r){e.call(t,n.value,n.name)})},writable:!0,enumerable:!0,configurable:!0},toString:{value:function(){return r(this._list)},writable:!0,enumerable:!1,configurable:!0}}),"Symbol"in e&&"iterator"in e.Symbol&&(Object.defineProperty(a.prototype,e.Symbol.iterator,{value:a.prototype.entries,writable:!0,enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,e.Symbol.iterator,{value:function(){return this},writable:!0,enumerable:!0,configurable:!0})),l)for(var s in l)l.hasOwnProperty(s)&&"function"==typeof l[s]&&(u[s]=l[s]);e.URL=u,e.URLSearchParams=a}(),function(){if("1"!==new e.URLSearchParams([["a",1]]).get("a")||"1"!==new e.URLSearchParams({a:1}).get("a")){var r=e.URLSearchParams;e.URLSearchParams=function(e){if(e&&"object"==typeof e&&t(e)){var o=new r;return n(e).forEach(function(e){if(!t(e))throw TypeError();var r=n(e);if(2!==r.length)throw TypeError();o.append(r[0],r[1])}),o}return e&&"object"==typeof e?(o=new r,Object.keys(e).forEach(function(t){o.set(t,e[t])}),o):new r(e)}}}()}(self);var e=Object.freeze({}),t=function(e,t){return t={exports:{}},e(t,t.exports),t.exports}(function(e,t){!function(t){if(e.exports=t(),!!0){var n=window.Cookies,r=window.Cookies=t();r.noConflict=function(){return window.Cookies=n,r}}}(function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function t(n){function r(t,o,a){var i;if("undefined"!=typeof document){if(arguments.length>1){if("number"==typeof(a=e({path:"/"},r.defaults,a)).expires){var u=new Date;u.setMilliseconds(u.getMilliseconds()+864e5*a.expires),a.expires=u}a.expires=a.expires?a.expires.toUTCString():"";try{i=JSON.stringify(o),/^[\{\[]/.test(i)&&(o=i)}catch(e){}o=n.write?n.write(o,t):encodeURIComponent(String(o)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=(t=(t=encodeURIComponent(String(t))).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent)).replace(/[\(\)]/g,escape);var c="";for(var l in a)a[l]&&(c+="; "+l,!0!==a[l]&&(c+="="+a[l]));return document.cookie=t+"="+o+c}t||(i={});for(var s=document.cookie?document.cookie.split("; "):[],f=/(%[0-9A-Z]{2})+/g,h=0;h<s.length;h++){var m=s[h].split("="),p=m.slice(1).join("=");this.json||'"'!==p.charAt(0)||(p=p.slice(1,-1));try{var d=m[0].replace(f,decodeURIComponent);if(p=n.read?n.read(p,d):n(p,d)||p.replace(f,decodeURIComponent),this.json)try{p=JSON.parse(p)}catch(e){}if(t===d){i=p;break}t||(i[d]=p)}catch(e){}}return i}}return r.set=r,r.get=function(e){return r.call(r,e)},r.getJSON=function(){return r.apply({json:!0},[].slice.call(arguments))},r.defaults={},r.remove=function(t,n){r(t,"",e(n,{expires:-1}))},r.withConverter=t,r}return t(function(){})})}),n=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];return function(){var r=document.referrer?new e(document.referrer):null,o=new e(document.location.href),a="."+o.hostname.replace(/^(www\.)/,""),i=n.filter(function(e){return o.searchParams.has(e)});i.length&&(n.forEach(function(e){return t.remove(e,{domain:a})}),i.forEach(function(e){t.set(e,o.searchParams.get(e),{domain:a})})),r&&r.hostname!==o.hostname&&t.set("referrer",r.href,{domain:a}),t.get("landing_page")||t.set("landing_page",o.origin+o.pathname,{domain:a}),o.searchParams.has("discount")&&t.set("discount",o.searchParams.get("discount"),{domain:a}),o.searchParams.has("a")&&t.set("partner_id",o.searchParams.get("a"),{domain:a,expires:120}),o.searchParams.has("partner")&&t.set("promocode",o.searchParams.get("partner"),{domain:a,expires:120})}});
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.storeMetrics = factory());
}(this, (function () { 'use strict';
// URL Polyfill
// Draft specification: https://url.spec.whatwg.org
// Notes:
// - Primarily useful for parsing URLs and modifying query parameters
// - Should work in IE8+ and everything more modern, with es5.js polyfills
(function (global) {
function isSequence(o) {
if (!o) return false;
if ('Symbol' in global && 'iterator' in global.Symbol &&
typeof o[Symbol.iterator] === 'function') return true;
if (Array.isArray(o)) return true;
return false;
}
function toArray(iter) {
return ('from' in Array) ? Array.from(iter) : Array.prototype.slice.call(iter);
}
(function() {
// Browsers may have:
// * No global URL object
// * URL with static methods only - may have a dummy constructor
// * URL with members except searchParams
// * Full URL API support
var origURL = global.URL;
var nativeURL;
try {
if (origURL) {
nativeURL = new global.URL('http://example.com');
if ('searchParams' in nativeURL)
return;
if (!('href' in nativeURL))
nativeURL = undefined;
}
} catch (_) {}
// NOTE: Doesn't do the encoding/decoding dance
function urlencoded_serialize(pairs) {
var output = '', first = true;
pairs.forEach(function (pair) {
var name = encodeURIComponent(pair.name);
var value = encodeURIComponent(pair.value);
if (!first) output += '&';
output += name + '=' + value;
first = false;
});
return output.replace(/%20/g, '+');
}
// NOTE: Doesn't do the encoding/decoding dance
function urlencoded_parse(input, isindex) {
var sequences = input.split('&');
if (isindex && sequences[0].indexOf('=') === -1)
sequences[0] = '=' + sequences[0];
var pairs = [];
sequences.forEach(function (bytes) {
if (bytes.length === 0) return;
var index = bytes.indexOf('=');
if (index !== -1) {
var name = bytes.substring(0, index);
var value = bytes.substring(index + 1);
} else {
name = bytes;
value = '';
}
name = name.replace(/\+/g, ' ');
value = value.replace(/\+/g, ' ');
pairs.push({ name: name, value: value });
});
var output = [];
pairs.forEach(function (pair) {
output.push({
name: decodeURIComponent(pair.name),
value: decodeURIComponent(pair.value)
});
});
return output;
}
function URLUtils(url) {
if (nativeURL)
return new origURL(url);
var anchor = document.createElement('a');
anchor.href = url;
return anchor;
}
function URLSearchParams(init) {
var $this = this;
this._list = [];
if (init === undefined || init === null) {
// no-op
} else if (init instanceof URLSearchParams) {
// In ES6 init would be a sequence, but special case for ES5.
this._list = urlencoded_parse(String(init));
} else if (typeof init === 'object' && isSequence(init)) {
toArray(init).forEach(function(e) {
if (!isSequence(e)) throw TypeError();
var nv = toArray(e);
if (nv.length !== 2) throw TypeError();
$this._list.push({name: String(nv[0]), value: String(nv[1])});
});
} else if (typeof init === 'object' && init) {
Object.keys(init).forEach(function(key) {
$this._list.push({name: String(key), value: String(init[key])});
});
} else {
init = String(init);
if (init.substring(0, 1) === '?')
init = init.substring(1);
this._list = urlencoded_parse(init);
}
this._url_object = null;
this._setList = function (list) { if (!updating) $this._list = list; };
var updating = false;
this._update_steps = function() {
if (updating) return;
updating = true;
if (!$this._url_object) return;
// Partial workaround for IE issue with 'about:'
if ($this._url_object.protocol === 'about:' &&
$this._url_object.pathname.indexOf('?') !== -1) {
$this._url_object.pathname = $this._url_object.pathname.split('?')[0];
}
$this._url_object.search = urlencoded_serialize($this._list);
updating = false;
};
}
Object.defineProperties(URLSearchParams.prototype, {
append: {
value: function (name, value) {
this._list.push({ name: name, value: value });
this._update_steps();
}, writable: true, enumerable: true, configurable: true
},
'delete': {
value: function (name) {
for (var i = 0; i < this._list.length;) {
if (this._list[i].name === name)
this._list.splice(i, 1);
else
++i;
}
this._update_steps();
}, writable: true, enumerable: true, configurable: true
},
get: {
value: function (name) {
for (var i = 0; i < this._list.length; ++i) {
if (this._list[i].name === name)
return this._list[i].value;
}
return null;
}, writable: true, enumerable: true, configurable: true
},
getAll: {
value: function (name) {
var result = [];
for (var i = 0; i < this._list.length; ++i) {
if (this._list[i].name === name)
result.push(this._list[i].value);
}
return result;
}, writable: true, enumerable: true, configurable: true
},
has: {
value: function (name) {
for (var i = 0; i < this._list.length; ++i) {
if (this._list[i].name === name)
return true;
}
return false;
}, writable: true, enumerable: true, configurable: true
},
set: {
value: function (name, value) {
var found = false;
for (var i = 0; i < this._list.length;) {
if (this._list[i].name === name) {
if (!found) {
this._list[i].value = value;
found = true;
++i;
} else {
this._list.splice(i, 1);
}
} else {
++i;
}
}
if (!found)
this._list.push({ name: name, value: value });
this._update_steps();
}, writable: true, enumerable: true, configurable: true
},
entries: {
value: function() { return new Iterator(this._list, 'key+value'); },
writable: true, enumerable: true, configurable: true
},
keys: {
value: function() { return new Iterator(this._list, 'key'); },
writable: true, enumerable: true, configurable: true
},
values: {
value: function() { return new Iterator(this._list, 'value'); },
writable: true, enumerable: true, configurable: true
},
forEach: {
value: function(callback) {
var thisArg = (arguments.length > 1) ? arguments[1] : undefined;
this._list.forEach(function(pair, index) {
callback.call(thisArg, pair.value, pair.name);
});
}, writable: true, enumerable: true, configurable: true
},
toString: {
value: function () {
return urlencoded_serialize(this._list);
}, writable: true, enumerable: false, configurable: true
}
});
function Iterator(source, kind) {
var index = 0;
this['next'] = function() {
if (index >= source.length)
return {done: true, value: undefined};
var pair = source[index++];
return {done: false, value:
kind === 'key' ? pair.name :
kind === 'value' ? pair.value :
[pair.name, pair.value]};
};
}
if ('Symbol' in global && 'iterator' in global.Symbol) {
Object.defineProperty(URLSearchParams.prototype, global.Symbol.iterator, {
value: URLSearchParams.prototype.entries,
writable: true, enumerable: true, configurable: true});
Object.defineProperty(Iterator.prototype, global.Symbol.iterator, {
value: function() { return this; },
writable: true, enumerable: true, configurable: true});
}
function URL(url, base) {
if (!(this instanceof global.URL))
throw new TypeError("Failed to construct 'URL': Please use the 'new' operator.");
if (base) {
url = (function () {
if (nativeURL) return new origURL(url, base).href;
var iframe;
try {
var doc;
// Use another document/base tag/anchor for relative URL resolution, if possible
if (Object.prototype.toString.call(window.operamini) === "[object OperaMini]") {
iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.documentElement.appendChild(iframe);
doc = iframe.contentWindow.document;
} else if (document.implementation && document.implementation.createHTMLDocument) {
doc = document.implementation.createHTMLDocument('');
} else if (document.implementation && document.implementation.createDocument) {
doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
doc.documentElement.appendChild(doc.createElement('head'));
doc.documentElement.appendChild(doc.createElement('body'));
} else if (window.ActiveXObject) {
doc = new window.ActiveXObject('htmlfile');
doc.write('<head><\/head><body><\/body>');
doc.close();
}
if (!doc) throw Error('base not supported');
var baseTag = doc.createElement('base');
baseTag.href = base;
doc.getElementsByTagName('head')[0].appendChild(baseTag);
var anchor = doc.createElement('a');
anchor.href = url;
return anchor.href;
} finally {
if (iframe)
iframe.parentNode.removeChild(iframe);
}
}());
}
// An inner object implementing URLUtils (either a native URL
// object or an HTMLAnchorElement instance) is used to perform the
// URL algorithms. With full ES5 getter/setter support, return a
// regular object For IE8's limited getter/setter support, a
// different HTMLAnchorElement is returned with properties
// overridden
var instance = URLUtils(url || '');
// Detect for ES5 getter/setter support
// (an Object.defineProperties polyfill that doesn't support getters/setters may throw)
var ES5_GET_SET = (function() {
if (!('defineProperties' in Object)) return false;
try {
var obj = {};
Object.defineProperties(obj, { prop: { 'get': function () { return true; } } });
return obj.prop;
} catch (_) {
return false;
}
})();
var self = ES5_GET_SET ? this : document.createElement('a');
var query_object = new URLSearchParams(
instance.search ? instance.search.substring(1) : null);
query_object._url_object = self;
Object.defineProperties(self, {
href: {
get: function () { return instance.href; },
set: function (v) { instance.href = v; tidy_instance(); update_steps(); },
enumerable: true, configurable: true
},
origin: {
get: function () {
if ('origin' in instance) return instance.origin;
return this.protocol + '//' + this.host;
},
enumerable: true, configurable: true
},
protocol: {
get: function () { return instance.protocol; },
set: function (v) { instance.protocol = v; },
enumerable: true, configurable: true
},
username: {
get: function () { return instance.username; },
set: function (v) { instance.username = v; },
enumerable: true, configurable: true
},
password: {
get: function () { return instance.password; },
set: function (v) { instance.password = v; },
enumerable: true, configurable: true
},
host: {
get: function () {
// IE returns default port in |host|
var re = {'http:': /:80$/, 'https:': /:443$/, 'ftp:': /:21$/}[instance.protocol];
return re ? instance.host.replace(re, '') : instance.host;
},
set: function (v) { instance.host = v; },
enumerable: true, configurable: true
},
hostname: {
get: function () { return instance.hostname; },
set: function (v) { instance.hostname = v; },
enumerable: true, configurable: true
},
port: {
get: function () { return instance.port; },
set: function (v) { instance.port = v; },
enumerable: true, configurable: true
},
pathname: {
get: function () {
// IE does not include leading '/' in |pathname|
if (instance.pathname.charAt(0) !== '/') return '/' + instance.pathname;
return instance.pathname;
},
set: function (v) { instance.pathname = v; },
enumerable: true, configurable: true
},
search: {
get: function () { return instance.search; },
set: function (v) {
if (instance.search === v) return;
instance.search = v; tidy_instance(); update_steps();
},
enumerable: true, configurable: true
},
searchParams: {
get: function () { return query_object; },
enumerable: true, configurable: true
},
hash: {
get: function () { return instance.hash; },
set: function (v) { instance.hash = v; tidy_instance(); },
enumerable: true, configurable: true
},
toString: {
value: function() { return instance.toString(); },
enumerable: false, configurable: true
},
valueOf: {
value: function() { return instance.valueOf(); },
enumerable: false, configurable: true
}
});
function tidy_instance() {
var href = instance.href.replace(/#$|\?$|\?(?=#)/g, '');
if (instance.href !== href)
instance.href = href;
}
function update_steps() {
query_object._setList(instance.search ? urlencoded_parse(instance.search.substring(1)) : []);
query_object._update_steps();
}
return self;
}
if (origURL) {
for (var i in origURL) {
if (origURL.hasOwnProperty(i) && typeof origURL[i] === 'function')
URL[i] = origURL[i];
}
}
global.URL = URL;
global.URLSearchParams = URLSearchParams;
}());
// Patch native URLSearchParams constructor to handle sequences/records
// if necessary.
(function() {
if (new global.URLSearchParams([['a', 1]]).get('a') === '1' &&
new global.URLSearchParams({a: 1}).get('a') === '1')
return;
var orig = global.URLSearchParams;
global.URLSearchParams = function(init) {
if (init && typeof init === 'object' && isSequence(init)) {
var o = new orig();
toArray(init).forEach(function(e) {
if (!isSequence(e)) throw TypeError();
var nv = toArray(e);
if (nv.length !== 2) throw TypeError();
o.append(nv[0], nv[1]);
});
return o;
} else if (init && typeof init === 'object') {
o = new orig();
Object.keys(init).forEach(function(key) {
o.set(key, init[key]);
});
return o;
} else {
return new orig(init);
}
};
}());
}(self));
var URL = Object.freeze({
});
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var js_cookie = createCommonjsModule(function (module, exports) {
/*!
* JavaScript Cookie v2.2.0
* https://github.com/js-cookie/js-cookie
*
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
* Released under the MIT license
*/
(function (factory) {
var registeredInModuleLoader = false;
if (typeof undefined === 'function' && undefined.amd) {
undefined(factory);
registeredInModuleLoader = true;
}
{
module.exports = factory();
registeredInModuleLoader = true;
}
if (!registeredInModuleLoader) {
var OldCookies = window.Cookies;
var api = window.Cookies = factory();
api.noConflict = function () {
window.Cookies = OldCookies;
return api;
};
}
}(function () {
function extend () {
var i = 0;
var result = {};
for (; i < arguments.length; i++) {
var attributes = arguments[ i ];
for (var key in attributes) {
result[key] = attributes[key];
}
}
return result;
}
function init (converter) {
function api (key, value, attributes) {
var result;
if (typeof document === 'undefined') {
return;
}
// Write
if (arguments.length > 1) {
attributes = extend({
path: '/'
}, api.defaults, attributes);
if (typeof attributes.expires === 'number') {
var expires = new Date();
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
attributes.expires = expires;
}
// We're using "expires" because "max-age" is not supported by IE
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
try {
result = JSON.stringify(value);
if (/^[\{\[]/.test(result)) {
value = result;
}
} catch (e) {}
if (!converter.write) {
value = encodeURIComponent(String(value))
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
} else {
value = converter.write(value, key);
}
key = encodeURIComponent(String(key));
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
key = key.replace(/[\(\)]/g, escape);
var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue;
}
stringifiedAttributes += '; ' + attributeName;
if (attributes[attributeName] === true) {
continue;
}
stringifiedAttributes += '=' + attributes[attributeName];
}
return (document.cookie = key + '=' + value + stringifiedAttributes);
}
// Read
if (!key) {
result = {};
}
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling "get()"
var cookies = document.cookie ? document.cookie.split('; ') : [];
var rdecode = /(%[0-9A-Z]{2})+/g;
var i = 0;
for (; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var cookie = parts.slice(1).join('=');
if (!this.json && cookie.charAt(0) === '"') {
cookie = cookie.slice(1, -1);
}
try {
var name = parts[0].replace(rdecode, decodeURIComponent);
cookie = converter.read ?
converter.read(cookie, name) : converter(cookie, name) ||
cookie.replace(rdecode, decodeURIComponent);
if (this.json) {
try {
cookie = JSON.parse(cookie);
} catch (e) {}
}
if (key === name) {
result = cookie;
break;
}
if (!key) {
result[name] = cookie;
}
} catch (e) {}
}
return result;
}
api.set = api;
api.get = function (key) {
return api.call(api, key);
};
api.getJSON = function () {
return api.apply({
json: true
}, [].slice.call(arguments));
};
api.defaults = {};
api.remove = function (key, attributes) {
api(key, '', extend(attributes, {
expires: -1
}));
};
api.withConverter = init;
return api;
}
return init(function () {});
}));
});
var utms = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
var index = function () {
var referrer = document.referrer ? new URL(document.referrer) : null;
var location = new URL(document.location.href);
var cookieDomain = "." + location.hostname.replace(/^(www\.)/, "");
// Handle UTM params
var foundUtms = utms.filter(function (utm) {
return location.searchParams.has(utm);
});
if (foundUtms.length) {
// Prevent UTM params overlapping:
// when any param is present in query
// remove all saved previously
utms.forEach(function (utm) {
return js_cookie.remove(utm, { domain: cookieDomain });
});
// Store UTM params
// Duration: session
foundUtms.forEach(function (utm) {
js_cookie.set(utm, location.searchParams.get(utm), {
domain: cookieDomain
});
});
}
// Store referrer
// Duration: session
if (referrer && referrer.hostname !== location.hostname) {
js_cookie.set("referrer", referrer.href, {
domain: cookieDomain
});
}
// Store landing page
// Duration: session
if (!js_cookie.get("landing_page")) {
js_cookie.set("landing_page", location.origin + location.pathname, {
domain: cookieDomain
});
}
// Store discount
// Duration: session
if (location.searchParams.has("discount")) {
js_cookie.set("discount", location.searchParams.get("discount"), {
domain: cookieDomain
});
}
// Store affiliation
// Duration: 120 days
if (location.searchParams.has("a")) {
js_cookie.set("partner_id", location.searchParams.get("a"), {
domain: cookieDomain,
expires: 120
});
}
// Store promocode
// Duration: 120 days
if (location.searchParams.has("partner")) {
js_cookie.set("promocode", location.searchParams.get("partner"), {
domain: cookieDomain,
expires: 120
});
}
};
return index;
})));

11

package.json
{
"name": "@livechat/store-metrics",
"version": "0.1.0",
"version": "0.1.1",
"description": "",

@@ -8,5 +8,3 @@ "main": "dist/store-metrics.cjs.js",

"unpkg": "dist/store-metrics.min.js",
"files": [
"dist"
],
"files": ["dist"],
"scripts": {

@@ -23,6 +21,3 @@ "build": "cross-env NODE_ENV=production rollup -c",

"lint-staged": {
"*.{js,json,css}": [
"prettier --write",
"git add"
]
"*.{js,json,css}": ["prettier --write", "git add"]
},

@@ -29,0 +24,0 @@ "keywords": [],

@@ -1,4 +0,38 @@

# store-metrics
# @livechat/store-metrics
Reads and stores various marketing parameters as cookies. Super Important Thing for Marketing Team™.
## Installation
```bash
npm install --save @livechat/store-metrics
```
## Usage
### Apps
Library exposes only one function that creates subdomain scoped cookies (`*.example.com`) based on `document.location` and `document.referrer`. Make sure to fire it as early as possible, before redirects etc.
```js
import storeMetrics from "@livechat/store-metrics";
storeMetrics();
```
**NOTE:** `store-metrics` makes use of [URL API](https://developer.mozilla.org/en-US/docs/Web/API/URL). Polyfill for older browser is highly encouraged. We do not bundle any, as your app may already use some polyfill. However, we recommend [inexorabletash/polyfill](https://github.com/inexorabletash/polyfill/blob/master/url.js):
```bash
npm install --save js-polyfills
```
```js
import "js-polyfills/url";
```
### Websites
```html
<script src="TBA/store-metrics.min.js"></script>
```
## Development

@@ -8,3 +42,3 @@

npm install
npm start
npm test:watch
```

@@ -16,2 +50,2 @@

npm run build
```
```
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc