analytics-client
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -7,2 +7,6 @@ # Change Log | ||
## 0.1.1 - 2019-10-18 | ||
* Fix device ID cookie path [Roman Mazur] | ||
## 0.1.0 - 2019-10-14 | ||
@@ -9,0 +13,0 @@ |
@@ -1,1 +0,1 @@ | ||
var analyticsClient=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1);t.AnalyticsUrlParams=r.AnalyticsUrlParams},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),o="__analytics_dids",i=/\s*,\s*/,c=function(){function e(e){this.mixpanel=e,this.cookiesSupported=r.hasCookieSupport(),this.deviceIds=new Set;var t=this.cookiesSupported?r.getCookie(o):null;this.setDeviceIds(t,null)}return e.prototype.setDeviceIds=function(e,t){var n=e?e.split(i):[];return t&&n.push(t),this.deviceIds=new Set(n.concat(Array.from(this.deviceIds))),this.cookiesSupported&&r.setCookie(o,Array.from(this.deviceIds).join(",")),n.length>0?n[0]:null},e.prototype.clearCookies=function(){this.cookiesSupported&&r.setCookie(o,"")},e.prototype.consumeUrlParameters=function(e){var t=new URLSearchParams(e),n=t.get("d_id");if(n){var r=null!=this.mixpanel?this.mixpanel.get_distinct_id():null,o=this.setDeviceIds(n,r);return null!=this.mixpanel&&o&&this.mixpanel.register({distinct_id:o,$device_id:o}),t.delete("d_id"),t.toString()}return null},e.prototype.allDeviceIds=function(){var e=this.mixpanel?this.mixpanel.get_distinct_id():null;if(null==e)return Array.from(this.deviceIds);var t=new Set(this.deviceIds);return t.add(e),Array.from(t)},e.prototype.getDeviceIdsQueryString=function(){var e=this.allDeviceIds();return 0===e.length?"":"d_id="+encodeURIComponent(e.join(","))},e}();t.AnalyticsUrlParams=c},function(e,t,n){"use strict";function r(e,t,n,r,o,i){if("undefined"!=typeof window)return arguments.length>1?document.cookie="".concat(e,"=").concat(encodeURIComponent(t)).concat(n?"; expires=".concat(new Date(+new Date+1e3*n).toUTCString()):"").concat(r?"; path=".concat(r):"").concat(o?"; domain=".concat(o):"").concat(i?"; secure":""):decodeURIComponent(("; ".concat(document.cookie).split("; ".concat(e,"="))[1]||"").split(";")[0])}function o(){try{r("___c","1");var e=-1!==document.cookie.indexOf("___c");return r("___c","",-1),e}catch(e){return!1}}n.r(t),n.d(t,"hasCookieSupport",(function(){return o})),n.d(t,"setCookie",(function(){return c})),n.d(t,"getCookie",(function(){return i})),n.d(t,"removeCookie",(function(){return u}));var i=r,c=r;function u(e){return r(e,"",-1)}}]); | ||
var analyticsClient=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1);t.AnalyticsUrlParams=r.AnalyticsUrlParams},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),o="__analytics_dids",i=/\s*,\s*/,c=function(){function e(e){this.mixpanel=e,this.cookiesSupported=r.hasCookieSupport(),this.deviceIds=new Set;var t=this.cookiesSupported?r.getCookie(o):null;this.setDeviceIds(t,null)}return e.prototype.setDeviceIds=function(e,t){var n=e?e.split(i):[];return t&&n.push(t),this.deviceIds=new Set(n.concat(Array.from(this.deviceIds))),this.cookiesSupported&&r.setCookie(o,Array.from(this.deviceIds).join(","),2592e7,"/"),n.length>0?n[0]:null},e.prototype.clearCookies=function(){this.cookiesSupported&&r.removeCookie(o)},e.prototype.consumeUrlParameters=function(e){var t=new URLSearchParams(e),n=t.get("d_id");if(n){var r=null!=this.mixpanel?this.mixpanel.get_distinct_id():null,o=this.setDeviceIds(n,r);return null!=this.mixpanel&&o&&this.mixpanel.register({distinct_id:o,$device_id:o}),t.delete("d_id"),t.toString()}return null},e.prototype.allDeviceIds=function(){var e=this.mixpanel?this.mixpanel.get_distinct_id():null;if(null==e)return Array.from(this.deviceIds);var t=new Set(this.deviceIds);return t.add(e),Array.from(t)},e.prototype.getDeviceIdsQueryString=function(){var e=this.allDeviceIds();return 0===e.length?"":"d_id="+encodeURIComponent(e.join(","))},e}();t.AnalyticsUrlParams=c},function(e,t,n){"use strict";function r(e,t,n,r,o,i){if("undefined"!=typeof window)return arguments.length>1?document.cookie="".concat(e,"=").concat(encodeURIComponent(t)).concat(n?"; expires=".concat(new Date(+new Date+1e3*n).toUTCString()):"").concat(r?"; path=".concat(r):"").concat(o?"; domain=".concat(o):"").concat(i?"; secure":""):decodeURIComponent(("; ".concat(document.cookie).split("; ".concat(e,"="))[1]||"").split(";")[0])}function o(){try{r("___c","1");var e=-1!==document.cookie.indexOf("___c");return r("___c","",-1),e}catch(e){return!1}}n.r(t),n.d(t,"hasCookieSupport",(function(){return o})),n.d(t,"setCookie",(function(){return c})),n.d(t,"getCookie",(function(){return i})),n.d(t,"removeCookie",(function(){return u}));var i=r,c=r;function u(e){return r(e,"",-1)}}]); |
@@ -6,2 +6,3 @@ "use strict"; | ||
var COOKIES_DEVICE_IDS = '__analytics_dids'; | ||
var COOKIES_TTL_MS = 300 * 24 * 60 * 60 * 1000; | ||
var deviceIdSeparator = /\s*,\s*/; | ||
@@ -25,3 +26,3 @@ var AnalyticsUrlParams = (function () { | ||
if (this.cookiesSupported) { | ||
cookie_utils_1.setCookie(COOKIES_DEVICE_IDS, Array.from(this.deviceIds).join(',')); | ||
cookie_utils_1.setCookie(COOKIES_DEVICE_IDS, Array.from(this.deviceIds).join(','), COOKIES_TTL_MS, '/'); | ||
} | ||
@@ -32,3 +33,3 @@ return list.length > 0 ? list[0] : null; | ||
if (this.cookiesSupported) { | ||
cookie_utils_1.setCookie(COOKIES_DEVICE_IDS, ''); | ||
cookie_utils_1.removeCookie(COOKIES_DEVICE_IDS); | ||
} | ||
@@ -35,0 +36,0 @@ }; |
{ | ||
"name": "analytics-client", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Convenient builders to compose analytics tools", | ||
@@ -5,0 +5,0 @@ "repository": { |
import { | ||
getCookie, | ||
hasCookieSupport, | ||
removeCookie, | ||
setCookie, | ||
@@ -10,2 +11,3 @@ } from '@analytics/cookie-utils'; | ||
const COOKIES_DEVICE_IDS = '__analytics_dids'; | ||
const COOKIES_TTL_MS = 300 * 24 * 60 * 60 * 1000; // 300 days. | ||
@@ -39,3 +41,8 @@ const deviceIdSeparator = /\s*,\s*/; | ||
if (this.cookiesSupported) { | ||
setCookie(COOKIES_DEVICE_IDS, Array.from(this.deviceIds).join(',')); | ||
setCookie( | ||
COOKIES_DEVICE_IDS, | ||
Array.from(this.deviceIds).join(','), | ||
COOKIES_TTL_MS, | ||
'/', | ||
); | ||
} | ||
@@ -47,3 +54,3 @@ return list.length > 0 ? list[0] : null; | ||
if (this.cookiesSupported) { | ||
setCookie(COOKIES_DEVICE_IDS, ''); | ||
removeCookie(COOKIES_DEVICE_IDS); | ||
} | ||
@@ -50,0 +57,0 @@ } |
declare module '@analytics/cookie-utils' { | ||
export function hasCookieSupport(): boolean; | ||
export function setCookie(name: string, value: string): void; | ||
export function setCookie( | ||
name: string, | ||
value: string, | ||
ttlMs: number, | ||
path: string, | ||
): void; | ||
export function getCookie(name: string): string; | ||
export function removeCookie(name: string): void; | ||
} |
23268
515