analytics-event
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -632,2 +632,36 @@ (function (global, factory) { | ||
var segment$1 = function formatSegment(event) { | ||
var newEvent = {}; | ||
if (event.name) { | ||
newEvent.event = event.name; | ||
} | ||
if (event.timestamp) { | ||
newEvent.timestamp = event.timestamp; | ||
} | ||
if (event.messageId) { | ||
newEvent.messageId = event.messageId; | ||
} | ||
if (event.properties) { | ||
newEvent.properties = event.properties; | ||
} | ||
if (event.context) { | ||
newEvent.context = event.context; | ||
} | ||
if (event.userId) { | ||
newEvent.userId = event.userId; | ||
} | ||
if (event.anonymousId) { | ||
newEvent.anonymousId = event.anonymousId; | ||
} | ||
return newEvent; | ||
}; | ||
var short_1 = function formatShort(event) { | ||
@@ -664,3 +698,4 @@ var newEvent = {}; | ||
var formatByType = { | ||
short: short_1 | ||
short: short_1, | ||
segment: segment$1 | ||
}; | ||
@@ -667,0 +702,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.AnalyticsEvent=t()}(this,function(){"use strict";var r=function(e){var i=e.debug;return function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];if(i){var o,n=t[0],a=t.slice(1);(o=console).log.apply(o,["analyticsEvent."+n].concat(function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}(a)))}}};for(var e=function(e,t){r("validate")},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},s=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],o=!0,n=!1,a=void 0;try{for(var i,s=e[Symbol.iterator]();!(o=(i=s.next()).done)&&(r.push(i.value),!t||r.length!==t);o=!0);}catch(e){n=!0,a=e}finally{try{!o&&s.return&&s.return()}finally{if(n)throw a}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},b=function(e){var i=e.debug;return function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];if(i){var o,n=t[0],a=t.slice(1);(o=console).log.apply(o,["analyticsId."+n].concat(function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}(a)))}}},o=[],t=0;t<=15;t++)o.push(t.toString(16));var n=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,n()].join("-")},mutate:!0,persist:!0}};var a={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 r=0;r<e.length;r++){var o=e[r].split("="),n=s(o,2),a=n[0],i=n[1];t[a]=decodeURIComponent(i)}return t}(e.cookie)[t]},set:function(){var e,t,r,o,n,a,i,s,c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},u=c.key,d=c.id,f=c.mutate,l=c.domain,g=c.cookie,m=!1;try{g=document.cookie,m=!0}catch(e){g=""}return m&&(t=(e={name:u,value:d,path:"/",domain:l}).name,r=e.value,o=e.expires,n=e.domain,a=e.path,i=e.secure,s=(s=void 0)!==r&&"object"===(void 0===r?"undefined":v(r))?JSON.stringify(r):encodeURIComponent(r),document.cookie=t+"="+s+(o?"; expires="+new Date(o).toUTCString():"")+"; path="+(a||"/")+(n?"; domain="+n:"")+(i?"; secure":"")),f||(g=""+g),[g,u+"="+encodeURIComponent(d)].filter(Boolean).join("; ")}};var i={get:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.key,r=e.localStorage,o=void 0===r?{}:r;return o.getItem?o.getItem(t):o[t]},set:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.key,r=e.id,o=e.localStorage,n=void 0===o?{}:o,a=e.mutate?n:Object.assign({},n);return a.setItem?a.setItem(t,r):a[t]=r,a}},c={get:{cookie:a.get,localStorage:i.get},set:{cookie:a.set,localStorage:i.set}},k=c.set,h=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.id,r=e.debug,o=e.preset,n=void 0===o?"segment":o,a=e.cookie,i=e.localStorage,s=e.domain,c=e.prefix,u=b({debug:r});p[n]||(n="segment");var d=p[n],f=d.generateId,l=d.key,g=d.stores,m=d.mutate;u(t?'set: using {id: "'+t+'"}':'set: created new id {id: "'+(t=f({prefix:c}))+'"}');var v=void 0;if(!i)try{i=window.localStorage}catch(e){}try{(v=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.debug,r=e.key,o=e.id,n=e.stores,a=e.mutate,i=e.cookie,s=e.localStorage,c=e.domain,u={},d=b({debug:t}),f=!0,l=!1,g=void 0;try{for(var m,v=n[Symbol.iterator]();!(f=(m=v.next()).done);f=!0){var y=m.value;try{var p=k[y],h=p({key:r,id:o,mutate:a,cookie:i,localStorage:s,domain:c});h?(d("set."+y+': success {id: "'+o+'"}'),u[y]=h):d("set."+y+': fail {id: "'+o+'"}')}catch(e){d("set."+y+': fail {id: "'+o+'"}'),console.error(e)}}}catch(e){l=!0,g=e}finally{try{!f&&v.return&&v.return()}finally{if(l)throw g}}return u}({debug:r,key:l,id:t,stores:g,mutate:m,cookie:a,localStorage:i,domain:s})).status="success"}catch(e){u("set: error",e),v={status:"error",error:e}}return v};var S=c.get,u=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.debug,r=e.preset,o=void 0===r?"segment":r,n=e.env,a=void 0===n?"":n,i=e.cookie,s=e.localStorage,c=e.prefix,u=b({debug:t});p[o]||(o="segment");var d=p[o],f=d.generateId,l=d.key,g=d.stores,m=d.persist;if(function(){return"browser"===(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).env||"undefined"!=typeof window}({env:a})){if(!s)try{s=window.localStorage}catch(e){}if(!i)try{i=document.cookie}catch(e){}var v=function(e){var t=e.debug,r=e.stores,o=e.key,n=e.cookie,a=e.localStorage,i=b({debug:t}),s=!0,c=!1,u=void 0;try{for(var d,f=r[Symbol.iterator]();!(s=(d=f.next()).done);s=!0){var l=d.value,g=S[l],m=g({key:o,cookie:n,localStorage:a});if(m)return i('get.browser: hit {store: "'+l+'", key: "'+o+'"}'),m;i('get.browser: miss {store: "'+l+'", key: "'+o+'"}')}}catch(e){c=!0,u=e}finally{try{!s&&f.return&&f.return()}finally{if(c)throw u}}return""}({debug:t,stores:g,key:l,cookie:i,localStorage:s});if(v)return u('get: found browser id {id: "'+v+'"}'),v}var y=f({prefix:c});return m&&(u('get: persisting new id {id: "'+y+'"}'),h({debug:t,key:l,id:y,cookie:e.cookie,localStorage:e.localStorage})),y};function d(e){return void 0===e?n():"string"==typeof e||"number"==typeof e?h({id:e}):"object"===(void 0===e?"undefined":v(e))?void 0!==e.id?h(e):u(e):u()}d.get=u,d.set=h;var f=d,l=Object.freeze({default:f}),g=l&&f||l,m={name:function(e,t){return"function"==typeof t["getters.name"]?t["getters.name"](e,t):e.event||e.name||e.Event},context:function(e){return e.context||e.ctx},timestamp:function(e,t){if("function"==typeof t["getters.timestamp"])return t["getters.timestamp"](e,t);var r=e.timestamp||e.ts;try{return new Date(r).toISOString()}catch(e){if(r)return r}return(new Date).toISOString()},messageId:function(e,t){return"function"==typeof t["getters.messageId"]?t["getters.messageId"](e,t):e.messageId||e.originalMessageId||g()},namespaceId:function(e,t){return"function"==typeof t["getters.namespaceId"]?t["getters.namespaceId"](e,t):e.namespaceId||e.nsc_id||e.namespace},properties:function(e){return e.properties||e.props||e.traits}},y={short:function(e){var t={};return e.name&&(t.name=e.name),e.timestamp&&(t.ts=e.timestamp),e.messageId&&(t.msg_id=e.messageId),e.namespaceId&&(t.nsc_id=e.namespaceId),e.properties&&(t.props=e.properties),e.context&&(t.ctx=e.context),t}};function I(e,t){return(0,y[t.format])(e,t)}I.load=function(e,t){return t?y[e]?r.error("format.load","format type already exists"):void(y[e]=t):r.error("format.load","missing formatter function")};var w=I;function x(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=m.namespaceId(e,t),o=m.messageId(e,t),n=m.timestamp(e,t),a=m.name(e,t),i=m.properties(e,t),s=m.context(e,t),c={};return a&&(c.name=a),i&&(c.properties=i),s&&(c.context=s),n&&(c.timestamp=n),r&&(c.namespaceId=r),o&&(c.messageId=o),t.format?w(c,t):c}return x.format=w,x.validate=e,x.loadFormat=w.load.bind(w),x.withOptions=function(){var r=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return function(e,t){return x(e,Object.assign({},t,r))}},x}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.AnalyticsEvent=t()}(this,function(){"use strict";var r=function(e){var i=e.debug;return function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];if(i){var o,n=t[0],a=t.slice(1);(o=console).log.apply(o,["analyticsEvent."+n].concat(function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}(a)))}}};for(var e=function(e,t){r("validate")},p="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},s=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],o=!0,n=!1,a=void 0;try{for(var i,s=e[Symbol.iterator]();!(o=(i=s.next()).done)&&(r.push(i.value),!t||r.length!==t);o=!0);}catch(e){n=!0,a=e}finally{try{!o&&s.return&&s.return()}finally{if(n)throw a}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},I=function(e){var i=e.debug;return function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];if(i){var o,n=t[0],a=t.slice(1);(o=console).log.apply(o,["analyticsId."+n].concat(function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}(a)))}}},o=[],t=0;t<=15;t++)o.push(t.toString(16));var n=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},y={segment:{stores:["cookie","localStorage"],key:"ajs_user_id",generateId:function(e){var t=e.prefix;return[void 0===t?"ajs":t,n()].join("-")},mutate:!0,persist:!0}};var a={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 r=0;r<e.length;r++){var o=e[r].split("="),n=s(o,2),a=n[0],i=n[1];t[a]=decodeURIComponent(i)}return t}(e.cookie)[t]},set:function(){var e,t,r,o,n,a,i,s,c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},u=c.key,d=c.id,f=c.mutate,m=c.domain,l=c.cookie,g=!1;try{l=document.cookie,g=!0}catch(e){l=""}return g&&(t=(e={name:u,value:d,path:"/",domain:m}).name,r=e.value,o=e.expires,n=e.domain,a=e.path,i=e.secure,s=(s=void 0)!==r&&"object"===(void 0===r?"undefined":p(r))?JSON.stringify(r):encodeURIComponent(r),document.cookie=t+"="+s+(o?"; expires="+new Date(o).toUTCString():"")+"; path="+(a||"/")+(n?"; domain="+n:"")+(i?"; secure":"")),f||(l=""+l),[l,u+"="+encodeURIComponent(d)].filter(Boolean).join("; ")}};var i={get:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.key,r=e.localStorage,o=void 0===r?{}:r;return o.getItem?o.getItem(t):o[t]},set:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.key,r=e.id,o=e.localStorage,n=void 0===o?{}:o,a=e.mutate?n:Object.assign({},n);return a.setItem?a.setItem(t,r):a[t]=r,a}},c={get:{cookie:a.get,localStorage:i.get},set:{cookie:a.set,localStorage:i.set}},b=c.set,h=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.id,r=e.debug,o=e.preset,n=void 0===o?"segment":o,a=e.cookie,i=e.localStorage,s=e.domain,c=e.prefix,u=I({debug:r});y[n]||(n="segment");var d=y[n],f=d.generateId,m=d.key,l=d.stores,g=d.mutate;u(t?'set: using {id: "'+t+'"}':'set: created new id {id: "'+(t=f({prefix:c}))+'"}');var p=void 0;if(!i)try{i=window.localStorage}catch(e){}try{(p=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.debug,r=e.key,o=e.id,n=e.stores,a=e.mutate,i=e.cookie,s=e.localStorage,c=e.domain,u={},d=I({debug:t}),f=!0,m=!1,l=void 0;try{for(var g,p=n[Symbol.iterator]();!(f=(g=p.next()).done);f=!0){var v=g.value;try{var y=b[v],h=y({key:r,id:o,mutate:a,cookie:i,localStorage:s,domain:c});h?(d("set."+v+': success {id: "'+o+'"}'),u[v]=h):d("set."+v+': fail {id: "'+o+'"}')}catch(e){d("set."+v+': fail {id: "'+o+'"}'),console.error(e)}}}catch(e){m=!0,l=e}finally{try{!f&&p.return&&p.return()}finally{if(m)throw l}}return u}({debug:r,key:m,id:t,stores:l,mutate:g,cookie:a,localStorage:i,domain:s})).status="success"}catch(e){u("set: error",e),p={status:"error",error:e}}return p};var k=c.get,u=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.debug,r=e.preset,o=void 0===r?"segment":r,n=e.env,a=void 0===n?"":n,i=e.cookie,s=e.localStorage,c=e.prefix,u=I({debug:t});y[o]||(o="segment");var d=y[o],f=d.generateId,m=d.key,l=d.stores,g=d.persist;if(function(){return"browser"===(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).env||"undefined"!=typeof window}({env:a})){if(!s)try{s=window.localStorage}catch(e){}if(!i)try{i=document.cookie}catch(e){}var p=function(e){var t=e.debug,r=e.stores,o=e.key,n=e.cookie,a=e.localStorage,i=I({debug:t}),s=!0,c=!1,u=void 0;try{for(var d,f=r[Symbol.iterator]();!(s=(d=f.next()).done);s=!0){var m=d.value,l=k[m],g=l({key:o,cookie:n,localStorage:a});if(g)return i('get.browser: hit {store: "'+m+'", key: "'+o+'"}'),g;i('get.browser: miss {store: "'+m+'", key: "'+o+'"}')}}catch(e){c=!0,u=e}finally{try{!s&&f.return&&f.return()}finally{if(c)throw u}}return""}({debug:t,stores:l,key:m,cookie:i,localStorage:s});if(p)return u('get: found browser id {id: "'+p+'"}'),p}var v=f({prefix:c});return g&&(u('get: persisting new id {id: "'+v+'"}'),h({debug:t,key:m,id:v,cookie:e.cookie,localStorage:e.localStorage})),v};function d(e){return void 0===e?n():"string"==typeof e||"number"==typeof e?h({id:e}):"object"===(void 0===e?"undefined":p(e))?void 0!==e.id?h(e):u(e):u()}d.get=u,d.set=h;var f=d,m=Object.freeze({default:f}),l=m&&f||m,g={name:function(e,t){return"function"==typeof t["getters.name"]?t["getters.name"](e,t):e.event||e.name||e.Event},context:function(e){return e.context||e.ctx},timestamp:function(e,t){if("function"==typeof t["getters.timestamp"])return t["getters.timestamp"](e,t);var r=e.timestamp||e.ts;try{return new Date(r).toISOString()}catch(e){if(r)return r}return(new Date).toISOString()},messageId:function(e,t){return"function"==typeof t["getters.messageId"]?t["getters.messageId"](e,t):e.messageId||e.originalMessageId||l()},namespaceId:function(e,t){return"function"==typeof t["getters.namespaceId"]?t["getters.namespaceId"](e,t):e.namespaceId||e.nsc_id||e.namespace},properties:function(e){return e.properties||e.props||e.traits}},v={short:function(e){var t={};return e.name&&(t.name=e.name),e.timestamp&&(t.ts=e.timestamp),e.messageId&&(t.msg_id=e.messageId),e.namespaceId&&(t.nsc_id=e.namespaceId),e.properties&&(t.props=e.properties),e.context&&(t.ctx=e.context),t},segment:function(e){var t={};return e.name&&(t.event=e.name),e.timestamp&&(t.timestamp=e.timestamp),e.messageId&&(t.messageId=e.messageId),e.properties&&(t.properties=e.properties),e.context&&(t.context=e.context),e.userId&&(t.userId=e.userId),e.anonymousId&&(t.anonymousId=e.anonymousId),t}};function S(e,t){return(0,v[t.format])(e,t)}S.load=function(e,t){return t?v[e]?r.error("format.load","format type already exists"):void(v[e]=t):r.error("format.load","missing formatter function")};var x=S;function w(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=g.namespaceId(e,t),o=g.messageId(e,t),n=g.timestamp(e,t),a=g.name(e,t),i=g.properties(e,t),s=g.context(e,t),c={};return a&&(c.name=a),i&&(c.properties=i),s&&(c.context=s),n&&(c.timestamp=n),r&&(c.namespaceId=r),o&&(c.messageId=o),t.format?x(c,t):c}return w.format=x,w.validate=e,w.loadFormat=x.load.bind(x),w.withOptions=function(){var r=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return function(e,t){return w(e,Object.assign({},t,r))}},w}); |
@@ -102,2 +102,36 @@ import analyticsId from 'analytics-id'; | ||
var segment = function formatSegment(event) { | ||
var newEvent = {}; | ||
if (event.name) { | ||
newEvent.event = event.name; | ||
} | ||
if (event.timestamp) { | ||
newEvent.timestamp = event.timestamp; | ||
} | ||
if (event.messageId) { | ||
newEvent.messageId = event.messageId; | ||
} | ||
if (event.properties) { | ||
newEvent.properties = event.properties; | ||
} | ||
if (event.context) { | ||
newEvent.context = event.context; | ||
} | ||
if (event.userId) { | ||
newEvent.userId = event.userId; | ||
} | ||
if (event.anonymousId) { | ||
newEvent.anonymousId = event.anonymousId; | ||
} | ||
return newEvent; | ||
}; | ||
var short_1 = function formatShort(event) { | ||
@@ -134,3 +168,4 @@ var newEvent = {}; | ||
var formatByType = { | ||
short: short_1 | ||
short: short_1, | ||
segment: segment | ||
}; | ||
@@ -137,0 +172,0 @@ |
@@ -106,2 +106,36 @@ 'use strict'; | ||
var segment = function formatSegment(event) { | ||
var newEvent = {}; | ||
if (event.name) { | ||
newEvent.event = event.name; | ||
} | ||
if (event.timestamp) { | ||
newEvent.timestamp = event.timestamp; | ||
} | ||
if (event.messageId) { | ||
newEvent.messageId = event.messageId; | ||
} | ||
if (event.properties) { | ||
newEvent.properties = event.properties; | ||
} | ||
if (event.context) { | ||
newEvent.context = event.context; | ||
} | ||
if (event.userId) { | ||
newEvent.userId = event.userId; | ||
} | ||
if (event.anonymousId) { | ||
newEvent.anonymousId = event.anonymousId; | ||
} | ||
return newEvent; | ||
}; | ||
var short_1 = function formatShort(event) { | ||
@@ -138,3 +172,4 @@ var newEvent = {}; | ||
var formatByType = { | ||
short: short_1 | ||
short: short_1, | ||
segment: segment | ||
}; | ||
@@ -141,0 +176,0 @@ |
{ | ||
"name": "analytics-event", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Utility for working with analytics events server-side and in the browser.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
64914
1035