diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c4f6419..885a3033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 3.1.3 (2023-06-15) +* `postWithTimeout` should be requested with body +* only enable `td_global_id` when in signed mode + + ## 3.1.2 (2022-10-05) * Default values for backward compatibility diff --git a/README.md b/README.md index 48280d7c..b647501f 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Install td-js-sdk on your page by copying the appropriate JavaScript snippet bel ```html ``` diff --git a/dist/td.js b/dist/td.js index 2b6b2459..e3b54012 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.2',\n HOST: 'in.treasuredata.com',\n DATABASE: '',\n PATHNAME: '/js/v3/event/'\n};\n\n//# sourceURL=webpack:///./lib/config.js?"); +eval("module.exports = {\n GLOBAL: 'Treasure',\n VERSION: '3.1.3',\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.2',\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 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?"); +eval("/*\n * Treasure Configurator\n */\n\n// Modules\nvar _ = __webpack_require__(/*! ./utils/lodash */ \"./lib/utils/lodash.js\");\nvar invariant = __webpack_require__(/*! ./utils/misc */ \"./lib/utils/misc.js\").invariant;\nvar config = __webpack_require__(/*! ./config */ \"./lib/config.js\");\nvar cookie = __webpack_require__(/*! ./vendor/js-cookies */ \"./lib/vendor/js-cookies.js\");\n\n// Helpers\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}\nvar defaultSSCCookieDomain = function defaultSSCCookieDomain() {\n var domainChunks = document.location.hostname.split('.');\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 cookie.setItem(name, domain, 3600, '/', domain);\n if (cookie.getItem(name) === domain) {\n return domain;\n }\n }\n return document.location.hostname;\n};\n\n// Default config for library values\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/*\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 * */\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 if (this.client.useNewJavaScriptEndpoint) {\n this.client.pathname = '/';\n }\n if (!this.client.endpoint) {\n this.client.endpoint = 'https://' + this.client.host + this.client.pathname;\n }\n return this;\n};\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 */\nexports.set = function set(table, property, value) {\n if (_.isObject(table)) {\n property = table;\n table = '$global';\n }\n this.client.globals[table] = this.client.globals[table] || {};\n if (_.isObject(property)) {\n _.assign(this.client.globals[table], property);\n } else {\n this.client.globals[table][property] = value;\n }\n return this;\n};\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 */\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};\nexports.isGlobalIdEnabled = function () {\n return this.get(null, 'td_global_id') === 'td_global_id';\n};\n\n//# sourceURL=webpack:///./lib/configurator.js?"); /***/ }), @@ -115,7 +115,7 @@ eval("/*\n * Treasure Configurator\n */\n// Modules\nvar _ = __webpack_require__ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -eval("/*\n * Treasure Index\n */\nvar Treasure = __webpack_require__(/*! ./treasure.js */ \"./lib/treasure.js\");\n\nvar window = __webpack_require__(/*! global/window */ \"./node_modules/global/window.js\");\n\nvar GLOBAL = __webpack_require__(/*! ./config */ \"./lib/config.js\").GLOBAL; // Load all cached clients\n\n\n__webpack_require__(/*! ./loadClients */ \"./lib/loadClients.js\")(Treasure, GLOBAL); // Expose the library on the window\n\n\nwindow[GLOBAL] = Treasure;\n\n//# sourceURL=webpack:///./lib/index.js?"); +eval("/*\n * Treasure Index\n */\nvar Treasure = __webpack_require__(/*! ./treasure.js */ \"./lib/treasure.js\");\nvar window = __webpack_require__(/*! global/window */ \"./node_modules/global/window.js\");\nvar GLOBAL = __webpack_require__(/*! ./config */ \"./lib/config.js\").GLOBAL;\n\n// Load all cached clients\n__webpack_require__(/*! ./loadClients */ \"./lib/loadClients.js\")(Treasure, GLOBAL);\n\n// Expose the library on the window\nwindow[GLOBAL] = Treasure;\n\n//# sourceURL=webpack:///./lib/index.js?"); /***/ }), @@ -126,7 +126,7 @@ eval("/*\n * Treasure Index\n */\nvar Treasure = __webpack_require__(/*! ./treas /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -eval("/*\n * Treasure Client Loader\n */\n// Modules\nvar _ = __webpack_require__(/*! ./utils/lodash */ \"./lib/utils/lodash.js\");\n\nvar window = __webpack_require__(/*! global/window */ \"./node_modules/global/window.js\"); // Helpers\n\n\nfunction applyToClient(client, method) {\n var _method = '_' + method;\n\n if (client[_method]) {\n var arr = client[_method] || [];\n\n while (arr.length) {\n client[method].apply(client, arr.shift());\n }\n\n delete client[_method];\n }\n} // Constants\n\n\nvar TREASURE_KEYS = ['init', 'set', 'blockEvents', 'unblockEvents', 'setSignedMode', 'setAnonymousMode', 'resetUUID', 'addRecord', 'fetchGlobalID', 'trackPageview', 'trackEvent', 'trackClicks', 'fetchUserSegments', 'fetchServerCookie', 'ready'];\n/*\n * Load clients\n */\n\nmodule.exports = function loadClients(Treasure, name) {\n if (_.isObject(window[name])) {\n var snippet = window[name];\n var clients = snippet.clients; // Copy over Treasure.prototype functions over to snippet's prototype\n // This allows already-instanciated clients to work\n\n _.forIn(Treasure.prototype, function (value, key) {\n snippet.prototype[key] = value;\n }); // Iterate over each client instance\n\n\n _.forEach(clients, function (client) {\n // Call each key and with any stored values\n _.forEach(TREASURE_KEYS, function (value) {\n applyToClient(client, value);\n });\n });\n }\n};\n\n//# sourceURL=webpack:///./lib/loadClients.js?"); +eval("/*\n * Treasure Client Loader\n */\n\n// Modules\nvar _ = __webpack_require__(/*! ./utils/lodash */ \"./lib/utils/lodash.js\");\nvar window = __webpack_require__(/*! global/window */ \"./node_modules/global/window.js\");\n\n// Helpers\nfunction applyToClient(client, method) {\n var _method = '_' + method;\n if (client[_method]) {\n var arr = client[_method] || [];\n while (arr.length) {\n client[method].apply(client, arr.shift());\n }\n delete client[_method];\n }\n}\n\n// Constants\nvar TREASURE_KEYS = ['init', 'set', 'blockEvents', 'unblockEvents', 'setSignedMode', 'setAnonymousMode', 'resetUUID', 'addRecord', 'fetchGlobalID', 'trackPageview', 'trackEvent', 'trackClicks', 'fetchUserSegments', 'fetchServerCookie', 'ready'];\n\n/*\n * Load clients\n */\nmodule.exports = function loadClients(Treasure, name) {\n if (_.isObject(window[name])) {\n var snippet = window[name];\n var clients = snippet.clients;\n\n // Copy over Treasure.prototype functions over to snippet's prototype\n // This allows already-instanciated clients to work\n _.forIn(Treasure.prototype, function (value, key) {\n snippet.prototype[key] = value;\n });\n\n // Iterate over each client instance\n _.forEach(clients, function (client) {\n // Call each key and with any stored values\n _.forEach(TREASURE_KEYS, function (value) {\n applyToClient(client, value);\n });\n });\n }\n};\n\n//# sourceURL=webpack:///./lib/loadClients.js?"); /***/ }), @@ -137,7 +137,7 @@ eval("/*\n * Treasure Client Loader\n */\n// Modules\nvar _ = __webpack_require_ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -eval("var window = __webpack_require__(/*! global/window */ \"./node_modules/global/window.js\");\n\nvar elementUtils = __webpack_require__(/*! ../utils/element */ \"./lib/utils/element.js\");\n\nvar assign = __webpack_require__(/*! ../utils/lodash */ \"./lib/utils/lodash.js\").assign;\n\nvar disposable = __webpack_require__(/*! ../utils/misc */ \"./lib/utils/misc.js\").disposable;\n\nfunction defaultExtendClickData(event, data) {\n return data;\n}\n\nfunction configure() {\n this._clickTrackingInstalled = false;\n}\n/**\n * Setup an event listener to automatically log clicks.\n * The event will be hooked only follows\n * - `role=button` or `role=link`\n * - ``\n * - `