analytics-id
Advanced tools
Comparing version 0.1.0 to 1.0.1
@@ -109,4 +109,5 @@ (function (global, factory) { | ||
key: 'ajs_user_id', | ||
generateId: function generateId() { | ||
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'ajs'; | ||
generateId: function generateId(_ref) { | ||
var _ref$prefix = _ref.prefix, | ||
prefix = _ref$prefix === undefined ? 'ajs' : _ref$prefix; | ||
return [prefix, uuidV4()].join('-'); | ||
@@ -261,3 +262,4 @@ }, | ||
localStorage = opts.localStorage, | ||
domain = opts.domain; | ||
domain = opts.domain, | ||
prefix = opts.prefix; | ||
@@ -279,3 +281,3 @@ var log$$1 = log({ debug: debug }); | ||
if (!id) { | ||
id = generateId(); | ||
id = generateId({ prefix: prefix }); | ||
log$$1('set: created new id {id: "' + id + '"}'); | ||
@@ -386,3 +388,4 @@ } else { | ||
cookie = opts.cookie, | ||
localStorage = opts.localStorage; | ||
localStorage = opts.localStorage, | ||
prefix = opts.prefix; | ||
@@ -434,3 +437,3 @@ var log$$1 = log({ debug: debug }); | ||
var newId = generateId(); | ||
var newId = generateId({ prefix: prefix }); | ||
@@ -437,0 +440,0 @@ if (persist) { |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.AnalyticsId=t()}(this,function(){"use strict";for(var v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var o=[],r=!0,n=!1,i=void 0;try{for(var a,c=e[Symbol.iterator]();!(r=(a=c.next()).done)&&(o.push(a.value),!t||o.length!==t);r=!0);}catch(e){n=!0,i=e}finally{try{!r&&c.return&&c.return()}finally{if(n)throw i}}return o}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},b=function(e){var a=e.debug;return function(){for(var e=arguments.length,t=Array(e),o=0;o<e;o++)t[o]=arguments[o];if(a){var r,n=t[0],i=t.slice(1);(r=console).log.apply(r,["analyticsId."+n].concat(function(e){if(Array.isArray(e)){for(var t=0,o=Array(e.length);t<e.length;t++)o[t]=e[t];return o}return Array.from(e)}(i)))}}},o=[],e=0;e<=15;e++)o.push(e.toString(16));var t=function(){for(var e="",t=1;t<=36;t++)e+=9===t||14===t||19===t||24===t?"-":15===t?4:20===t?o[4*Math.random()|8]:o[15*Math.random()|0];return e},m={segment:{stores:["cookie","localStorage"],key:"ajs_user_id",generateId:function(){return[0<arguments.length&&void 0!==arguments[0]?arguments[0]:"ajs",t()].join("-")},mutate:!0,persist:!0}};var r={get:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.key;return function(){var e=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:"").split("; "),t={};if(0===e.length||1===e.length&&""===e[0])return t;for(var o=0;o<e.length;o++){var r=e[o].split("="),n=c(r,2),i=n[0],a=n[1];t[i]=decodeURIComponent(a)}return t}(e.cookie)[t]},set:function(){var e,t,o,r,n,i,a,c,u=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},d=u.key,l=u.id,s=u.mutate,f=u.domain,g=u.cookie,y=!1;try{g=document.cookie,y=!0}catch(e){g=""}return y&&(t=(e={name:d,value:l,path:"/",domain:f}).name,o=e.value,r=e.expires,n=e.domain,i=e.path,a=e.secure,c=(c=void 0)!==o&&"object"===(void 0===o?"undefined":v(o))?JSON.stringify(o):encodeURIComponent(o),document.cookie=t+"="+c+(r?"; expires="+new Date(r).toUTCString():"")+"; path="+(i||"/")+(n?"; domain="+n:"")+(a?"; secure":"")),s||(g=""+g),[g,d+"="+encodeURIComponent(l)].filter(Boolean).join("; ")}};var n={get:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.key,o=e.localStorage,r=void 0===o?{}:o;return r.getItem?r.getItem(t):r[t]},set:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.key,o=e.id,r=e.localStorage,n=void 0===r?{}:r,i=e.mutate?n:Object.assign({},n);return i.setItem?i.setItem(t,o):i[t]=o,i}},i={get:{cookie:r.get,localStorage:n.get},set:{cookie:r.set,localStorage:n.set}},k=i.set,h=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.id,o=e.debug,r=e.preset,n=void 0===r?"segment":r,i=e.cookie,a=e.localStorage,c=e.domain,u=b({debug:o});m[n]||(n="segment");var d=m[n],l=d.generateId,s=d.key,f=d.stores,g=d.mutate;u(t?'set: using {id: "'+t+'"}':'set: created new id {id: "'+(t=l())+'"}');var y=void 0;if(!a)try{a=window.localStorage}catch(e){}try{(y=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.debug,o=e.key,r=e.id,n=e.stores,i=e.mutate,a=e.cookie,c=e.localStorage,u=e.domain,d={},l=b({debug:t}),s=!0,f=!1,g=void 0;try{for(var y,v=n[Symbol.iterator]();!(s=(y=v.next()).done);s=!0){var m=y.value;try{var h=k[m],p=h({key:o,id:r,mutate:i,cookie:a,localStorage:c,domain:u});p?(l("set."+m+': success {id: "'+r+'"}'),d[m]=p):l("set."+m+': fail {id: "'+r+'"}')}catch(e){l("set."+m+': fail {id: "'+r+'"}'),console.error(e)}}}catch(e){f=!0,g=e}finally{try{!s&&v.return&&v.return()}finally{if(f)throw g}}return d}({debug:o,key:s,id:t,stores:f,mutate:g,cookie:i,localStorage:a,domain:c})).status="success"}catch(e){u("set: error",e),y={status:"error",error:e}}return y};var p=i.get,a=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.debug,o=e.preset,r=void 0===o?"segment":o,n=e.env,i=void 0===n?"":n,a=e.cookie,c=e.localStorage,u=b({debug:t});m[r]||(r="segment");var d=m[r],l=d.generateId,s=d.key,f=d.stores,g=d.persist;if(function(){return"browser"===(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).env||"undefined"!=typeof window}({env:i})){if(!c)try{c=window.localStorage}catch(e){}if(!a)try{a=document.cookie}catch(e){}var y=function(e){var t=e.debug,o=e.stores,r=e.key,n=e.cookie,i=e.localStorage,a=b({debug:t}),c=!0,u=!1,d=void 0;try{for(var l,s=o[Symbol.iterator]();!(c=(l=s.next()).done);c=!0){var f=l.value,g=p[f],y=g({key:r,cookie:n,localStorage:i});if(y)return a('get.browser: hit {store: "'+f+'", key: "'+r+'"}'),y;a('get.browser: miss {store: "'+f+'", key: "'+r+'"}')}}catch(e){u=!0,d=e}finally{try{!c&&s.return&&s.return()}finally{if(u)throw d}}return""}({debug:t,stores:f,key:s,cookie:a,localStorage:c});if(y)return u('get: found browser id {id: "'+y+'"}'),y}var v=l();return g&&(u('get: persisting new id {id: "'+v+'"}'),h({debug:t,key:s,id:v,cookie:e.cookie,localStorage:e.localStorage})),v};function u(e){return"string"==typeof e||"number"==typeof e?h({id:e}):"object"===(void 0===e?"undefined":v(e))?void 0!==e.id?h(e):a(e):a()}return u.get=a,u.set=h,u}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.AnalyticsId=t()}(this,function(){"use strict";for(var v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var o=[],r=!0,n=!1,i=void 0;try{for(var a,c=e[Symbol.iterator]();!(r=(a=c.next()).done)&&(o.push(a.value),!t||o.length!==t);r=!0);}catch(e){n=!0,i=e}finally{try{!r&&c.return&&c.return()}finally{if(n)throw i}}return o}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},b=function(e){var a=e.debug;return function(){for(var e=arguments.length,t=Array(e),o=0;o<e;o++)t[o]=arguments[o];if(a){var r,n=t[0],i=t.slice(1);(r=console).log.apply(r,["analyticsId."+n].concat(function(e){if(Array.isArray(e)){for(var t=0,o=Array(e.length);t<e.length;t++)o[t]=e[t];return o}return Array.from(e)}(i)))}}},o=[],e=0;e<=15;e++)o.push(e.toString(16));var r=function(){for(var e="",t=1;t<=36;t++)e+=9===t||14===t||19===t||24===t?"-":15===t?4:20===t?o[4*Math.random()|8]:o[15*Math.random()|0];return e},p={segment:{stores:["cookie","localStorage"],key:"ajs_user_id",generateId:function(e){var t=e.prefix;return[void 0===t?"ajs":t,r()].join("-")},mutate:!0,persist:!0}};var t={get:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.key;return function(){var e=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:"").split("; "),t={};if(0===e.length||1===e.length&&""===e[0])return t;for(var o=0;o<e.length;o++){var r=e[o].split("="),n=c(r,2),i=n[0],a=n[1];t[i]=decodeURIComponent(a)}return t}(e.cookie)[t]},set:function(){var e,t,o,r,n,i,a,c,u=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},d=u.key,l=u.id,s=u.mutate,f=u.domain,g=u.cookie,y=!1;try{g=document.cookie,y=!0}catch(e){g=""}return y&&(t=(e={name:d,value:l,path:"/",domain:f}).name,o=e.value,r=e.expires,n=e.domain,i=e.path,a=e.secure,c=(c=void 0)!==o&&"object"===(void 0===o?"undefined":v(o))?JSON.stringify(o):encodeURIComponent(o),document.cookie=t+"="+c+(r?"; expires="+new Date(r).toUTCString():"")+"; path="+(i||"/")+(n?"; domain="+n:"")+(a?"; secure":"")),s||(g=""+g),[g,d+"="+encodeURIComponent(l)].filter(Boolean).join("; ")}};var n={get:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.key,o=e.localStorage,r=void 0===o?{}:o;return r.getItem?r.getItem(t):r[t]},set:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.key,o=e.id,r=e.localStorage,n=void 0===r?{}:r,i=e.mutate?n:Object.assign({},n);return i.setItem?i.setItem(t,o):i[t]=o,i}},i={get:{cookie:t.get,localStorage:n.get},set:{cookie:t.set,localStorage:n.set}},k=i.set,h=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.id,o=e.debug,r=e.preset,n=void 0===r?"segment":r,i=e.cookie,a=e.localStorage,c=e.domain,u=e.prefix,d=b({debug:o});p[n]||(n="segment");var l=p[n],s=l.generateId,f=l.key,g=l.stores,y=l.mutate;d(t?'set: using {id: "'+t+'"}':'set: created new id {id: "'+(t=s({prefix:u}))+'"}');var v=void 0;if(!a)try{a=window.localStorage}catch(e){}try{(v=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.debug,o=e.key,r=e.id,n=e.stores,i=e.mutate,a=e.cookie,c=e.localStorage,u=e.domain,d={},l=b({debug:t}),s=!0,f=!1,g=void 0;try{for(var y,v=n[Symbol.iterator]();!(s=(y=v.next()).done);s=!0){var m=y.value;try{var p=k[m],h=p({key:o,id:r,mutate:i,cookie:a,localStorage:c,domain:u});h?(l("set."+m+': success {id: "'+r+'"}'),d[m]=h):l("set."+m+': fail {id: "'+r+'"}')}catch(e){l("set."+m+': fail {id: "'+r+'"}'),console.error(e)}}}catch(e){f=!0,g=e}finally{try{!s&&v.return&&v.return()}finally{if(f)throw g}}return d}({debug:o,key:f,id:t,stores:g,mutate:y,cookie:i,localStorage:a,domain:c})).status="success"}catch(e){d("set: error",e),v={status:"error",error:e}}return v};var S=i.get,a=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.debug,o=e.preset,r=void 0===o?"segment":o,n=e.env,i=void 0===n?"":n,a=e.cookie,c=e.localStorage,u=e.prefix,d=b({debug:t});p[r]||(r="segment");var l=p[r],s=l.generateId,f=l.key,g=l.stores,y=l.persist;if(function(){return"browser"===(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).env||"undefined"!=typeof window}({env:i})){if(!c)try{c=window.localStorage}catch(e){}if(!a)try{a=document.cookie}catch(e){}var v=function(e){var t=e.debug,o=e.stores,r=e.key,n=e.cookie,i=e.localStorage,a=b({debug:t}),c=!0,u=!1,d=void 0;try{for(var l,s=o[Symbol.iterator]();!(c=(l=s.next()).done);c=!0){var f=l.value,g=S[f],y=g({key:r,cookie:n,localStorage:i});if(y)return a('get.browser: hit {store: "'+f+'", key: "'+r+'"}'),y;a('get.browser: miss {store: "'+f+'", key: "'+r+'"}')}}catch(e){u=!0,d=e}finally{try{!c&&s.return&&s.return()}finally{if(u)throw d}}return""}({debug:t,stores:g,key:f,cookie:a,localStorage:c});if(v)return d('get: found browser id {id: "'+v+'"}'),v}var m=s({prefix:u});return y&&(d('get: persisting new id {id: "'+m+'"}'),h({debug:t,key:f,id:m,cookie:e.cookie,localStorage:e.localStorage})),m};function u(e){return"string"==typeof e||"number"==typeof e?h({id:e}):"object"===(void 0===e?"undefined":v(e))?void 0!==e.id?h(e):a(e):a()}return u.get=a,u.set=h,u}); |
@@ -103,4 +103,5 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
key: 'ajs_user_id', | ||
generateId: function generateId() { | ||
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'ajs'; | ||
generateId: function generateId(_ref) { | ||
var _ref$prefix = _ref.prefix, | ||
prefix = _ref$prefix === undefined ? 'ajs' : _ref$prefix; | ||
return [prefix, uuidV4()].join('-'); | ||
@@ -255,3 +256,4 @@ }, | ||
localStorage = opts.localStorage, | ||
domain = opts.domain; | ||
domain = opts.domain, | ||
prefix = opts.prefix; | ||
@@ -273,3 +275,3 @@ var log$$1 = log({ debug: debug }); | ||
if (!id) { | ||
id = generateId(); | ||
id = generateId({ prefix: prefix }); | ||
log$$1('set: created new id {id: "' + id + '"}'); | ||
@@ -380,3 +382,4 @@ } else { | ||
cookie = opts.cookie, | ||
localStorage = opts.localStorage; | ||
localStorage = opts.localStorage, | ||
prefix = opts.prefix; | ||
@@ -428,3 +431,3 @@ var log$$1 = log({ debug: debug }); | ||
var newId = generateId(); | ||
var newId = generateId({ prefix: prefix }); | ||
@@ -431,0 +434,0 @@ if (persist) { |
@@ -105,4 +105,5 @@ 'use strict'; | ||
key: 'ajs_user_id', | ||
generateId: function generateId() { | ||
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'ajs'; | ||
generateId: function generateId(_ref) { | ||
var _ref$prefix = _ref.prefix, | ||
prefix = _ref$prefix === undefined ? 'ajs' : _ref$prefix; | ||
return [prefix, uuidV4()].join('-'); | ||
@@ -257,3 +258,4 @@ }, | ||
localStorage = opts.localStorage, | ||
domain = opts.domain; | ||
domain = opts.domain, | ||
prefix = opts.prefix; | ||
@@ -275,3 +277,3 @@ var log$$1 = log({ debug: debug }); | ||
if (!id) { | ||
id = generateId(); | ||
id = generateId({ prefix: prefix }); | ||
log$$1('set: created new id {id: "' + id + '"}'); | ||
@@ -382,3 +384,4 @@ } else { | ||
cookie = opts.cookie, | ||
localStorage = opts.localStorage; | ||
localStorage = opts.localStorage, | ||
prefix = opts.prefix; | ||
@@ -430,3 +433,3 @@ var log$$1 = log({ debug: debug }); | ||
var newId = generateId(); | ||
var newId = generateId({ prefix: prefix }); | ||
@@ -433,0 +436,0 @@ if (persist) { |
{ | ||
"name": "analytics-id", | ||
"version": "0.1.0", | ||
"version": "1.0.1", | ||
"description": "get and set analytics ids on the server and in the browser", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -43,5 +43,7 @@ <p align="center"> | ||
analyticsId() // generate or pull id from cookie/localStorage | ||
// generate or pull id from cookie/localStorage | ||
analyticsId() | ||
analyticsId('exampleId') // call the function with string or number to set as id, otherwise pass in options | ||
// call the function with string or number to set as id, otherwise pass in options | ||
analyticsId('exampleId') | ||
``` | ||
@@ -48,0 +50,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
80568
1287
0
97