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
56
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.3.0 to 1.0.0

157

dist/store-metrics.cjs.js

@@ -6,24 +6,49 @@ 'use strict';

var Cookies = _interopDefault(require('js-cookie'));
var CrossStorageClient = _interopDefault(require('cross-storage/lib/client'));
var utms = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
var DAYS_14 = 1209600000; // ms
var DAYS_120 = 10368000000; // ms
var hostnameToWildcard = function hostnameToWildcard(hostname) {
var hostParts = hostname.split(".");
return "." + (hostParts.length > 2 ? hostParts.slice(1).join(".") : hostParts.join("."));
var UTMs = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
var TTLs = {
utm: DAYS_14,
referrer: DAYS_14,
landing_page: DAYS_14,
discount: DAYS_14,
partner_id: DAYS_120,
promocode: DAYS_120,
sscid: DAYS_120
/**
* Converts hostname to wildcard domain
*
* Examples:
* www.livechat.com -> .livechat.com
* partners.labs.livechat.com -> .labs.livechat.com
*/
};var hostnameToWildcard = function hostnameToWildcard(hostname) {
var hostParts = hostname.split('.');
return '.' + (hostParts.length > 2 ? hostParts.slice(1).join('.') : hostParts.join('.'));
};
var extend = function extend(defaults, options) {
var extended = {};
var prop;
for (prop in defaults) {
if (Object.prototype.hasOwnProperty.call(defaults, prop)) {
extended[prop] = defaults[prop];
}
/**
* Gets cross-storage hub URL for given product hostname
*/
var getStorageUrl = function getStorageUrl(host) {
return 'https://accounts.' + (host.includes('labs') ? 'labs.' : '') + 'livechat.com/static/hub.html';
};
/**
* Converts hostname to product name
*
* Examples:
* www.helpdesk.com -> helpdesk
* partners.livechat.com -> livechat
*/
var hostnameToProduct = function hostnameToProduct(hostname) {
var hostParts = hostname.split('.');
if (hostParts.length > 1) {
return hostParts[hostParts.length - 2];
}
for (prop in options) {
if (Object.prototype.hasOwnProperty.call(options, prop)) {
extended[prop] = options[prop];
}
}
return extended;
};

@@ -34,21 +59,12 @@

var index = function () {
var referrer = document.referrer ? new window.URL(document.referrer) : null;
var out = {};
var location = new window.URL(document.location.href);
// Cookies are set for all subdomains, e.g. `.livechatinc.com`
var cookieDomain = hostnameToWildcard(location.hostname);
var cookieDefaults = {
domain: cookieDomain,
samesite: 'none',
secure: true
};
var product = hostnameToProduct(location.hostname);
var storageUrl = getStorageUrl(location.hostname);
var out = {};
var setParam = function setParam(name, value, options) {
var settings = extend(cookieDefaults, options);
Cookies.set(name, value, settings);
out[name] = value;
};
var inSession = Boolean(Cookies.get('metrics_session'));
// Handle UTM params
var foundUtms = utms.filter(function (utm) {
var foundUtms = UTMs.filter(function (utm) {
return location.searchParams.has(utm);

@@ -59,11 +75,7 @@ });

// when any param is present in query
// remove all saved previously
utms.forEach(function (utm) {
return Cookies.remove(utm, { domain: cookieDomain });
});
// overwrite all saved previously
out.utm = {};
// Store UTM params
// Duration: session
foundUtms.forEach(function (utm) {
setParam(utm, location.searchParams.get(utm));
out.utm[utm] = location.searchParams.get(utm);
});

@@ -73,47 +85,62 @@ }

// Store referrer
// Duration: session, overwritten
// Omit internal referrers
var referrer = document.referrer ? new window.URL(document.referrer) : null;
if (referrer && hostnameToWildcard(referrer.hostname) !== hostnameToWildcard(location.hostname)) {
setParam("referrer", referrer.href);
out.referrer = referrer.href;
}
// Store landing page
// Duration: session
if (!Cookies.get("landing_page")) {
setParam("landing_page", location.origin + location.pathname);
if (!inSession) {
out.landing_page = location.origin + location.pathname;
}
// Store discount
// Duration: session
if (location.searchParams.has("discount")) {
setParam("discount", location.searchParams.get("discount"));
if (location.searchParams.has('discount')) {
out.discount = location.searchParams.get('discount');
}
// Store affiliation
// Duration: 120 days
if (location.searchParams.has("a")) {
setParam("partner_id", location.searchParams.get("a"), {
expires: 120
});
if (location.searchParams.has('a')) {
out.partner_id = location.searchParams.get('a');
}
if (location.searchParams.has("partner_id")) {
setParam("partner_id", location.searchParams.get("partner_id"), {
expires: 120
});
if (location.searchParams.has('partner_id')) {
out.partner_id = location.searchParams.get('partner_id');
}
// Store promocode
// Duration: 120 days
if (location.searchParams.has("partner")) {
setParam("promocode", location.searchParams.get("partner"), {
expires: 120
});
// Store promocode (deprecated)
// TODO: Add logging
if (location.searchParams.has('partner')) {
out.promocode = location.searchParams.get('partner');
}
// http://shareasale.com/itp/lead.htm#_Toc522268050
if (location.searchParams.has("sscid")) {
setParam("sscid", location.searchParams.get("sscid"), {
expires: 120
if (location.searchParams.has('sscid')) {
out.sscid = location.searchParams.get('sscid');
}
// Send params to Accounts Client Store
var paramsToSave = Object.keys(out);
if (paramsToSave.length) {
// Initiate storage only when there is something to save
var storage = new CrossStorageClient(storageUrl);
var storagePromise = storage.onConnect();
paramsToSave.forEach(function (param) {
storagePromise.then(function () {
return storage.set(product + ':' + param, out[param], TTLs[param]);
});
});
storagePromise.catch(function (err) {
return console.error(err);
});
// Prevent some params overwriting in current 'session'
Cookies.set('metrics_session', 'true', {
domain: hostnameToWildcard(location.hostname),
samesite: 'none',
secure: true,
expires: 14
});
}

@@ -120,0 +147,0 @@

import Cookies from 'js-cookie';
import CrossStorageClient from 'cross-storage/lib/client';
var utms = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
var DAYS_14 = 1209600000; // ms
var DAYS_120 = 10368000000; // ms
var hostnameToWildcard = function hostnameToWildcard(hostname) {
var hostParts = hostname.split(".");
return "." + (hostParts.length > 2 ? hostParts.slice(1).join(".") : hostParts.join("."));
var UTMs = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
var TTLs = {
utm: DAYS_14,
referrer: DAYS_14,
landing_page: DAYS_14,
discount: DAYS_14,
partner_id: DAYS_120,
promocode: DAYS_120,
sscid: DAYS_120
/**
* Converts hostname to wildcard domain
*
* Examples:
* www.livechat.com -> .livechat.com
* partners.labs.livechat.com -> .labs.livechat.com
*/
};var hostnameToWildcard = function hostnameToWildcard(hostname) {
var hostParts = hostname.split('.');
return '.' + (hostParts.length > 2 ? hostParts.slice(1).join('.') : hostParts.join('.'));
};
var extend = function extend(defaults, options) {
var extended = {};
var prop;
for (prop in defaults) {
if (Object.prototype.hasOwnProperty.call(defaults, prop)) {
extended[prop] = defaults[prop];
}
/**
* Gets cross-storage hub URL for given product hostname
*/
var getStorageUrl = function getStorageUrl(host) {
return 'https://accounts.' + (host.includes('labs') ? 'labs.' : '') + 'livechat.com/static/hub.html';
};
/**
* Converts hostname to product name
*
* Examples:
* www.helpdesk.com -> helpdesk
* partners.livechat.com -> livechat
*/
var hostnameToProduct = function hostnameToProduct(hostname) {
var hostParts = hostname.split('.');
if (hostParts.length > 1) {
return hostParts[hostParts.length - 2];
}
for (prop in options) {
if (Object.prototype.hasOwnProperty.call(options, prop)) {
extended[prop] = options[prop];
}
}
return extended;
};

@@ -29,21 +54,12 @@

var index = function () {
var referrer = document.referrer ? new window.URL(document.referrer) : null;
var out = {};
var location = new window.URL(document.location.href);
// Cookies are set for all subdomains, e.g. `.livechatinc.com`
var cookieDomain = hostnameToWildcard(location.hostname);
var cookieDefaults = {
domain: cookieDomain,
samesite: 'none',
secure: true
};
var product = hostnameToProduct(location.hostname);
var storageUrl = getStorageUrl(location.hostname);
var out = {};
var setParam = function setParam(name, value, options) {
var settings = extend(cookieDefaults, options);
Cookies.set(name, value, settings);
out[name] = value;
};
var inSession = Boolean(Cookies.get('metrics_session'));
// Handle UTM params
var foundUtms = utms.filter(function (utm) {
var foundUtms = UTMs.filter(function (utm) {
return location.searchParams.has(utm);

@@ -54,11 +70,7 @@ });

// when any param is present in query
// remove all saved previously
utms.forEach(function (utm) {
return Cookies.remove(utm, { domain: cookieDomain });
});
// overwrite all saved previously
out.utm = {};
// Store UTM params
// Duration: session
foundUtms.forEach(function (utm) {
setParam(utm, location.searchParams.get(utm));
out.utm[utm] = location.searchParams.get(utm);
});

@@ -68,47 +80,62 @@ }

// Store referrer
// Duration: session, overwritten
// Omit internal referrers
var referrer = document.referrer ? new window.URL(document.referrer) : null;
if (referrer && hostnameToWildcard(referrer.hostname) !== hostnameToWildcard(location.hostname)) {
setParam("referrer", referrer.href);
out.referrer = referrer.href;
}
// Store landing page
// Duration: session
if (!Cookies.get("landing_page")) {
setParam("landing_page", location.origin + location.pathname);
if (!inSession) {
out.landing_page = location.origin + location.pathname;
}
// Store discount
// Duration: session
if (location.searchParams.has("discount")) {
setParam("discount", location.searchParams.get("discount"));
if (location.searchParams.has('discount')) {
out.discount = location.searchParams.get('discount');
}
// Store affiliation
// Duration: 120 days
if (location.searchParams.has("a")) {
setParam("partner_id", location.searchParams.get("a"), {
expires: 120
});
if (location.searchParams.has('a')) {
out.partner_id = location.searchParams.get('a');
}
if (location.searchParams.has("partner_id")) {
setParam("partner_id", location.searchParams.get("partner_id"), {
expires: 120
});
if (location.searchParams.has('partner_id')) {
out.partner_id = location.searchParams.get('partner_id');
}
// Store promocode
// Duration: 120 days
if (location.searchParams.has("partner")) {
setParam("promocode", location.searchParams.get("partner"), {
expires: 120
});
// Store promocode (deprecated)
// TODO: Add logging
if (location.searchParams.has('partner')) {
out.promocode = location.searchParams.get('partner');
}
// http://shareasale.com/itp/lead.htm#_Toc522268050
if (location.searchParams.has("sscid")) {
setParam("sscid", location.searchParams.get("sscid"), {
expires: 120
if (location.searchParams.has('sscid')) {
out.sscid = location.searchParams.get('sscid');
}
// Send params to Accounts Client Store
var paramsToSave = Object.keys(out);
if (paramsToSave.length) {
// Initiate storage only when there is something to save
var storage = new CrossStorageClient(storageUrl);
var storagePromise = storage.onConnect();
paramsToSave.forEach(function (param) {
storagePromise.then(function () {
return storage.set(product + ':' + param, out[param], TTLs[param]);
});
});
storagePromise.catch(function (err) {
return console.error(err);
});
// Prevent some params overwriting in current 'session'
Cookies.set('metrics_session', 'true', {
domain: hostnameToWildcard(location.hostname),
samesite: 'none',
secure: true,
expires: 14
});
}

@@ -115,0 +142,0 @@

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,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),a=encodeURIComponent(e.value);n||(t+="&"),t+=r+"="+a,n=!1}),t.replace(/%20/g,"+")}function a(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),a=e.substring(t+1);else n=e,a="";n=n.replace(/\+/g," "),a=a.replace(/\+/g," "),r.push({name:n,value:a})}});var a=[];return r.forEach(function(e){a.push({name:decodeURIComponent(e.name),value:decodeURIComponent(e.value)})}),a}function o(e){var i=this;this._list=[],void 0===e||null===e||(e instanceof o?this._list=a(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=a(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?a(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 s(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 a=r.createElement("base");a.href=n,r.getElementsByTagName("head")[0].appendChild(a);var o=r.createElement("a");return o.href=t,o.href}finally{e&&e.parentNode.removeChild(e)}}());var u=function(e){if(c)return new s(e);var t=document.createElement("a");return t.href=e,t}(t||""),l=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 o(u.search?u.search.substring(1):null);return f._url_object=l,Object.defineProperties(l,{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}}),l}var c,s=e.URL;try{if(s){if("searchParams"in(c=new e.URL("http://example.com")))return;"href"in c||(c=void 0)}}catch(e){}if(Object.defineProperties(o.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(o.prototype,e.Symbol.iterator,{value:o.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})),s)for(var l in s)s.hasOwnProperty(l)&&"function"==typeof s[l]&&(u[l]=s[l]);e.URL=u,e.URLSearchParams=o}(),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 a=new r;return n(e).forEach(function(e){if(!t(e))throw TypeError();var r=n(e);if(2!==r.length)throw TypeError();a.append(r[0],r[1])}),a}return e&&"object"==typeof e?(a=new r,Object.keys(e).forEach(function(t){a.set(t,e[t])}),a):new r(e)}}}()}(self);var e=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,a,o){var i;if("undefined"!=typeof document){if(arguments.length>1){if("number"==typeof(o=e({path:"/"},r.defaults,o)).expires){var u=new Date;u.setMilliseconds(u.getMilliseconds()+864e5*o.expires),o.expires=u}o.expires=o.expires?o.expires.toUTCString():"";try{i=JSON.stringify(a),/^[\{\[]/.test(i)&&(a=i)}catch(e){}a=n.write?n.write(a,t):encodeURIComponent(String(a)).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 s in o)o[s]&&(c+="; "+s,!0!==o[s]&&(c+="="+o[s]));return document.cookie=t+"="+a+c}t||(i={});for(var l=document.cookie?document.cookie.split("; "):[],f=/(%[0-9A-Z]{2})+/g,h=0;h<l.length;h++){var m=l[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(){})})}),t=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],n=function(e){var t=e.split(".");return"."+(t.length>2?t.slice(1).join("."):t.join("."))};!function(){var r=document.referrer?new window.URL(document.referrer):null,a=new window.URL(document.location.href),o=n(a.hostname),i={domain:o,samesite:"none",secure:!0},u={},c=function(t,n,r){var a=function(e,t){var n,r={};for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);for(n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n]);return r}(i,r);e.set(t,n,a),u[t]=n},s=t.filter(function(e){return a.searchParams.has(e)});s.length&&(t.forEach(function(t){return e.remove(t,{domain:o})}),s.forEach(function(e){c(e,a.searchParams.get(e))})),r&&n(r.hostname)!==n(a.hostname)&&c("referrer",r.href),e.get("landing_page")||c("landing_page",a.origin+a.pathname),a.searchParams.has("discount")&&c("discount",a.searchParams.get("discount")),a.searchParams.has("a")&&c("partner_id",a.searchParams.get("a"),{expires:120}),a.searchParams.has("partner_id")&&c("partner_id",a.searchParams.get("partner_id"),{expires:120}),a.searchParams.has("partner")&&c("promocode",a.searchParams.get("partner"),{expires:120}),a.searchParams.has("sscid")&&c("sscid",a.searchParams.get("sscid"),{expires:120})}()});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";function e(e,t){return t={exports:{}},e(t,t.exports),t.exports}"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var t=e(function(e,t){!function(t){if(e.exports=t(),!!0){var r=window.Cookies,n=window.Cookies=t();n.noConflict=function(){return window.Cookies=r,n}}}(function(){function e(){for(var e=0,t={};e<arguments.length;e++){var r=arguments[e];for(var n in r)t[n]=r[n]}return t}function t(r){function n(t,o,s){var i;if("undefined"!=typeof document){if(arguments.length>1){if("number"==typeof(s=e({path:"/"},n.defaults,s)).expires){var a=new Date;a.setMilliseconds(a.getMilliseconds()+864e5*s.expires),s.expires=a}s.expires=s.expires?s.expires.toUTCString():"";try{i=JSON.stringify(o),/^[\{\[]/.test(i)&&(o=i)}catch(e){}o=r.write?r.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 u in s)s[u]&&(c+="; "+u,!0!==s[u]&&(c+="="+s[u]));return document.cookie=t+"="+o+c}t||(i={});for(var l=document.cookie?document.cookie.split("; "):[],d=/(%[0-9A-Z]{2})+/g,f=0;f<l.length;f++){var p=l[f].split("="),h=p.slice(1).join("=");this.json||'"'!==h.charAt(0)||(h=h.slice(1,-1));try{var m=p[0].replace(d,decodeURIComponent);if(h=r.read?r.read(h,m):r(h,m)||h.replace(d,decodeURIComponent),this.json)try{h=JSON.parse(h)}catch(e){}if(t===m){i=h;break}t||(i[m]=h)}catch(e){}}return i}}return n.set=n,n.get=function(e){return n.call(n,e)},n.getJSON=function(){return n.apply({json:!0},[].slice.call(arguments))},n.defaults={},n.remove=function(t,r){n(t,"",e(r,{expires:-1}))},n.withConverter=t,n}return t(function(){})})}),r=e(function(e,t){!function(r){function n(e,t){t=t||{},this._id=n._generateUUID(),this._promise=t.promise||Promise,this._frameId=t.frameId||"CrossStorageClient-"+this._id,this._origin=n._getOrigin(e),this._requests={},this._connected=!1,this._closed=!1,this._count=0,this._timeout=t.timeout||5e3,this._listener=null,this._installListener();var r;t.frameId&&(r=document.getElementById(t.frameId)),r&&this._poll(),r=r||this._createFrame(e),this._hub=r.contentWindow}n.frameStyle={display:"none",position:"absolute",top:"-999px",left:"-999px"},n._getOrigin=function(e){var t,r,n;return t=document.createElement("a"),t.href=e,t.host||(t=window.location),r=t.protocol&&":"!==t.protocol?t.protocol:window.location.protocol,n=r+"//"+t.host,n=n.replace(/:80$|:443$/,"")},n._generateUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})},n.prototype.onConnect=function(){var e=this;return this._connected?this._promise.resolve():this._closed?this._promise.reject(new Error("CrossStorageClient has closed")):(this._requests.connect||(this._requests.connect=[]),new this._promise(function(t,r){var n=setTimeout(function(){r(new Error("CrossStorageClient could not connect"))},e._timeout);e._requests.connect.push(function(e){if(clearTimeout(n),e)return r(e);t()})}))},n.prototype.set=function(e,t,r){return this._request("set",{key:e,value:t,ttl:r})},n.prototype.get=function(e){var t=Array.prototype.slice.call(arguments);return this._request("get",{keys:t})},n.prototype.del=function(){var e=Array.prototype.slice.call(arguments);return this._request("del",{keys:e})},n.prototype.clear=function(){return this._request("clear")},n.prototype.getKeys=function(){return this._request("getKeys")},n.prototype.close=function(){var e=document.getElementById(this._frameId);e&&e.parentNode.removeChild(e),window.removeEventListener?window.removeEventListener("message",this._listener,!1):window.detachEvent("onmessage",this._listener),this._connected=!1,this._closed=!0},n.prototype._installListener=function(){var e=this;this._listener=function(t){var r,n,o;if(!e._closed&&t.data&&"string"==typeof t.data&&("null"===t.origin?"file://":t.origin)===e._origin)if("cross-storage:unavailable"!==t.data){if(-1!==t.data.indexOf("cross-storage:")&&!e._connected){if(e._connected=!0,!e._requests.connect)return;for(r=0;r<e._requests.connect.length;r++)e._requests.connect[r](n);delete e._requests.connect}if("cross-storage:ready"!==t.data){try{o=JSON.parse(t.data)}catch(e){return}o.id&&e._requests[o.id]&&e._requests[o.id](o.error,o.result)}}else{if(e._closed||e.close(),!e._requests.connect)return;for(n=new Error("Closing client. Could not access localStorage in hub."),r=0;r<e._requests.connect.length;r++)e._requests.connect[r](n)}},window.addEventListener?window.addEventListener("message",this._listener,!1):window.attachEvent("onmessage",this._listener)},n.prototype._poll=function(){var e,t,r;r="file://"===(e=this)._origin?"*":e._origin,t=setInterval(function(){if(e._connected)return clearInterval(t);e._hub&&e._hub.postMessage("cross-storage:poll",r)},1e3)},n.prototype._createFrame=function(e){var t,r;(t=window.document.createElement("iframe")).id=this._frameId;for(r in n.frameStyle)n.frameStyle.hasOwnProperty(r)&&(t.style[r]=n.frameStyle[r]);return window.document.body.appendChild(t),t.src=e,t},n.prototype._request=function(e,t){var r,n;return this._closed?this._promise.reject(new Error("CrossStorageClient has closed")):(n=this,n._count++,r={id:this._id+":"+n._count,method:"cross-storage:"+e,params:t},new this._promise(function(e,t){var o,s,i;o=setTimeout(function(){n._requests[r.id]&&(delete n._requests[r.id],t(new Error("Timeout: could not perform "+r.method)))},n._timeout),n._requests[r.id]=function(s,i){if(clearTimeout(o),delete n._requests[r.id],s)return t(new Error(s));e(i)},Array.prototype.toJSON&&(s=Array.prototype.toJSON,Array.prototype.toJSON=null),i="file://"===n._origin?"*":n._origin,n._hub.postMessage(JSON.stringify(r),i),s&&(Array.prototype.toJSON=s)}))},e.exports?e.exports=n:t.CrossStorageClient=n}()}),n=(r.CrossStorageClient,["utm_source","utm_medium","utm_campaign","utm_term","utm_content"]),o={utm:12096e5,referrer:12096e5,landing_page:12096e5,discount:12096e5,partner_id:10368e6,promocode:10368e6,sscid:10368e6},s=function(e){var t=e.split(".");return"."+(t.length>2?t.slice(1).join("."):t.join("."))};!function(){var e={},i=new window.URL(document.location.href),a=function(e){var t=i.hostname.split(".");if(t.length>1)return t[t.length-2]}(),c="https://accounts."+(i.hostname.includes("labs")?"labs.":"")+"livechat.com/static/hub.html",u=Boolean(t.get("metrics_session")),l=n.filter(function(e){return i.searchParams.has(e)});l.length&&(e.utm={},l.forEach(function(t){e.utm[t]=i.searchParams.get(t)}));var d=document.referrer?new window.URL(document.referrer):null;d&&s(d.hostname)!==s(i.hostname)&&(e.referrer=d.href),u||(e.landing_page=i.origin+i.pathname),i.searchParams.has("discount")&&(e.discount=i.searchParams.get("discount")),i.searchParams.has("a")&&(e.partner_id=i.searchParams.get("a")),i.searchParams.has("partner_id")&&(e.partner_id=i.searchParams.get("partner_id")),i.searchParams.has("partner")&&(e.promocode=i.searchParams.get("partner")),i.searchParams.has("sscid")&&(e.sscid=i.searchParams.get("sscid"));var f=Object.keys(e);if(f.length){var p=new r(c),h=p.onConnect();f.forEach(function(t){h.then(function(){return p.set(a+":"+t,e[t],o[t])})}),h.catch(function(e){return console.error(e)}),t.set("metrics_session","true",{domain:s(i.hostname),samesite:"none",secure:!0,expires:14})}}()});
{
"name": "@livechat/store-metrics",
"version": "0.3.0",
"version": "1.0.0",
"description": "",

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

"dependencies": {
"js-cookie": "^2.2.0",
"js-polyfills": "^0.1.41"
"cross-storage": "0.8.2",
"js-cookie": "^2.2.0"
}
}
# @livechat/store-metrics
Reads and stores various marketing parameters as cookies. Super Important Thing for Marketing Team™.
Reads and stores various marketing parameters in Accounts Client Store. Super Important Thing for Marketing Team™. Only 3.1kB gzipped.

@@ -15,3 +15,3 @@ ## Installation

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.
Library exposes only one function that saves source attribution and Partner Program affiliation params based on `document.location` and `document.referrer`. Make sure to fire it as early as possible, before redirects etc.

@@ -23,15 +23,5 @@ ```js

**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
For websites without module bundler/resolver you can use self-executing version of store-metrics that comes bundled with URL API polyfill. You can load it directly from our CDN:
For websites without module bundler/resolver you can use self-executing version of store-metrics. You can load it directly from our CDN:

@@ -59,2 +49,13 @@ ```html

### 1.0.0 — 2021-05-25
#### Changed
- Storage mechanism changed from cookies to cross-domain localStorage, to support multi-product Global Accounts
- Because there is no 'session' concpet in localStorage, default TTL is set to 2 weeks
#### Removed
- IE no longer supported
- URL API polyfill
### 0.4.0 [YANKED]
### 0.3.0 — 2020-06-17

@@ -61,0 +62,0 @@ #### Added

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