From 840eedd4a22f0c53f5bd65522b02dcca438f1cae Mon Sep 17 00:00:00 2001 From: dnson Date: Tue, 28 Jun 2022 08:02:05 +0700 Subject: [PATCH] release 3.1.1 (#233) --- CHANGELOG.md | 4 ++-- dist/td.js | 12 ++++++------ dist/td.min.js | 6 +++--- lib/config.js | 2 +- package.json | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31737488..f895206d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog -## 3.1.0 (2022-05-31) -* Using new JavaScript endpoint +## 3.1.1 (2022-06-28) +* Opt-in for new JavaScript endpoint ## 3.0.0 (2021-05-26) * Using the Fetch API as a replacement for the JSONP diff --git a/dist/td.js b/dist/td.js index 9f7047dd..54769e13 100644 --- a/dist/td.js +++ b/dist/td.js @@ -93,7 +93,7 @@ /*! no static exports found */ /***/ (function(module, exports) { -eval("module.exports = {\n GLOBAL: 'Treasure',\n VERSION: '3.1.0',\n HOST: 'in.treasuredata.com',\n DATABASE: '',\n PATHNAME: '/'\n};\n\n//# sourceURL=webpack:///./lib/config.js?"); +eval("module.exports = {\n GLOBAL: 'Treasure',\n VERSION: '3.1.1',\n HOST: 'in.treasuredata.com',\n DATABASE: '',\n PATHNAME: '/js/v3/event/'\n};\n\n//# sourceURL=webpack:///./lib/config.js?"); /***/ }), @@ -104,7 +104,7 @@ eval("module.exports = {\n GLOBAL: 'Treasure',\n VERSION: '3.1.0',\n HOST: 'i /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -eval("/*\n * Treasure Configurator\n */\n// Modules\nvar _ = __webpack_require__(/*! ./utils/lodash */ \"./lib/utils/lodash.js\");\n\nvar invariant = __webpack_require__(/*! ./utils/misc */ \"./lib/utils/misc.js\").invariant;\n\nvar config = __webpack_require__(/*! ./config */ \"./lib/config.js\");\n\nvar cookie = __webpack_require__(/*! ./vendor/js-cookies */ \"./lib/vendor/js-cookies.js\"); // Helpers\n\n\nfunction validateOptions(options) {\n // options must be an object\n invariant(_.isObject(options), 'Check out our JavaScript SDK Usage Guide: ' + 'https://github.com/treasure-data/td-js-sdk#api');\n invariant(_.isString(options.writeKey), 'Must provide a writeKey');\n invariant(_.isString(options.database), 'Must provide a database');\n invariant(/^[a-z0-9_]{3,255}$/.test(options.database), 'Database must be between 3 and 255 characters and must ' + 'consist only of lower case letters, numbers, and _');\n}\n\nvar defaultSSCCookieDomain = function defaultSSCCookieDomain() {\n var domainChunks = document.location.hostname.split('.');\n\n for (var i = domainChunks.length - 2; i >= 1; i--) {\n var domain = domainChunks.slice(i).join('.');\n var name = '_td_domain_' + domain; // append domain name to avoid race condition\n\n cookie.setItem(name, domain, 3600, '/', domain);\n\n if (cookie.getItem(name) === domain) {\n return domain;\n }\n }\n\n return document.location.hostname;\n}; // Default config for library values\n\n\nexports.DEFAULT_CONFIG = {\n database: config.DATABASE,\n development: false,\n globalIdCookie: '_td_global',\n host: config.HOST,\n logging: true,\n pathname: config.PATHNAME,\n requestType: 'fetch',\n jsonpTimeout: 10000,\n startInSignedMode: false,\n useServerSideCookie: false,\n sscDomain: defaultSSCCookieDomain,\n sscServer: function sscServer(cookieDomain) {\n return ['ssc', cookieDomain].join('.');\n },\n storeConsentByLocalStorage: false\n};\n/*\n * Initial configurator\n * Checks validity\n * Creates and sets up client object\n *\n * Modify DEFAULT_CONFIG to change any defaults\n * Protocol defaults to auto-detection but can be set manually\n * host defaults to in.treasuredata.com\n * pathname defaults to /js/v3/event/\n * requestType is always fetch\n *\n * */\n\nexports.configure = function configure(options) {\n this.client = _.assign({\n globals: {}\n }, exports.DEFAULT_CONFIG, options, {\n requestType: 'fetch'\n });\n validateOptions(this.client);\n\n if (!this.client.endpoint) {\n this.client.endpoint = 'https://' + this.client.host + this.client.pathname;\n }\n\n return this;\n};\n/**\n * Useful when you want to set multiple values.\n * Table value setter\n * When you set mutliple attributes, the object is iterated and values are set on the table\n * Attributes are not recursively set on the table\n *\n * @param {string} table - table name\n * @param {object} properties - Object with keys and values that you wish applies on the table each time a record is sent\n *\n * @example\n * var td = new Treasure({...})\n * td.set('table', {foo: 'foo', bar: 'bar'});\n * td.addRecord('table', {baz: 'baz'});\n * // Sends:\n * // {\n * // \"foo\": \"foo\",\n * // \"bar\": \"bar\",\n * // \"baz\": \"baz\"\n * // }\n */\n\n\nexports.set = function set(table, property, value) {\n if (_.isObject(table)) {\n property = table;\n table = '$global';\n }\n\n this.client.globals[table] = this.client.globals[table] || {};\n\n if (_.isObject(property)) {\n _.assign(this.client.globals[table], property);\n } else {\n this.client.globals[table][property] = value;\n }\n\n return this;\n};\n/**\n * Takes a table name and returns an object with its default values.\n * If the table does not exist, its object gets created\n *\n * NOTE: This is only available once the library has loaded. Wrap any getter with a Treasure#ready callback to ensure the library is loaded.\n *\n * @param {string} table - table name\n * @param {string} [key] - Optional key to get from the table\n *\n * @example Getting all rows in a table\n * var td = new Treasure({..});\n * td.set('table', 'foo', 'bar');\n * td.get('table');\n * // {foo: 'bar'}\n *\n * @example Getting a single attribute\n * var td = new Treasure({..});\n * td.get('table', 'foo')\n * // > 'bar'\n */\n\n\nexports.get = function get(table, key) {\n // If no table, show $global\n table = table || '$global';\n this.client.globals[table] = this.client.globals[table] || {};\n return key ? this.client.globals[table][key] : this.client.globals[table];\n};\n\nexports.isGlobalIdEnabled = function () {\n return this.get(null, 'td_global_id') === 'td_global_id';\n};\n\n//# sourceURL=webpack:///./lib/configurator.js?"); +eval("/*\n * Treasure Configurator\n */\n// Modules\nvar _ = __webpack_require__(/*! ./utils/lodash */ \"./lib/utils/lodash.js\");\n\nvar invariant = __webpack_require__(/*! ./utils/misc */ \"./lib/utils/misc.js\").invariant;\n\nvar config = __webpack_require__(/*! ./config */ \"./lib/config.js\");\n\nvar cookie = __webpack_require__(/*! ./vendor/js-cookies */ \"./lib/vendor/js-cookies.js\"); // Helpers\n\n\nfunction validateOptions(options) {\n // options must be an object\n invariant(_.isObject(options), 'Check out our JavaScript SDK Usage Guide: ' + 'https://github.com/treasure-data/td-js-sdk#api');\n invariant(_.isString(options.writeKey), 'Must provide a writeKey');\n invariant(_.isString(options.database), 'Must provide a database');\n invariant(/^[a-z0-9_]{3,255}$/.test(options.database), 'Database must be between 3 and 255 characters and must ' + 'consist only of lower case letters, numbers, and _');\n}\n\nvar defaultSSCCookieDomain = function defaultSSCCookieDomain() {\n var domainChunks = document.location.hostname.split('.');\n\n for (var i = domainChunks.length - 2; i >= 1; i--) {\n var domain = domainChunks.slice(i).join('.');\n var name = '_td_domain_' + domain; // append domain name to avoid race condition\n\n cookie.setItem(name, domain, 3600, '/', domain);\n\n if (cookie.getItem(name) === domain) {\n return domain;\n }\n }\n\n return document.location.hostname;\n}; // Default config for library values\n\n\nexports.DEFAULT_CONFIG = {\n database: config.DATABASE,\n development: false,\n useNewJavaScriptEndpoint: false,\n globalIdCookie: '_td_global',\n host: config.HOST,\n logging: true,\n pathname: config.PATHNAME,\n requestType: 'fetch',\n jsonpTimeout: 10000,\n startInSignedMode: false,\n useServerSideCookie: false,\n sscDomain: defaultSSCCookieDomain,\n sscServer: function sscServer(cookieDomain) {\n return ['ssc', cookieDomain].join('.');\n },\n storeConsentByLocalStorage: false\n};\n/*\n * Initial configurator\n * Checks validity\n * Creates and sets up client object\n *\n * Modify DEFAULT_CONFIG to change any defaults\n * Protocol defaults to auto-detection but can be set manually\n * host defaults to in.treasuredata.com\n * pathname defaults to /js/v3/event/\n * requestType is always fetch\n *\n * */\n\nexports.configure = function configure(options) {\n this.client = _.assign({\n globals: {}\n }, exports.DEFAULT_CONFIG, options, {\n requestType: 'fetch'\n });\n validateOptions(this.client);\n\n if (this.client.useNewJavaScriptEndpoint) {\n this.client.pathname = '/';\n }\n\n if (!this.client.endpoint) {\n this.client.endpoint = 'https://' + this.client.host + this.client.pathname;\n }\n\n return this;\n};\n/**\n * Useful when you want to set multiple values.\n * Table value setter\n * When you set mutliple attributes, the object is iterated and values are set on the table\n * Attributes are not recursively set on the table\n *\n * @param {string} table - table name\n * @param {object} properties - Object with keys and values that you wish applies on the table each time a record is sent\n *\n * @example\n * var td = new Treasure({...})\n * td.set('table', {foo: 'foo', bar: 'bar'});\n * td.addRecord('table', {baz: 'baz'});\n * // Sends:\n * // {\n * // \"foo\": \"foo\",\n * // \"bar\": \"bar\",\n * // \"baz\": \"baz\"\n * // }\n */\n\n\nexports.set = function set(table, property, value) {\n if (_.isObject(table)) {\n property = table;\n table = '$global';\n }\n\n this.client.globals[table] = this.client.globals[table] || {};\n\n if (_.isObject(property)) {\n _.assign(this.client.globals[table], property);\n } else {\n this.client.globals[table][property] = value;\n }\n\n return this;\n};\n/**\n * Takes a table name and returns an object with its default values.\n * If the table does not exist, its object gets created\n *\n * NOTE: This is only available once the library has loaded. Wrap any getter with a Treasure#ready callback to ensure the library is loaded.\n *\n * @param {string} table - table name\n * @param {string} [key] - Optional key to get from the table\n *\n * @example Getting all rows in a table\n * var td = new Treasure({..});\n * td.set('table', 'foo', 'bar');\n * td.get('table');\n * // {foo: 'bar'}\n *\n * @example Getting a single attribute\n * var td = new Treasure({..});\n * td.get('table', 'foo')\n * // > 'bar'\n */\n\n\nexports.get = function get(table, key) {\n // If no table, show $global\n table = table || '$global';\n this.client.globals[table] = this.client.globals[table] || {};\n return key ? this.client.globals[table][key] : this.client.globals[table];\n};\n\nexports.isGlobalIdEnabled = function () {\n return this.get(null, 'td_global_id') === 'td_global_id';\n};\n\n//# sourceURL=webpack:///./lib/configurator.js?"); /***/ }), @@ -159,7 +159,7 @@ eval("var _slicedToArray = __webpack_require__(/*! @babel/runtime/helpers/sliced /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -eval("/**\n * Treasure Global ID\n */\n// Modules\nvar noop = __webpack_require__(/*! ../utils/lodash */ \"./lib/utils/lodash.js\").noop;\n\nvar misc = __webpack_require__(/*! ../utils/misc */ \"./lib/utils/misc.js\");\n\nvar cookie = __webpack_require__(/*! ../vendor/js-cookies */ \"./lib/vendor/js-cookies.js\");\n\nvar api = __webpack_require__(/*! ../utils/xhr */ \"./lib/utils/xhr.js\");\n\nfunction cacheSuccess(result, cookieName, cookieOptions) {\n cookieOptions = cookieOptions || {};\n\n if (!result['global_id']) {\n return null;\n }\n\n var path = cookieOptions.path;\n var domain = cookieOptions.domain;\n var secure = cookieOptions.secure;\n var maxAge = cookieOptions.maxAge || 6000;\n var sameSite = cookieOptions.sameSite;\n cookie.setItem(cookieName, result['global_id'], maxAge, path, domain, secure, sameSite);\n return result['global_id'];\n}\n\nfunction configure() {\n return this;\n}\n/**\n * @param {function} [success] - Callback for when sending the event is successful\n * @param {function} [error] - Callback for when sending the event is unsuccessful\n * @param {boolean} [forceFetch] - Forces a refetch of global id and ignores cached version (default false)\n * @param {object} [options] - Cookie options Note: If you set the sameSite value to None, the Secure property of the cookie will be set to true (it overwrites the secure option). More details on SameSite cookies.\n * @property {string} [options.path] - '/',\n * @property {string} [options.domain] - 'mycompany.com',\n * @property {boolean} [options.secure] - true|false,\n * @property {number|string|date} [options.maxAge] - Number | String | Date,\n * @property {string} [options.sameSite] - 'None | Lax | Strict'\n *\n * @example Cookie options: Note - If you set the sameSite value to None, the Secure property of the cookie will be set to true (it overwrites the secure option). More details on SameSite cookies.\n * {\n * path: '/',\n * domain: 'abc.com',\n * secure: true|false,\n * maxAge: Number | String | Date,\n * sameSite: 'None | Lax | Strict'\n * }\n *\n * @example\n * var td = new Treasure({...})\n *\n * var successCallback = function (globalId) {\n * // celebrate();\n * };\n *\n * var errorCallback = function (error) {\n * // cry();\n * }\n *\n * td.fetchGlobalID(successCallback, errorCallback)\n *\n * // with cookie options\n * td.fetchGlobalID(successCallback, errorCallback, true, {\n * path: '/',\n * secure: true,\n * maxAge: 5 * 60 // 5 minutes,\n * sameSite: 'None'\n * })\n */\n\n\nfunction fetchGlobalID(success, error, forceFetch, options) {\n options = options || {};\n success = success || noop;\n error = error || noop;\n\n if (!this.inSignedMode()) {\n return error('not in signed in mode');\n }\n\n var cookieName = this.client.globalIdCookie;\n var cachedGlobalId = cookie.getItem(cookieName);\n\n if (cachedGlobalId && !forceFetch) {\n return setTimeout(function () {\n success(cachedGlobalId);\n }, 0);\n }\n\n if (!options.sameSite) {\n options.sameSite = 'None';\n }\n\n var url = 'https://' + this.client.host;\n api.get(url, {\n headers: {\n 'Authorization': 'TD1 ' + this.client.writeKey,\n 'User-Agent': navigator.userAgent,\n 'Content-Type': misc.globalIdContentTypeHeader,\n 'Accept': misc.globalIdAcceptHeader\n }\n }).then(function (res) {\n var cachedId = cacheSuccess(res, cookieName, options);\n success(cachedId);\n }).catch(function (err) {\n error(err);\n });\n}\n\nfunction removeCachedGlobalID() {\n cookie.removeItem(this.client.globalIdCookie);\n}\n\nmodule.exports = {\n cacheSuccess: cacheSuccess,\n configure: configure,\n fetchGlobalID: fetchGlobalID,\n removeCachedGlobalID: removeCachedGlobalID\n};\n\n//# sourceURL=webpack:///./lib/plugins/globalid.js?"); +eval("/**\n * Treasure Global ID\n */\n// Modules\nvar noop = __webpack_require__(/*! ../utils/lodash */ \"./lib/utils/lodash.js\").noop;\n\nvar misc = __webpack_require__(/*! ../utils/misc */ \"./lib/utils/misc.js\");\n\nvar cookie = __webpack_require__(/*! ../vendor/js-cookies */ \"./lib/vendor/js-cookies.js\");\n\nvar api = __webpack_require__(/*! ../utils/xhr */ \"./lib/utils/xhr.js\");\n\nfunction cacheSuccess(result, cookieName, cookieOptions) {\n cookieOptions = cookieOptions || {};\n\n if (!result['global_id']) {\n return null;\n }\n\n var path = cookieOptions.path;\n var domain = cookieOptions.domain;\n var secure = cookieOptions.secure;\n var maxAge = cookieOptions.maxAge || 6000;\n var sameSite = cookieOptions.sameSite;\n cookie.setItem(cookieName, result['global_id'], maxAge, path, domain, secure, sameSite);\n return result['global_id'];\n}\n\nfunction configure() {\n return this;\n}\n/**\n * @param {function} [success] - Callback for when sending the event is successful\n * @param {function} [error] - Callback for when sending the event is unsuccessful\n * @param {boolean} [forceFetch] - Forces a refetch of global id and ignores cached version (default false)\n * @param {object} [options] - Cookie options Note: If you set the sameSite value to None, the Secure property of the cookie will be set to true (it overwrites the secure option). More details on SameSite cookies.\n * @property {string} [options.path] - '/',\n * @property {string} [options.domain] - 'mycompany.com',\n * @property {boolean} [options.secure] - true|false,\n * @property {number|string|date} [options.maxAge] - Number | String | Date,\n * @property {string} [options.sameSite] - 'None | Lax | Strict'\n *\n * @example Cookie options: Note - If you set the sameSite value to None, the Secure property of the cookie will be set to true (it overwrites the secure option). More details on SameSite cookies.\n * {\n * path: '/',\n * domain: 'abc.com',\n * secure: true|false,\n * maxAge: Number | String | Date,\n * sameSite: 'None | Lax | Strict'\n * }\n *\n * @example\n * var td = new Treasure({...})\n *\n * var successCallback = function (globalId) {\n * // celebrate();\n * };\n *\n * var errorCallback = function (error) {\n * // cry();\n * }\n *\n * td.fetchGlobalID(successCallback, errorCallback)\n *\n * // with cookie options\n * td.fetchGlobalID(successCallback, errorCallback, true, {\n * path: '/',\n * secure: true,\n * maxAge: 5 * 60 // 5 minutes,\n * sameSite: 'None'\n * })\n */\n\n\nfunction fetchGlobalID(success, error, forceFetch, options) {\n options = options || {};\n success = success || noop;\n error = error || noop;\n\n if (!this.inSignedMode()) {\n return error('not in signed in mode');\n }\n\n if (!this.isGlobalIdEnabled()) {\n return error('global id is not enabled');\n }\n\n var cookieName = this.client.globalIdCookie;\n var cachedGlobalId = cookie.getItem(cookieName);\n\n if (cachedGlobalId && !forceFetch) {\n return setTimeout(function () {\n success(cachedGlobalId);\n }, 0);\n }\n\n if (!options.sameSite) {\n options.sameSite = 'None';\n }\n\n var url = 'https://' + this.client.host + '/js/v3/enable_global_id';\n var requestHeaders = {};\n var ignoreDefaultHeaders = false;\n\n if (this.client.useNewJavaScriptEndpoint) {\n url = 'https://' + this.client.host;\n requestHeaders['Authorization'] = 'TD1 ' + this.client.writeKey;\n requestHeaders['User-Agent'] = navigator.userAgent;\n requestHeaders['Content-Type'] = misc.globalIdAdlHeaders['Content-Type'];\n requestHeaders['Accept'] = misc.globalIdAdlHeaders['Accept'];\n ignoreDefaultHeaders = true;\n }\n\n api.get(url, {\n headers: requestHeaders,\n ignoreDefaultHeaders: ignoreDefaultHeaders\n }).then(function (res) {\n var cachedId = cacheSuccess(res, cookieName, options);\n success(cachedId);\n }).catch(function (err) {\n error(err);\n });\n}\n\nfunction removeCachedGlobalID() {\n cookie.removeItem(this.client.globalIdCookie);\n}\n\nmodule.exports = {\n cacheSuccess: cacheSuccess,\n configure: configure,\n fetchGlobalID: fetchGlobalID,\n removeCachedGlobalID: removeCachedGlobalID\n};\n\n//# sourceURL=webpack:///./lib/plugins/globalid.js?"); /***/ }), @@ -203,7 +203,7 @@ eval("/*!\n* ----------------------\n* Treasure Tracker\n* --------------------- /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -eval("/**\n * Treasure Record\n */\n// Modules\nvar misc = __webpack_require__(/*! ./utils/misc */ \"./lib/utils/misc.js\");\n\nvar _ = __webpack_require__(/*! ./utils/lodash */ \"./lib/utils/lodash.js\");\n\nvar global = __webpack_require__(/*! global */ \"./node_modules/global/window.js\");\n\nvar cookie = __webpack_require__(/*! ./vendor/js-cookies */ \"./lib/vendor/js-cookies.js\");\n\nvar setCookie = __webpack_require__(/*! ./utils/setCookie */ \"./lib/utils/setCookie.js\");\n\nvar api = __webpack_require__(/*! ./utils/xhr */ \"./lib/utils/xhr.js\");\n\nvar noop = _.noop;\nvar invariant = misc.invariant; // Helpers\n\n/*\n * Validate record\n */\n\nfunction validateRecord(table, record) {\n invariant(_.isString(table), 'Must provide a table');\n invariant(/^[a-z0-9_]{3,255}$/.test(table), 'Table must be between 3 and 255 characters and must ' + 'consist only of lower case letters, numbers, and _');\n invariant(_.isObject(record), 'Must provide a record');\n}\n\nvar BLOCKEVENTSCOOKIE = '__td_blockEvents';\nvar SIGNEDMODECOOKIE = '__td_signed';\nexports.BLOCKEVENTSCOOKIE = BLOCKEVENTSCOOKIE;\nexports.SIGNEDMODECOOKIE = SIGNEDMODECOOKIE;\n/**\n * @Treasure.blockEvents\n * Block all events from being sent to Treasure Data.\n *\n * @example\n * var td = new Treasure({...})\n * td.trackEvent('customevent')\n * td.blockEvents()\n * td.trackEvent('willnotbetracked')\n */\n\nexports.blockEvents = function blockEvents() {\n setCookie(this.client.storage, BLOCKEVENTSCOOKIE, 'true');\n};\n/**\n * @Treasure.unblockEvents\n * Unblock all events; events will be sent to Treasure Data.\n *\n * @example\n * var td = new Treasure({...})\n * td.blockEvents()\n * td.trackEvent('willnotbetracked')\n * td.unblockEvents()\n * td.trackEvent('willbetracked')\n */\n\n\nexports.unblockEvents = function unblockEvents() {\n setCookie(this.client.storage, BLOCKEVENTSCOOKIE, 'false');\n};\n/**\n * @Treasure.areEventsBlocked\n * Informational method, expressing whether events are blocked or not.\n *\n * @example\n * var td = new Treasure({...})\n * td.areEventsBlocked() // false, default\n * td.blockEvents()\n * td.areEventsBlocked() // true\n */\n\n\nexports.areEventsBlocked = function areEventsBlocked() {\n return cookie.getItem(BLOCKEVENTSCOOKIE) === 'true';\n};\n/**\n * @Treasure.setSignedMode\n * Sets the user to Signed Mode.\n * Permit sending of Personally Identifying Information over the wire: td_ip, td_client_id, and td_global_id\n *\n * @example\n * var td = new Treasure({...})\n * td.setSignedMode()\n * td.trackEvent('willbetracked') // will send td_ip and td_client_id; td_global_id will also be sent if set.\n */\n\n\nexports.setSignedMode = function setSignedMode() {\n if (this.client.storeConsentByLocalStorage) {\n if (!misc.isLocalStorageAccessible()) return this;\n global.localStorage.setItem(SIGNEDMODECOOKIE, 'true');\n } else {\n setCookie(this.client.storage, SIGNEDMODECOOKIE, 'true');\n }\n\n this.resetUUID(this.client.storage, this.client.track.uuid);\n return this;\n};\n/**\n * @Treasure.setAnonymousMode\n *\n * Sets the user to anonymous mode.\n * Prohibit sending of Personally Identifying Information over the wire: td_ip, td_client_id, and td_global_id\n *\n * @param {boolean} keepIdentifier - Keep the cookies. By default setAnonymousMode will remove all cookies that are set by Treasure Data JavaScript SDK, you can set keepIdentifier parameter to true to not remove the cookies.\n *\n * @example\n * var td = new Treasure({...})\n * td.setAnonymousMode()\n * td.trackEvent('willbetracked') // will NOT send td_ip and td_client_id; td_global_id will also NOT be sent if set.\n */\n\n\nexports.setAnonymousMode = function setAnonymousMode(keepIdentifier) {\n if (this.client.storeConsentByLocalStorage) {\n if (!misc.isLocalStorageAccessible()) return this;\n global.localStorage.setItem(SIGNEDMODECOOKIE, 'false');\n } else {\n setCookie(this.client.storage, SIGNEDMODECOOKIE, 'false');\n }\n\n if (!keepIdentifier) {\n // remove _td cookie\n setCookie(this.client.storage, this.client.storage.name); // remove global id cookie\n\n this.removeCachedGlobalID(); // remove server side cookie\n\n this.removeServerCookie();\n }\n\n return this;\n};\n/**\n * @Treasure.inSignedMode\n *\n * Tells whether or not the user is in Signed Mode.\n * Informational method, indicating whether trackEvents method will automatically collect td_ip, td_client_id, and td_global_id if set.\n *\n * @example\n * var td = new Treasure({...})\n * td.inSignedMode() // false, default\n * td.trackEvent('willbetracked') // will NOT send td_ip and td_client_id; td_global_id will also NOT be sent if set.\n * td.setSignedMode()\n * td.inSignedMode() // true\n * td.trackEvent('willbetracked') // will send td_ip and td_client_id; td_global_id will also be sent if set.\n */\n\n\nexports.inSignedMode = function inSignedMode() {\n if (this.client.storeConsentByLocalStorage) {\n if (!misc.isLocalStorageAccessible()) return false;\n return global.localStorage.getItem([SIGNEDMODECOOKIE]) !== 'false' && (global.localStorage.getItem([SIGNEDMODECOOKIE]) === 'true' || this.client.startInSignedMode);\n }\n\n return cookie.getItem(SIGNEDMODECOOKIE) !== 'false' && (cookie.getItem(SIGNEDMODECOOKIE) === 'true' || this.client.startInSignedMode);\n};\n/*\n * Send record\n */\n\n\nexports._sendRecord = function _sendRecord(request, success, error, blockedEvent) {\n success = success || noop;\n error = error || noop;\n\n if (blockedEvent) {\n return;\n }\n\n var params = ['modified=' + encodeURIComponent(new Date().getTime())];\n\n if (request.time) {\n params.push('time=' + encodeURIComponent(request.time));\n }\n\n var url = request.url + '?' + params.join('&');\n var isClickedLink = request.record.tag === 'a' && !!request.record.href;\n var authHeader = {\n 'Authorization': 'TD1 ' + request.apikey,\n 'User-Agent': navigator.userAgent\n };\n\n if (this.isGlobalIdEnabled()) {\n authHeader['Content-Type'] = misc.globalIdContentTypeHeader;\n authHeader['Accept'] = misc.globalIdAcceptHeader;\n }\n\n if (window.fetch && (this._windowBeingUnloaded || isClickedLink)) {\n api.postWithTimeout(url, {\n events: [request.record]\n }, this.client.jsonpTimeout, {\n method: 'POST',\n keepalive: true,\n credentials: 'include',\n headers: authHeader\n }).then(success).catch(error);\n } else {\n api.post(url, {\n events: [request.record]\n }, {\n headers: authHeader\n }).then(success).catch(error);\n }\n}; // Methods\n\n/*\n * Treasure#applyProperties\n *\n * Applies properties on a payload object\n *\n * Starts with an empty object and applies properties in the following order:\n * $global -> table -> payload\n *\n * $global attributes are initially set on all objects\n * table attributes overwrite $global attributes for specific tables\n * payload attributes overwrite set $global and table attributes\n *\n * Expects a table name and a payload object as parameters\n * Returns a new object with all properties applied\n *\n * Example:\n * td.set('$global', 'foo', 'bar')\n * td.set('$global', 'bar', 'foo')\n * td.set('table', 'foo', 'foo')\n *\n * td.applyProperties('sales', {})\n * // > { foo: 'bar', bar: 'foo'}\n *\n * td.applyProperties('table', {})\n * // > { foo: 'foo', bar: 'foo'}\n *\n * td.applyProperties('table', {bar: 'bar'})\n * // > { foo: 'foo', bar: 'bar'}\n *\n * td.applyProperties('table', {foo: 'qux'})\n * // > { foo: 'qux', bar: 'foo'}\n *\n */\n\n\nexports.applyProperties = function applyProperties(table, payload) {\n return _.assign({}, this.get('$global'), this.get(table), payload);\n};\n/**\n * Sends an event to Treasure Data. If the table does not exist it will be created for you.\n * Records will have additional properties applied to them if $global or table-specific attributes are configured using Treasure#set.\n *\n * @param {string} table - table name, must consist only of lower case letters, numbers, and _, must be longer than or equal to 3 chars, the total length of database and table must be shorter than 129 chars.\n * @param {object} record - Object that will be serialized to JSON and sent to the server\n * @param {boolean=} [success] - Callback for when sending the event is successful\n * @param {boolean=} [error] - Callback for when sending the event is unsuccessful\n */\n\n\nexports.addRecord = function addRecord(table, record, success, error) {\n validateRecord(table, record);\n var propertiesRecord = this.applyProperties(table, record);\n var finalRecord = this.inSignedMode() ? propertiesRecord : _.omit(propertiesRecord, ['td_ip', 'td_client_id', 'td_global_id']);\n var request = {\n apikey: this.client.writeKey,\n record: finalRecord,\n time: null,\n type: this.client.requestType,\n url: this.client.endpoint + this.client.database + '/' + table\n };\n\n if (request.record.time) {\n request.time = request.record.time;\n }\n\n if (this.client.development) {\n this.log('addRecord', request);\n } else if (!this.areEventsBlocked()) {\n this._sendRecord(request, success, error, this.areEventsBlocked());\n }\n};\n\nexports.addConsentRecord = function addConsentRecord(table, record, success, error) {\n validateRecord(table, record);\n var request = {\n apikey: this.client.writeKey,\n record: record,\n time: null,\n type: this.client.requestType,\n url: this.client.endpoint + this.client.database + '/' + table\n };\n\n if (request.record.time) {\n request.time = request.record.time;\n }\n\n if (this.client.development) {\n this.log('addConsentRecord', request);\n } else {\n this._sendRecord(request, success, error, false);\n }\n}; // Private functions, for testing only\n\n\nexports._validateRecord = validateRecord;\n\n//# sourceURL=webpack:///./lib/record.js?"); +eval("/**\n * Treasure Record\n */\n// Modules\nvar misc = __webpack_require__(/*! ./utils/misc */ \"./lib/utils/misc.js\");\n\nvar _ = __webpack_require__(/*! ./utils/lodash */ \"./lib/utils/lodash.js\");\n\nvar global = __webpack_require__(/*! global */ \"./node_modules/global/window.js\");\n\nvar cookie = __webpack_require__(/*! ./vendor/js-cookies */ \"./lib/vendor/js-cookies.js\");\n\nvar setCookie = __webpack_require__(/*! ./utils/setCookie */ \"./lib/utils/setCookie.js\");\n\nvar api = __webpack_require__(/*! ./utils/xhr */ \"./lib/utils/xhr.js\");\n\nvar noop = _.noop;\nvar invariant = misc.invariant; // Helpers\n\n/*\n * Validate record\n */\n\nfunction validateRecord(table, record) {\n invariant(_.isString(table), 'Must provide a table');\n invariant(/^[a-z0-9_]{3,255}$/.test(table), 'Table must be between 3 and 255 characters and must ' + 'consist only of lower case letters, numbers, and _');\n invariant(_.isObject(record), 'Must provide a record');\n}\n\nvar BLOCKEVENTSCOOKIE = '__td_blockEvents';\nvar SIGNEDMODECOOKIE = '__td_signed';\nexports.BLOCKEVENTSCOOKIE = BLOCKEVENTSCOOKIE;\nexports.SIGNEDMODECOOKIE = SIGNEDMODECOOKIE;\n/**\n * @Treasure.blockEvents\n * Block all events from being sent to Treasure Data.\n *\n * @example\n * var td = new Treasure({...})\n * td.trackEvent('customevent')\n * td.blockEvents()\n * td.trackEvent('willnotbetracked')\n */\n\nexports.blockEvents = function blockEvents() {\n setCookie(this.client.storage, BLOCKEVENTSCOOKIE, 'true');\n};\n/**\n * @Treasure.unblockEvents\n * Unblock all events; events will be sent to Treasure Data.\n *\n * @example\n * var td = new Treasure({...})\n * td.blockEvents()\n * td.trackEvent('willnotbetracked')\n * td.unblockEvents()\n * td.trackEvent('willbetracked')\n */\n\n\nexports.unblockEvents = function unblockEvents() {\n setCookie(this.client.storage, BLOCKEVENTSCOOKIE, 'false');\n};\n/**\n * @Treasure.areEventsBlocked\n * Informational method, expressing whether events are blocked or not.\n *\n * @example\n * var td = new Treasure({...})\n * td.areEventsBlocked() // false, default\n * td.blockEvents()\n * td.areEventsBlocked() // true\n */\n\n\nexports.areEventsBlocked = function areEventsBlocked() {\n return cookie.getItem(BLOCKEVENTSCOOKIE) === 'true';\n};\n/**\n * @Treasure.setSignedMode\n * Sets the user to Signed Mode.\n * Permit sending of Personally Identifying Information over the wire: td_ip, td_client_id, and td_global_id\n *\n * @example\n * var td = new Treasure({...})\n * td.setSignedMode()\n * td.trackEvent('willbetracked') // will send td_ip and td_client_id; td_global_id will also be sent if set.\n */\n\n\nexports.setSignedMode = function setSignedMode() {\n if (this.client.storeConsentByLocalStorage) {\n if (!misc.isLocalStorageAccessible()) return this;\n global.localStorage.setItem(SIGNEDMODECOOKIE, 'true');\n } else {\n setCookie(this.client.storage, SIGNEDMODECOOKIE, 'true');\n }\n\n this.resetUUID(this.client.storage, this.client.track.uuid);\n return this;\n};\n/**\n * @Treasure.setAnonymousMode\n *\n * Sets the user to anonymous mode.\n * Prohibit sending of Personally Identifying Information over the wire: td_ip, td_client_id, and td_global_id\n *\n * @param {boolean} keepIdentifier - Keep the cookies. By default setAnonymousMode will remove all cookies that are set by Treasure Data JavaScript SDK, you can set keepIdentifier parameter to true to not remove the cookies.\n *\n * @example\n * var td = new Treasure({...})\n * td.setAnonymousMode()\n * td.trackEvent('willbetracked') // will NOT send td_ip and td_client_id; td_global_id will also NOT be sent if set.\n */\n\n\nexports.setAnonymousMode = function setAnonymousMode(keepIdentifier) {\n if (this.client.storeConsentByLocalStorage) {\n if (!misc.isLocalStorageAccessible()) return this;\n global.localStorage.setItem(SIGNEDMODECOOKIE, 'false');\n } else {\n setCookie(this.client.storage, SIGNEDMODECOOKIE, 'false');\n }\n\n if (!keepIdentifier) {\n // remove _td cookie\n setCookie(this.client.storage, this.client.storage.name); // remove global id cookie\n\n this.removeCachedGlobalID(); // remove server side cookie\n\n this.removeServerCookie();\n }\n\n return this;\n};\n/**\n * @Treasure.inSignedMode\n *\n * Tells whether or not the user is in Signed Mode.\n * Informational method, indicating whether trackEvents method will automatically collect td_ip, td_client_id, and td_global_id if set.\n *\n * @example\n * var td = new Treasure({...})\n * td.inSignedMode() // false, default\n * td.trackEvent('willbetracked') // will NOT send td_ip and td_client_id; td_global_id will also NOT be sent if set.\n * td.setSignedMode()\n * td.inSignedMode() // true\n * td.trackEvent('willbetracked') // will send td_ip and td_client_id; td_global_id will also be sent if set.\n */\n\n\nexports.inSignedMode = function inSignedMode() {\n if (this.client.storeConsentByLocalStorage) {\n if (!misc.isLocalStorageAccessible()) return false;\n return global.localStorage.getItem([SIGNEDMODECOOKIE]) !== 'false' && (global.localStorage.getItem([SIGNEDMODECOOKIE]) === 'true' || this.client.startInSignedMode);\n }\n\n return cookie.getItem(SIGNEDMODECOOKIE) !== 'false' && (cookie.getItem(SIGNEDMODECOOKIE) === 'true' || this.client.startInSignedMode);\n};\n/*\n * Send record\n */\n\n\nexports._sendRecord = function _sendRecord(request, success, error, blockedEvent) {\n success = success || noop;\n error = error || noop;\n\n if (blockedEvent) {\n return;\n }\n\n var params = ['modified=' + encodeURIComponent(new Date().getTime())];\n\n if (request.time) {\n params.push('time=' + encodeURIComponent(request.time));\n }\n\n var url = request.url + '?' + params.join('&');\n var isClickedLink = request.record.tag === 'a' && !!request.record.href;\n var requestHeaders = {};\n var payload;\n var ignoreDefaultHeaders = false;\n\n if (this.client.useNewJavaScriptEndpoint) {\n requestHeaders['Authorization'] = 'TD1 ' + request.apikey;\n requestHeaders['User-Agent'] = navigator.userAgent;\n\n if (this.isGlobalIdEnabled()) {\n requestHeaders['Content-Type'] = misc.globalIdAdlHeaders['Content-Type'];\n requestHeaders['Accept'] = misc.globalIdAdlHeaders['Accept'];\n } else {\n requestHeaders['Content-Type'] = misc.adlHeaders['Content-Type'];\n requestHeaders['Accept'] = misc.adlHeaders['Accept'];\n }\n\n ignoreDefaultHeaders = true;\n payload = {\n events: [request.record]\n };\n } else {\n requestHeaders['X-TD-Write-Key'] = request.apikey;\n payload = request.record;\n }\n\n if (window.fetch && (this._windowBeingUnloaded || isClickedLink)) {\n api.postWithTimeout(url, payload, this.client.jsonpTimeout, {\n method: 'POST',\n keepalive: true,\n credentials: 'include',\n ignoreDefaultHeaders: ignoreDefaultHeaders,\n headers: requestHeaders\n }).then(success).catch(error);\n } else {\n api.post(url, payload, {\n ignoreDefaultHeaders: ignoreDefaultHeaders,\n headers: requestHeaders\n }).then(success).catch(error);\n }\n}; // Methods\n\n/*\n * Treasure#applyProperties\n *\n * Applies properties on a payload object\n *\n * Starts with an empty object and applies properties in the following order:\n * $global -> table -> payload\n *\n * $global attributes are initially set on all objects\n * table attributes overwrite $global attributes for specific tables\n * payload attributes overwrite set $global and table attributes\n *\n * Expects a table name and a payload object as parameters\n * Returns a new object with all properties applied\n *\n * Example:\n * td.set('$global', 'foo', 'bar')\n * td.set('$global', 'bar', 'foo')\n * td.set('table', 'foo', 'foo')\n *\n * td.applyProperties('sales', {})\n * // > { foo: 'bar', bar: 'foo'}\n *\n * td.applyProperties('table', {})\n * // > { foo: 'foo', bar: 'foo'}\n *\n * td.applyProperties('table', {bar: 'bar'})\n * // > { foo: 'foo', bar: 'bar'}\n *\n * td.applyProperties('table', {foo: 'qux'})\n * // > { foo: 'qux', bar: 'foo'}\n *\n */\n\n\nexports.applyProperties = function applyProperties(table, payload) {\n return _.assign({}, this.get('$global'), this.get(table), payload);\n};\n/**\n * Sends an event to Treasure Data. If the table does not exist it will be created for you.\n * Records will have additional properties applied to them if $global or table-specific attributes are configured using Treasure#set.\n *\n * @param {string} table - table name, must consist only of lower case letters, numbers, and _, must be longer than or equal to 3 chars, the total length of database and table must be shorter than 129 chars.\n * @param {object} record - Object that will be serialized to JSON and sent to the server\n * @param {boolean=} [success] - Callback for when sending the event is successful\n * @param {boolean=} [error] - Callback for when sending the event is unsuccessful\n */\n\n\nexports.addRecord = function addRecord(table, record, success, error) {\n validateRecord(table, record);\n var propertiesRecord = this.applyProperties(table, record);\n var finalRecord = this.inSignedMode() ? propertiesRecord : _.omit(propertiesRecord, ['td_ip', 'td_client_id', 'td_global_id']);\n var request = {\n apikey: this.client.writeKey,\n record: finalRecord,\n time: null,\n type: this.client.requestType,\n url: this.client.endpoint + this.client.database + '/' + table\n };\n\n if (request.record.time) {\n request.time = request.record.time;\n }\n\n if (this.client.development) {\n this.log('addRecord', request);\n } else if (!this.areEventsBlocked()) {\n this._sendRecord(request, success, error, this.areEventsBlocked());\n }\n};\n\nexports.addConsentRecord = function addConsentRecord(table, record, success, error) {\n validateRecord(table, record);\n var request = {\n apikey: this.client.writeKey,\n record: record,\n time: null,\n type: this.client.requestType,\n url: this.client.endpoint + this.client.database + '/' + table\n };\n\n if (request.record.time) {\n request.time = request.record.time;\n }\n\n if (this.client.development) {\n this.log('addConsentRecord', request);\n } else {\n this._sendRecord(request, success, error, false);\n }\n}; // Private functions, for testing only\n\n\nexports._validateRecord = validateRecord;\n\n//# sourceURL=webpack:///./lib/record.js?"); /***/ }), @@ -258,7 +258,7 @@ eval("/**\n * Fake lodash\n * Only import the parts of lodash that I'm using to /*! no static exports found */ /***/ (function(module, exports) { -eval("function disposable(action) {\n var disposed = false;\n return function dispose() {\n if (!disposed) {\n disposed = true;\n action();\n }\n };\n}\n\nfunction invariant(conditon, text) {\n if (!conditon) {\n throw new Error(text);\n }\n}\n\nfunction _timeout(milliseconds, promise, timeoutMessage) {\n var timerPromise = new Promise(function (resolve, reject) {\n setTimeout(function () {\n reject(new Error(timeoutMessage || 'Operation Timeout'));\n }, milliseconds);\n });\n return Promise.race([timerPromise, promise]);\n}\n\nfunction fetchWithTimeout(url, milliseconds, options) {\n if (window.AbortController) {\n var controller = new window.AbortController();\n var promise = window.fetch(url, Object.assign({}, options, {\n signal: controller.signal\n }));\n var timeoutId = setTimeout(function () {\n controller.abort();\n }, milliseconds);\n return promise['finally'](function () {\n clearTimeout(timeoutId);\n });\n } else {\n return _timeout(milliseconds, window.fetch(url, options), 'Request Timeout');\n }\n}\n\nfunction capitalizeFirstLetter(str) {\n var firstCodeUnit = str[0];\n\n if (firstCodeUnit < \"\\uD800\" || firstCodeUnit > \"\\uDFFF\") {\n return str[0].toUpperCase() + str.slice(1);\n }\n\n return str.slice(0, 2).toUpperCase() + str.slice(2);\n}\n\nfunction isLocalStorageAccessible() {\n var test = '__td__';\n\n try {\n localStorage.setItem(test, test);\n localStorage.removeItem(test);\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction camelCase(str) {\n if (!str) return;\n return str.toLowerCase().split(' ').reduce(function (name, word, index) {\n if (index === 0) {\n name += word;\n } else {\n name += capitalizeFirstLetter(word);\n }\n\n return name;\n }, '');\n}\n\nmodule.exports = {\n disposable: disposable,\n invariant: invariant,\n fetchWithTimeout: fetchWithTimeout,\n camelCase: camelCase,\n isLocalStorageAccessible: isLocalStorageAccessible,\n globalIdContentTypeHeader: 'application/vnd.treasuredata.v1.js+json',\n globalIdAcceptHeader: 'application/vnd.treasuredata.v1.js+json'\n};\n\n//# sourceURL=webpack:///./lib/utils/misc.js?"); +eval("function disposable(action) {\n var disposed = false;\n return function dispose() {\n if (!disposed) {\n disposed = true;\n action();\n }\n };\n}\n\nfunction invariant(conditon, text) {\n if (!conditon) {\n throw new Error(text);\n }\n}\n\nfunction _timeout(milliseconds, promise, timeoutMessage) {\n var timerPromise = new Promise(function (resolve, reject) {\n setTimeout(function () {\n reject(new Error(timeoutMessage || 'Operation Timeout'));\n }, milliseconds);\n });\n return Promise.race([timerPromise, promise]);\n}\n\nfunction fetchWithTimeout(url, milliseconds, options) {\n if (window.AbortController) {\n var controller = new window.AbortController();\n var promise = window.fetch(url, Object.assign({}, options, {\n signal: controller.signal\n }));\n var timeoutId = setTimeout(function () {\n controller.abort();\n }, milliseconds);\n return promise['finally'](function () {\n clearTimeout(timeoutId);\n });\n } else {\n return _timeout(milliseconds, window.fetch(url, options), 'Request Timeout');\n }\n}\n\nfunction capitalizeFirstLetter(str) {\n var firstCodeUnit = str[0];\n\n if (firstCodeUnit < \"\\uD800\" || firstCodeUnit > \"\\uDFFF\") {\n return str[0].toUpperCase() + str.slice(1);\n }\n\n return str.slice(0, 2).toUpperCase() + str.slice(2);\n}\n\nfunction isLocalStorageAccessible() {\n var test = '__td__';\n\n try {\n localStorage.setItem(test, test);\n localStorage.removeItem(test);\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction camelCase(str) {\n if (!str) return;\n return str.toLowerCase().split(' ').reduce(function (name, word, index) {\n if (index === 0) {\n name += word;\n } else {\n name += capitalizeFirstLetter(word);\n }\n\n return name;\n }, '');\n}\n\nvar adlHeaders = {\n 'Content-Type': 'application/vnd.treasuredata.v1+json',\n 'Accept': 'application/vnd.treasuredata.v1+json'\n};\nvar globalIdAdlHeaders = {\n 'Content-Type': 'application/vnd.treasuredata.v1.js+json',\n 'Accept': 'application/vnd.treasuredata.v1.js+json'\n};\nmodule.exports = {\n disposable: disposable,\n invariant: invariant,\n fetchWithTimeout: fetchWithTimeout,\n camelCase: camelCase,\n isLocalStorageAccessible: isLocalStorageAccessible,\n adlHeaders: adlHeaders,\n globalIdAdlHeaders: globalIdAdlHeaders\n};\n\n//# sourceURL=webpack:///./lib/utils/misc.js?"); /***/ }), @@ -280,7 +280,7 @@ eval("var cookie = __webpack_require__(/*! ../vendor/js-cookies */ \"./lib/vendo /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -eval("// (C) Treasure Data 2020\n\n/* global XMLHttpRequest fetch */\nvar win = __webpack_require__(/*! global/window */ \"./node_modules/global/window.js\");\n\nvar assign = __webpack_require__(/*! ./lodash */ \"./lib/utils/lodash.js\").assign;\n\nvar OK_STATUS = 200;\nvar NOT_MODIFIED = 304;\nvar defaultHeaders = {\n 'Content-Type': 'application/vnd.treasuredata.v1+json',\n 'Accept': 'application/vnd.treasuredata.v1+json'\n};\nvar FETCH_CREDENTIALS = {\n 'same-origin': 'same-origin',\n include: 'include',\n omit: 'omit'\n};\nvar DEFAULT_CREDENTIALS = FETCH_CREDENTIALS.include;\n\nfunction isValidStatus(status) {\n return status >= OK_STATUS && status < 300 || status === NOT_MODIFIED;\n}\n\nfunction toJSON(text) {\n var result;\n\n try {\n result = JSON.parse(text);\n } catch (e) {\n result = {};\n }\n\n return result;\n}\n\nfunction getHeaders(headers, ignoreDefaultHeaders) {\n headers = headers || {};\n\n if (ignoreDefaultHeaders) {\n return assign({}, headers);\n }\n\n return assign({}, defaultHeaders, headers);\n}\n\nfunction isFetchSupported() {\n return 'fetch' in win;\n}\n\nfunction isDefaultHeadersIgnored(options) {\n options = options || {};\n return options.ignoreDefaultHeaders || false;\n}\n\nfunction getCredentials(options) {\n options = options || {};\n return FETCH_CREDENTIALS[options.credentials] || DEFAULT_CREDENTIALS;\n} // Fetch API\n\n\nfunction postWithFetch(url, body, options) {\n options = options || {};\n var headers = options.headers || {};\n return fetch(url, {\n method: 'POST',\n headers: getHeaders(headers, isDefaultHeadersIgnored(options)),\n credentials: getCredentials(options),\n body: JSON.stringify(body)\n }).then(function (response) {\n if (!response.ok) {\n throw Error(response.statusText);\n }\n\n return response.text();\n }).then(function (text) {\n if (!text) return {};\n return JSON.parse(text);\n });\n}\n\nfunction getWithFetch(url, options) {\n options = options || {};\n var headers = options.headers || {};\n var method = options.method || 'GET';\n return fetch(url, {\n method: method,\n headers: getHeaders(headers, isDefaultHeadersIgnored(options)),\n credentials: getCredentials(options)\n }).then(function (response) {\n if (!response.ok) {\n throw Error(response.statusText);\n }\n\n return response.text();\n }).then(function (text) {\n if (!text) return {};\n return JSON.parse(text);\n });\n}\n\nfunction registerXhrEvents(xhr, resolve, reject) {\n xhr.onload = function onload() {\n if (isValidStatus(xhr.status)) {\n resolve(toJSON(xhr.responseText));\n } else {\n reject(new Error('Internal XMLHttpRequest error'));\n }\n };\n\n xhr.onerror = reject;\n}\n\nfunction createXHR(method, url, options) {\n options = options || {};\n var headers = options.headers || {};\n var xhr = new XMLHttpRequest();\n xhr.open(method, url);\n xhr.withCredentials = Boolean(getCredentials(options));\n headers = getHeaders(options.headers, isDefaultHeadersIgnored(options));\n var headerKey;\n\n for (headerKey in headers) {\n if (headers.hasOwnProperty(headerKey)) {\n xhr.setRequestHeader(headerKey, headers[headerKey]);\n }\n }\n\n return xhr;\n}\n\nfunction _timeout(milliseconds, promise, timeoutMessage) {\n var timerPromise = new Promise(function (resolve, reject) {\n setTimeout(function () {\n reject(new Error(timeoutMessage || 'Operation Timeout'));\n }, milliseconds);\n });\n return Promise.race([timerPromise, promise]);\n}\n\nfunction postWithTimeout(url, body, milliseconds, options) {\n if (window.AbortController) {\n var controller = new window.AbortController();\n var promise = window.fetch(url, Object.assign({}, options, {\n signal: controller.signal\n }));\n var timeoutId = setTimeout(function () {\n controller.abort();\n }, milliseconds);\n return promise['finally'](function () {\n clearTimeout(timeoutId);\n });\n } else {\n return _timeout(milliseconds, postWithFetch(url, body, options), 'Request Timeout');\n }\n}\n\nmodule.exports = {\n post: function post(url, body, options) {\n if (isFetchSupported()) {\n return postWithFetch(url, body, options);\n }\n\n return new Promise(function (resolve, reject) {\n var xhr = createXHR('POST', url, options);\n registerXhrEvents(xhr, resolve, reject);\n xhr.send(JSON.stringify(body));\n });\n },\n get: function get(url, options) {\n options = options || {};\n\n if (isFetchSupported()) {\n return getWithFetch(url, options);\n }\n\n var method = options.method || 'GET';\n return new Promise(function (resolve, reject) {\n var xhr = createXHR(method, url, options);\n registerXhrEvents(xhr, resolve, reject);\n xhr.send(null);\n });\n },\n postWithTimeout: postWithTimeout\n};\n\n//# sourceURL=webpack:///./lib/utils/xhr.js?"); +eval("// (C) Treasure Data 2020\n\n/* global XMLHttpRequest fetch */\nvar win = __webpack_require__(/*! global/window */ \"./node_modules/global/window.js\");\n\nvar assign = __webpack_require__(/*! ./lodash */ \"./lib/utils/lodash.js\").assign;\n\nvar OK_STATUS = 200;\nvar NOT_MODIFIED = 304;\nvar defaultHeaders = {\n 'Content-Type': 'application/json',\n 'X-TD-Fetch-Api': 'true'\n};\nvar FETCH_CREDENTIALS = {\n 'same-origin': 'same-origin',\n include: 'include',\n omit: 'omit'\n};\nvar DEFAULT_CREDENTIALS = FETCH_CREDENTIALS.include;\n\nfunction isValidStatus(status) {\n return status >= OK_STATUS && status < 300 || status === NOT_MODIFIED;\n}\n\nfunction toJSON(text) {\n var result;\n\n try {\n result = JSON.parse(text);\n } catch (e) {\n result = {};\n }\n\n return result;\n}\n\nfunction getHeaders(headers, ignoreDefaultHeaders) {\n headers = headers || {};\n\n if (ignoreDefaultHeaders) {\n return assign({}, headers);\n }\n\n return assign({}, defaultHeaders, headers);\n}\n\nfunction isFetchSupported() {\n return 'fetch' in win;\n}\n\nfunction isDefaultHeadersIgnored(options) {\n options = options || {};\n return options.ignoreDefaultHeaders || false;\n}\n\nfunction getCredentials(options) {\n options = options || {};\n return FETCH_CREDENTIALS[options.credentials] || DEFAULT_CREDENTIALS;\n} // Fetch API\n\n\nfunction postWithFetch(url, body, options) {\n options = options || {};\n var headers = options.headers || {};\n return fetch(url, {\n method: 'POST',\n headers: getHeaders(headers, isDefaultHeadersIgnored(options)),\n credentials: getCredentials(options),\n body: JSON.stringify(body)\n }).then(function (response) {\n if (!response.ok) {\n throw Error(response.statusText);\n }\n\n return response.text();\n }).then(function (text) {\n if (!text) return {};\n return JSON.parse(text);\n });\n}\n\nfunction getWithFetch(url, options) {\n options = options || {};\n var headers = options.headers || {};\n var method = options.method || 'GET';\n return fetch(url, {\n method: method,\n headers: getHeaders(headers, isDefaultHeadersIgnored(options)),\n credentials: getCredentials(options)\n }).then(function (response) {\n if (!response.ok) {\n throw Error(response.statusText);\n }\n\n return response.text();\n }).then(function (text) {\n if (!text) return {};\n return JSON.parse(text);\n });\n}\n\nfunction registerXhrEvents(xhr, resolve, reject) {\n xhr.onload = function onload() {\n if (isValidStatus(xhr.status)) {\n resolve(toJSON(xhr.responseText));\n } else {\n reject(new Error('Internal XMLHttpRequest error'));\n }\n };\n\n xhr.onerror = reject;\n}\n\nfunction createXHR(method, url, options) {\n options = options || {};\n var headers = options.headers || {};\n var xhr = new XMLHttpRequest();\n xhr.open(method, url);\n xhr.withCredentials = Boolean(getCredentials(options));\n headers = getHeaders(options.headers, isDefaultHeadersIgnored(options));\n var headerKey;\n\n for (headerKey in headers) {\n if (headers.hasOwnProperty(headerKey)) {\n xhr.setRequestHeader(headerKey, headers[headerKey]);\n }\n }\n\n return xhr;\n}\n\nfunction _timeout(milliseconds, promise, timeoutMessage) {\n var timerPromise = new Promise(function (resolve, reject) {\n setTimeout(function () {\n reject(new Error(timeoutMessage || 'Operation Timeout'));\n }, milliseconds);\n });\n return Promise.race([timerPromise, promise]);\n}\n\nfunction postWithTimeout(url, body, milliseconds, options) {\n if (window.AbortController) {\n var controller = new window.AbortController();\n var headers = getHeaders(options.headers, isDefaultHeadersIgnored(options));\n options.headers = headers;\n var promise = window.fetch(url, Object.assign({}, options, {\n signal: controller.signal\n }));\n var timeoutId = setTimeout(function () {\n controller.abort();\n }, milliseconds);\n return promise['finally'](function () {\n clearTimeout(timeoutId);\n });\n } else {\n return _timeout(milliseconds, postWithFetch(url, body, options), 'Request Timeout');\n }\n}\n\nmodule.exports = {\n post: function post(url, body, options) {\n if (isFetchSupported()) {\n return postWithFetch(url, body, options);\n }\n\n return new Promise(function (resolve, reject) {\n var xhr = createXHR('POST', url, options);\n registerXhrEvents(xhr, resolve, reject);\n xhr.send(JSON.stringify(body));\n });\n },\n get: function get(url, options) {\n options = options || {};\n\n if (isFetchSupported()) {\n return getWithFetch(url, options);\n }\n\n var method = options.method || 'GET';\n return new Promise(function (resolve, reject) {\n var xhr = createXHR(method, url, options);\n registerXhrEvents(xhr, resolve, reject);\n xhr.send(null);\n });\n },\n postWithTimeout: postWithTimeout\n};\n\n//# sourceURL=webpack:///./lib/utils/xhr.js?"); /***/ }), diff --git a/dist/td.min.js b/dist/td.min.js index effff2c3..a484f32d 100644 --- a/dist/td.min.js +++ b/dist/td.min.js @@ -1,8 +1,8 @@ -!function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=32)}([function(t,e,n){t.exports={forEach:n(35),isNumber:n(44),isObject:n(1),isString:n(8),isArray:n(5),isFunction:n(15),isEmpty:n(45),keys:n(9),assign:n(46),forIn:n(51),omit:n(53),cloneDeep:n(67),noop:n(74)}},function(t,e){t.exports=function(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}},function(t,e,n){(function(e){"undefined"!=typeof window?t.exports=window:void 0!==e?t.exports=e:"undefined"!=typeof self?t.exports=self:t.exports={}}).call(this,n(7))},function(t,e){t.exports={disposable:function(t){var e=!1;return function(){e||(e=!0,t())}},invariant:function(t,e){if(!t)throw new Error(e)},fetchWithTimeout:function(t,e,n){if(window.AbortController){var r=new window.AbortController,o=window.fetch(t,Object.assign({},n,{signal:r.signal})),i=setTimeout((function(){r.abort()}),e);return o.finally((function(){clearTimeout(i)}))}return function(t,e,n){var r=new Promise((function(e,r){setTimeout((function(){r(new Error(n||"Operation Timeout"))}),t)}));return Promise.race([r,e])}(e,window.fetch(t,n),"Request Timeout")},camelCase:function(t){if(t)return t.toLowerCase().split(" ").reduce((function(t,e,n){return t+=0===n?e:function(t){var e=t[0];return e<"\ud800"||e>"\udfff"?t[0].toUpperCase()+t.slice(1):t.slice(0,2).toUpperCase()+t.slice(2)}(e)}),"")},isLocalStorageAccessible:function(){try{return localStorage.setItem("__td__","__td__"),localStorage.removeItem("__td__"),!0}catch(t){return!1}},globalIdContentTypeHeader:"application/vnd.treasuredata.v1.js+json",globalIdAcceptHeader:"application/vnd.treasuredata.v1.js+json"}},function(t,e){t.exports=function(t){return!!t&&"object"==typeof t}},function(t,e,n){var r=n(14),o=n(11),i=n(4),s=Object.prototype.toString,a=r(Array,"isArray")||function(t){return i(t)&&o(t.length)&&"[object Array]"==s.call(t)};t.exports=a},function(t,e){var n=function(t){try{return encodeURIComponent(t)}catch(t){console.error("error encode %o")}return null},r=function(t){try{return decodeURIComponent(t)}catch(t){console.error("error decode %o")}return null},o={getItem:function(t){return t&&r(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+function(t){return n(t).replace(/[\-\.\+\*]/g,"\\$&")}(t)+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null},setItem:function(t,e,r,o,i,s,a){if(!t||/^(?:expires|max\-age|path|domain|secure)$/i.test(t))return!1;var c="";if(r)switch(r.constructor){case Number:c=r===1/0?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+r;break;case String:c="; expires="+r;break;case Date:c="; expires="+r.toUTCString()}var u="";return a&&"NONE"===a.toUpperCase()?u="; Secure; SameSite="+a:(s&&(u+="; Secure"),a&&(u+="; SameSite="+a)),document.cookie=[n(t),"=",n(e),c,i?"; domain="+i:"",o?"; path="+o:"",u].join(""),!0},removeItem:function(t,e,r){return!!this.hasItem(t)&&(document.cookie=[n(t),"=; expires=Thu, 01 Jan 1970 00:00:00 GMT",r?"; domain="+r:"",e?"; path="+e:""].join(""),!0)},hasItem:function(t){return!!t&&new RegExp("(?:^|;\\s*)"+n(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie)},keys:function(){var t=document.cookie.replace(/((?:^|\s*;)[^=]+)(?=;|$)|^\s*|\s*(?:=[^;]*)?(?:\1|$)/g,"").split(/\s*(?:=[^;]*)?;\s*/);return t=t.map((function(t){return r(t)}))}};t.exports=o},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){var r=n(4),o=Object.prototype.toString;t.exports=function(t){return"string"==typeof t||r(t)&&"[object String]"==o.call(t)}},function(t,e,n){var r=n(14),o=n(10),i=n(1),s=n(40),a=n(22),c=r(Object,"keys"),u=c?function(t){var e=null==t?void 0:t.constructor;return"function"==typeof e&&e.prototype===t||("function"==typeof t?a.enumPrototypes:o(t))?s(t):i(t)?c(t):[]}:s;t.exports=u},function(t,e,n){var r=n(27),o=n(11);t.exports=function(t){return null!=t&&o(r(t))}},function(t,e){t.exports=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}},function(t,e,n){var r=n(43);t.exports=function(t,e,n){if("function"!=typeof t)return r;if(void 0===e)return t;switch(n){case 1:return function(n){return t.call(e,n)};case 3:return function(n,r,o){return t.call(e,n,r,o)};case 4:return function(n,r,o,i){return t.call(e,n,r,o,i)};case 5:return function(n,r,o,i,s){return t.call(e,n,r,o,i,s)}}return function(){return t.apply(e,arguments)}}},function(t,e,n){var r=n(1),o=n(8),i=n(22);t.exports=function(t){if(i.unindexedChars&&o(t)){for(var e=-1,n=t.length,s=Object(t);++e0,S=l.enumErrorProps&&(t===p||t instanceof Error),j=l.enumPrototypes&&s(t);++r=200&&r<300||304===r?e(function(t){var e;try{e=JSON.parse(t)}catch(t){e={}}return e}(t.responseText)):n(new Error("Internal XMLHttpRequest error"))},t.onerror=n}function h(t,e,n){var r,o=(n=n||{}).headers||{},i=new XMLHttpRequest;for(r in i.open(t,e),i.withCredentials=Boolean(l(n)),o=c(n.headers,f(n)))o.hasOwnProperty(r)&&i.setRequestHeader(r,o[r]);return i}t.exports={post:function(t,e,n){return u()?d(t,e,n):new Promise((function(r,o){var i=h("POST",t,n);p(i,r,o),i.send(JSON.stringify(e))}))},get:function(t,e){if(e=e||{},u())return function(t,e){var n=(e=e||{}).headers||{},r=e.method||"GET";return fetch(t,{method:r,headers:c(n,f(e)),credentials:l(e)}).then((function(t){if(!t.ok)throw Error(t.statusText);return t.text()})).then((function(t){return t?JSON.parse(t):{}}))}(t,e);var n=e.method||"GET";return new Promise((function(r,o){var i=h(n,t,e);p(i,r,o),i.send(null)}))},postWithTimeout:function(t,e,n,r){if(window.AbortController){var o=new window.AbortController,i=window.fetch(t,Object.assign({},r,{signal:o.signal})),s=setTimeout((function(){o.abort()}),n);return i.finally((function(){clearTimeout(s)}))}return function(t,e,n){var r=new Promise((function(e,r){setTimeout((function(){r(new Error(n||"Operation Timeout"))}),t)}));return Promise.race([r,e])}(n,d(t,e,r),"Request Timeout")}}},function(t,e){t.exports={GLOBAL:"Treasure",VERSION:"3.1.0",HOST:"in.treasuredata.com",DATABASE:"",PATHNAME:"/"}},function(t,e){t.exports=function(t,e){for(var n=-1,r=t.length;++n-1&&t%1==0&&t=0;r--)n.push(e.slice(r).join("."));return n}(t.domain),l=f.length,d=0;if(n){if(r.getItem(e)===n)return;for(;d2?n[s-2]:void 0,c=s>2?n[2]:void 0,u=s>1?n[s-1]:void 0;for("function"==typeof a?(a=r(a,u,5),s-=2):s-=(a="function"==typeof u?u:void 0)?1:0,c&&o(n[0],n[1],c)&&(a=s<3?void 0:a,s=1);++i=200?i(e):null,l=e.length;f&&(c=o,u=!1,e=f);t:for(;++a=1;e--){var n=t.slice(e).join("."),r="_td_domain_"+n;if(s.setItem(r,n,3600,"/",n),s.getItem(r)===n)return n}return document.location.hostname},sscServer:function(t){return["ssc",t].join(".")},storeConsentByLocalStorage:!1},e.configure=function(t){return this.client=r.assign({globals:{}},e.DEFAULT_CONFIG,t,{requestType:"fetch"}),function(t){o(r.isObject(t),"Check out our JavaScript SDK Usage Guide: https://github.com/treasure-data/td-js-sdk#api"),o(r.isString(t.writeKey),"Must provide a writeKey"),o(r.isString(t.database),"Must provide a database"),o(/^[a-z0-9_]{3,255}$/.test(t.database),"Database must be between 3 and 255 characters and must consist only of lower case letters, numbers, and _")}(this.client),this.client.endpoint||(this.client.endpoint="https://"+this.client.host+this.client.pathname),this},e.set=function(t,e,n){return r.isObject(t)&&(e=t,t="$global"),this.client.globals[t]=this.client.globals[t]||{},r.isObject(e)?r.assign(this.client.globals[t],e):this.client.globals[t][e]=n,this},e.get=function(t,e){return t=t||"$global",this.client.globals[t]=this.client.globals[t]||{},e?this.client.globals[t][e]:this.client.globals[t]},e.isGlobalIdEnabled=function(){return"td_global_id"===this.get(null,"td_global_id")}},function(t,e,n){ +!function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=32)}([function(t,e,n){t.exports={forEach:n(35),isNumber:n(44),isObject:n(1),isString:n(8),isArray:n(5),isFunction:n(15),isEmpty:n(45),keys:n(9),assign:n(46),forIn:n(51),omit:n(53),cloneDeep:n(67),noop:n(74)}},function(t,e){t.exports=function(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}},function(t,e,n){(function(e){"undefined"!=typeof window?t.exports=window:void 0!==e?t.exports=e:"undefined"!=typeof self?t.exports=self:t.exports={}}).call(this,n(7))},function(t,e){t.exports={disposable:function(t){var e=!1;return function(){e||(e=!0,t())}},invariant:function(t,e){if(!t)throw new Error(e)},fetchWithTimeout:function(t,e,n){if(window.AbortController){var r=new window.AbortController,o=window.fetch(t,Object.assign({},n,{signal:r.signal})),i=setTimeout((function(){r.abort()}),e);return o.finally((function(){clearTimeout(i)}))}return function(t,e,n){var r=new Promise((function(e,r){setTimeout((function(){r(new Error(n||"Operation Timeout"))}),t)}));return Promise.race([r,e])}(e,window.fetch(t,n),"Request Timeout")},camelCase:function(t){if(t)return t.toLowerCase().split(" ").reduce((function(t,e,n){return t+=0===n?e:function(t){var e=t[0];return e<"\ud800"||e>"\udfff"?t[0].toUpperCase()+t.slice(1):t.slice(0,2).toUpperCase()+t.slice(2)}(e)}),"")},isLocalStorageAccessible:function(){try{return localStorage.setItem("__td__","__td__"),localStorage.removeItem("__td__"),!0}catch(t){return!1}},adlHeaders:{"Content-Type":"application/vnd.treasuredata.v1+json",Accept:"application/vnd.treasuredata.v1+json"},globalIdAdlHeaders:{"Content-Type":"application/vnd.treasuredata.v1.js+json",Accept:"application/vnd.treasuredata.v1.js+json"}}},function(t,e){t.exports=function(t){return!!t&&"object"==typeof t}},function(t,e,n){var r=n(14),o=n(11),i=n(4),s=Object.prototype.toString,a=r(Array,"isArray")||function(t){return i(t)&&o(t.length)&&"[object Array]"==s.call(t)};t.exports=a},function(t,e){var n=function(t){try{return encodeURIComponent(t)}catch(t){console.error("error encode %o")}return null},r=function(t){try{return decodeURIComponent(t)}catch(t){console.error("error decode %o")}return null},o={getItem:function(t){return t&&r(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+function(t){return n(t).replace(/[\-\.\+\*]/g,"\\$&")}(t)+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null},setItem:function(t,e,r,o,i,s,a){if(!t||/^(?:expires|max\-age|path|domain|secure)$/i.test(t))return!1;var c="";if(r)switch(r.constructor){case Number:c=r===1/0?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+r;break;case String:c="; expires="+r;break;case Date:c="; expires="+r.toUTCString()}var u="";return a&&"NONE"===a.toUpperCase()?u="; Secure; SameSite="+a:(s&&(u+="; Secure"),a&&(u+="; SameSite="+a)),document.cookie=[n(t),"=",n(e),c,i?"; domain="+i:"",o?"; path="+o:"",u].join(""),!0},removeItem:function(t,e,r){return!!this.hasItem(t)&&(document.cookie=[n(t),"=; expires=Thu, 01 Jan 1970 00:00:00 GMT",r?"; domain="+r:"",e?"; path="+e:""].join(""),!0)},hasItem:function(t){return!!t&&new RegExp("(?:^|;\\s*)"+n(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie)},keys:function(){var t=document.cookie.replace(/((?:^|\s*;)[^=]+)(?=;|$)|^\s*|\s*(?:=[^;]*)?(?:\1|$)/g,"").split(/\s*(?:=[^;]*)?;\s*/);return t=t.map((function(t){return r(t)}))}};t.exports=o},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){var r=n(4),o=Object.prototype.toString;t.exports=function(t){return"string"==typeof t||r(t)&&"[object String]"==o.call(t)}},function(t,e,n){var r=n(14),o=n(10),i=n(1),s=n(40),a=n(22),c=r(Object,"keys"),u=c?function(t){var e=null==t?void 0:t.constructor;return"function"==typeof e&&e.prototype===t||("function"==typeof t?a.enumPrototypes:o(t))?s(t):i(t)?c(t):[]}:s;t.exports=u},function(t,e,n){var r=n(27),o=n(11);t.exports=function(t){return null!=t&&o(r(t))}},function(t,e){t.exports=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}},function(t,e,n){var r=n(43);t.exports=function(t,e,n){if("function"!=typeof t)return r;if(void 0===e)return t;switch(n){case 1:return function(n){return t.call(e,n)};case 3:return function(n,r,o){return t.call(e,n,r,o)};case 4:return function(n,r,o,i){return t.call(e,n,r,o,i)};case 5:return function(n,r,o,i,s){return t.call(e,n,r,o,i,s)}}return function(){return t.apply(e,arguments)}}},function(t,e,n){var r=n(1),o=n(8),i=n(22);t.exports=function(t){if(i.unindexedChars&&o(t)){for(var e=-1,n=t.length,s=Object(t);++e0,S=l.enumErrorProps&&(t===p||t instanceof Error),j=l.enumPrototypes&&s(t);++r=200&&r<300||304===r?e(function(t){var e;try{e=JSON.parse(t)}catch(t){e={}}return e}(t.responseText)):n(new Error("Internal XMLHttpRequest error"))},t.onerror=n}function h(t,e,n){var r,o=(n=n||{}).headers||{},i=new XMLHttpRequest;for(r in i.open(t,e),i.withCredentials=Boolean(l(n)),o=c(n.headers,f(n)))o.hasOwnProperty(r)&&i.setRequestHeader(r,o[r]);return i}t.exports={post:function(t,e,n){return u()?d(t,e,n):new Promise((function(r,o){var i=h("POST",t,n);p(i,r,o),i.send(JSON.stringify(e))}))},get:function(t,e){if(e=e||{},u())return function(t,e){var n=(e=e||{}).headers||{},r=e.method||"GET";return fetch(t,{method:r,headers:c(n,f(e)),credentials:l(e)}).then((function(t){if(!t.ok)throw Error(t.statusText);return t.text()})).then((function(t){return t?JSON.parse(t):{}}))}(t,e);var n=e.method||"GET";return new Promise((function(r,o){var i=h(n,t,e);p(i,r,o),i.send(null)}))},postWithTimeout:function(t,e,n,r){if(window.AbortController){var o=new window.AbortController,i=c(r.headers,f(r));r.headers=i;var s=window.fetch(t,Object.assign({},r,{signal:o.signal})),a=setTimeout((function(){o.abort()}),n);return s.finally((function(){clearTimeout(a)}))}return function(t,e,n){var r=new Promise((function(e,r){setTimeout((function(){r(new Error(n||"Operation Timeout"))}),t)}));return Promise.race([r,e])}(n,d(t,e,r),"Request Timeout")}}},function(t,e){t.exports={GLOBAL:"Treasure",VERSION:"3.1.1",HOST:"in.treasuredata.com",DATABASE:"",PATHNAME:"/js/v3/event/"}},function(t,e){t.exports=function(t,e){for(var n=-1,r=t.length;++n-1&&t%1==0&&t=0;r--)n.push(e.slice(r).join("."));return n}(t.domain),l=f.length,d=0;if(n){if(r.getItem(e)===n)return;for(;d2?n[s-2]:void 0,c=s>2?n[2]:void 0,u=s>1?n[s-1]:void 0;for("function"==typeof a?(a=r(a,u,5),s-=2):s-=(a="function"==typeof u?u:void 0)?1:0,c&&o(n[0],n[1],c)&&(a=s<3?void 0:a,s=1);++i=200?i(e):null,l=e.length;f&&(c=o,u=!1,e=f);t:for(;++a=1;e--){var n=t.slice(e).join("."),r="_td_domain_"+n;if(s.setItem(r,n,3600,"/",n),s.getItem(r)===n)return n}return document.location.hostname},sscServer:function(t){return["ssc",t].join(".")},storeConsentByLocalStorage:!1},e.configure=function(t){return this.client=r.assign({globals:{}},e.DEFAULT_CONFIG,t,{requestType:"fetch"}),function(t){o(r.isObject(t),"Check out our JavaScript SDK Usage Guide: https://github.com/treasure-data/td-js-sdk#api"),o(r.isString(t.writeKey),"Must provide a writeKey"),o(r.isString(t.database),"Must provide a database"),o(/^[a-z0-9_]{3,255}$/.test(t.database),"Database must be between 3 and 255 characters and must consist only of lower case letters, numbers, and _")}(this.client),this.client.useNewJavaScriptEndpoint&&(this.client.pathname="/"),this.client.endpoint||(this.client.endpoint="https://"+this.client.host+this.client.pathname),this},e.set=function(t,e,n){return r.isObject(t)&&(e=t,t="$global"),this.client.globals[t]=this.client.globals[t]||{},r.isObject(e)?r.assign(this.client.globals[t],e):this.client.globals[t][e]=n,this},e.get=function(t,e){return t=t||"$global",this.client.globals[t]=this.client.globals[t]||{},e?this.client.globals[t][e]:this.client.globals[t]},e.isGlobalIdEnabled=function(){return"td_global_id"===this.get(null,"td_global_id")}},function(t,e,n){ /*! * domready (c) Dustin Diaz 2012 - License MIT */ -t.exports=function(t){var e,n=[],r=document,o=r.documentElement,i=o.doScroll,s=(i?/^loaded|^c/:/^loaded|c/).test(r.readyState);function a(t){for(s=1;t=n.shift();)t()}return r.addEventListener&&r.addEventListener("DOMContentLoaded",e=function(){r.removeEventListener("DOMContentLoaded",e,!1),a()},!1),i&&r.attachEvent("onreadystatechange",e=function(){/^c/.test(r.readyState)&&(r.detachEvent("onreadystatechange",e),a())}),t=i?function(e){self!=top?s?e():n.push(e):function(){try{o.doScroll("left")}catch(n){return setTimeout((function(){t(e)}),50)}e()}()}:function(t){s?t():n.push(t)}}()},function(t,e,n){var r=n(2),o=n(78),i=n(0).assign,s=n(3).disposable;function a(t,e){return e}t.exports={configure:function(){this._clickTrackingInstalled=!1},trackClicks:function(t){if(!this._clickTrackingInstalled){var e=this,n=i({element:r.document,extendClickData:a,ignoreAttribute:"td-ignore",tableName:"clicks"},t),c=o.createTreeHasIgnoreAttribute(n.ignoreAttribute),u=o.addEventListener(n.element,"click",(function(t){var r=o.findElement(o.getEventTarget(t));if(r&&!c(r)){var i=o.getElementData(r),s=n.extendClickData(t,i);s&&e.trackEvent(n.tableName,s)}}));return e._clickTrackingInstalled=!0,s((function(){u(),e._clickTrackingInstalled=!1}))}}}},function(t,e,n){var r=n(0).forEach,o=n(0).isString,i=n(3).disposable;function s(t){for(var e,n=[],r=0,o=0,i=" > ".length;t&&r++<5&&!("html"===(e=a(t))||r>1&&o+n.length*i+e.length>=80);)n.push(e),o+=e.length,t=t.parentNode;return n.reverse().join(" > ")}function a(t){var e,n,r,i,s,a=[];if(!t||!t.tagName)return"";if(a.push(t.tagName.toLowerCase()),t.id&&a.push("#"+t.id),(e=t.className)&&o(e))for(n=e.split(" "),s=0;s ".length;t&&r++<5&&!("html"===(e=a(t))||r>1&&o+n.length*i+e.length>=80);)n.push(e),o+=e.length,t=t.parentNode;return n.reverse().join(" > ")}function a(t){var e,n,r,i,s,a=[];if(!t||!t.tagName)return"";if(a.push(t.tagName.toLowerCase()),t.id&&a.push("#"+t.id),(e=t.className)&&o(e))for(n=e.split(" "),s=0;s1)for(var n=1;n1)for(var n=1;n