diff --git a/README.md b/README.md index e1ec6b701d..fec45c80aa 100644 --- a/README.md +++ b/README.md @@ -49,37 +49,7 @@ The JavaScript SDK lets you track customer event data from your website and send ### Using CDN -To integrate the JavaScript SDK with your website, place the following code snippet in the `` section of your website. - -```javascript - -``` - -
- -> The above snippet lets you integrate the SDK with your website and load it asynchronously to avoid impacting the performance of your webpages. +See [CDN installation](https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/quickstart/#using-cdn) for detailed steps. To load SDK script on to your page synchronously, see the [**JavaScript SDK documentation**](https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/installation/#synchronous-loading). diff --git a/package-lock.json b/package-lock.json index 59c99fed65..a8272e48ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@rudderstack/analytics-js-monorepo", - "version": "3.30.0", + "version": "3.31.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@rudderstack/analytics-js-monorepo", - "version": "3.30.0", + "version": "3.31.0", "hasInstallScript": true, "license": "Elastic-2.0", "workspaces": [ @@ -24225,7 +24225,7 @@ }, "packages/analytics-js": { "name": "@rudderstack/analytics-js", - "version": "3.7.8", + "version": "3.7.9", "license": "Elastic-2.0", "dependencies": { "@preact/signals-core": "1.6.1", @@ -24239,7 +24239,7 @@ }, "packages/analytics-js-common": { "name": "@rudderstack/analytics-js-common", - "version": "3.8.1", + "version": "3.9.0", "license": "Elastic-2.0", "dependencies": { "@lukeed/uuid": "2.0.1", @@ -24256,7 +24256,7 @@ }, "packages/analytics-js-cookies": { "name": "@rudderstack/analytics-js-cookies", - "version": "0.3.5", + "version": "0.3.6", "license": "Elastic-2.0", "dependencies": { "@rudderstack/analytics-js-common": "*" @@ -24265,7 +24265,7 @@ }, "packages/analytics-js-integrations": { "name": "@rudderstack/analytics-js-integrations", - "version": "3.7.0", + "version": "3.8.0", "license": "Elastic-2.0", "dependencies": { "@lukeed/uuid": "2.0.1", @@ -24285,7 +24285,7 @@ }, "packages/analytics-js-plugins": { "name": "@rudderstack/analytics-js-plugins", - "version": "3.4.8", + "version": "3.4.9", "license": "Elastic-2.0", "dependencies": { "@rudderstack/analytics-js-common": "*", @@ -24299,7 +24299,7 @@ }, "packages/analytics-js-service-worker": { "name": "@rudderstack/analytics-js-service-worker", - "version": "3.1.8", + "version": "3.1.9", "license": "Elastic-2.0", "dependencies": { "@lukeed/uuid": "2.0.1", @@ -24329,7 +24329,7 @@ }, "packages/analytics-v1.1": { "name": "rudder-sdk-js", - "version": "2.48.15", + "version": "2.48.16", "license": "Elastic-2.0", "dependencies": { "@rudderstack/analytics-js-common": "*" @@ -24338,7 +24338,7 @@ }, "packages/loading-scripts": { "name": "@rudderstack/analytics-js-loading-scripts", - "version": "3.0.25", + "version": "3.0.26", "license": "Elastic-2.0", "dependencies": { "@rudderstack/analytics-js": "*" @@ -24347,7 +24347,7 @@ }, "packages/sanity-suite": { "name": "@rudderstack/analytics-js-sanity-suite", - "version": "3.1.15", + "version": "3.1.16", "license": "Elastic-2.0", "dependencies": { "@rudderstack/analytics-js": "*", diff --git a/package.json b/package.json index dbb03f69cd..f3173c401d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rudderstack/analytics-js-monorepo", - "version": "3.30.0", + "version": "3.31.0", "private": true, "description": "Monorepo for RudderStack Analytics JS SDK", "workspaces": [ diff --git a/packages/analytics-js-common/CHANGELOG.md b/packages/analytics-js-common/CHANGELOG.md index 0c26ed0629..eedc929372 100644 --- a/packages/analytics-js-common/CHANGELOG.md +++ b/packages/analytics-js-common/CHANGELOG.md @@ -2,6 +2,13 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver). +## [3.9.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-common@3.8.1...@rudderstack/analytics-js-common@3.9.0) (2024-08-16) + + +### Features + +* onboarded XPixel Integration ([#1783](https://github.com/rudderlabs/rudder-sdk-js/issues/1783)) ([cf9b8cc](https://github.com/rudderlabs/rudder-sdk-js/commit/cf9b8cc41de341be781fae3108e4a07f2b553dda)) + ## [3.8.1](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-common@3.8.0...@rudderstack/analytics-js-common@3.8.1) (2024-08-02) diff --git a/packages/analytics-js-common/CHANGELOG_LATEST.md b/packages/analytics-js-common/CHANGELOG_LATEST.md index abaec440fa..ad225609d8 100644 --- a/packages/analytics-js-common/CHANGELOG_LATEST.md +++ b/packages/analytics-js-common/CHANGELOG_LATEST.md @@ -1,8 +1,7 @@ -## [3.8.1](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-common@3.8.0...@rudderstack/analytics-js-common@3.8.1) (2024-08-02) +## [3.9.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-common@3.8.1...@rudderstack/analytics-js-common@3.9.0) (2024-08-16) -### Bug Fixes +### Features -* error filtering of non-errors ([#1811](https://github.com/rudderlabs/rudder-sdk-js/issues/1811)) ([7b83e16](https://github.com/rudderlabs/rudder-sdk-js/commit/7b83e1661b1e0ce0b6b5ae45d3a2e08db97ddcb3)) -* npm sanity suites ([#1810](https://github.com/rudderlabs/rudder-sdk-js/issues/1810)) ([22e43da](https://github.com/rudderlabs/rudder-sdk-js/commit/22e43da01f750a5cb23a2fce50de3744c54a197e)) +* onboarded XPixel Integration ([#1783](https://github.com/rudderlabs/rudder-sdk-js/issues/1783)) ([cf9b8cc](https://github.com/rudderlabs/rudder-sdk-js/commit/cf9b8cc41de341be781fae3108e4a07f2b553dda)) diff --git a/packages/analytics-js-common/package.json b/packages/analytics-js-common/package.json index 71fabac797..5ccae234a7 100644 --- a/packages/analytics-js-common/package.json +++ b/packages/analytics-js-common/package.json @@ -1,6 +1,6 @@ { "name": "@rudderstack/analytics-js-common", - "version": "3.8.1", + "version": "3.9.0", "private": true, "description": "RudderStack JavaScript SDK common code", "module": "dist/npm/index.js", diff --git a/packages/analytics-js-common/project.json b/packages/analytics-js-common/project.json index 9316f12566..c2f325aecb 100644 --- a/packages/analytics-js-common/project.json +++ b/packages/analytics-js-common/project.json @@ -51,9 +51,9 @@ "github": { "executor": "@jscutlery/semver:github", "options": { - "tag": "@rudderstack/analytics-js-common@3.8.1", - "title": "@rudderstack/analytics-js-common@3.8.1", - "discussion-category": "@rudderstack/analytics-js-common@3.8.1", + "tag": "@rudderstack/analytics-js-common@3.9.0", + "title": "@rudderstack/analytics-js-common@3.9.0", + "discussion-category": "@rudderstack/analytics-js-common@3.9.0", "notesFile": "./packages/analytics-js-common/CHANGELOG_LATEST.md" } } diff --git a/packages/analytics-js-common/src/constants/integrations/XPixel/constants.js b/packages/analytics-js-common/src/constants/integrations/XPixel/constants.js new file mode 100644 index 0000000000..6f76bf94c1 --- /dev/null +++ b/packages/analytics-js-common/src/constants/integrations/XPixel/constants.js @@ -0,0 +1,61 @@ +const DIR_NAME = 'XPixel'; +const NAME = 'XPIXEL'; +const DISPLAY_NAME = 'XPixel'; + +const DISPLAY_NAME_TO_DIR_NAME_MAP = { [DISPLAY_NAME]: DIR_NAME }; +const CNameMapping = { + [NAME]: NAME, + XPIXEL: NAME, + XPixel: NAME, + Xpixel: NAME, + xpixel: NAME, + xPixel: NAME, +}; + +const trackPropertyMapping = [ + { + destKey: 'event_id', + sourceKeys: ['properties.eventId', 'properties.event_id', 'messageId'], + }, + { + destKey: 'status', + sourceKeys: 'properties.status', + }, + { + destKey: 'currency', + sourceKeys: 'properties.currency', + }, + { + destKey: 'value', + sourceKeys: 'properties.value', + }, + { + destKey: 'search_string', + sourceKeys: ['properties.search_string', 'properties.searchString'], + }, + { + destKey: 'description', + sourceKeys: 'properties.description', + }, + { + destKey: 'conversion_id', + sourceKeys: ['properties.conversion_id', 'properties.conversionId'], + }, + { + destKey: 'twclid', + sourceKeys: 'properties.twclid', + }, + { + destKey: 'contents', + sourceKeys: 'properties.contents', + }, +]; + +export { + NAME, + CNameMapping, + DISPLAY_NAME_TO_DIR_NAME_MAP, + DISPLAY_NAME, + DIR_NAME, + trackPropertyMapping, +}; diff --git a/packages/analytics-js-common/src/constants/integrations/client_server_name.js b/packages/analytics-js-common/src/constants/integrations/client_server_name.js index 6724c8e068..ecfd1e6a87 100644 --- a/packages/analytics-js-common/src/constants/integrations/client_server_name.js +++ b/packages/analytics-js-common/src/constants/integrations/client_server_name.js @@ -78,6 +78,7 @@ const clientToServerNames = { SPOTIFYPIXEL: 'Spotify Pixel', COMMANDBAR: 'CommandBar', NINETAILED: 'Ninetailed', + XPIXEL: 'XPixel', }; export { clientToServerNames }; diff --git a/packages/analytics-js-common/src/constants/integrations/config_to_integration_names.js b/packages/analytics-js-common/src/constants/integrations/config_to_integration_names.js index d713afce41..8c87a975f9 100644 --- a/packages/analytics-js-common/src/constants/integrations/config_to_integration_names.js +++ b/packages/analytics-js-common/src/constants/integrations/config_to_integration_names.js @@ -79,6 +79,7 @@ const configToIntNames = { SPOTIFYPIXEL: 'SpotifyPixel', COMMANDBAR: 'CommandBar', NINETAILED: 'Ninetailed', + XPIXEL: 'XPixel', }; export { configToIntNames }; diff --git a/packages/analytics-js-common/src/constants/integrations/integration_cname.js b/packages/analytics-js-common/src/constants/integrations/integration_cname.js index 247171b693..434f688faa 100644 --- a/packages/analytics-js-common/src/constants/integrations/integration_cname.js +++ b/packages/analytics-js-common/src/constants/integrations/integration_cname.js @@ -77,7 +77,7 @@ import { CNameMapping as Sprig } from './Sprig/constants'; import { CNameMapping as SpotifyPixel } from './SpotifyPixel/constants'; import { CNameMapping as CommandBar } from './CommandBar/constants'; import { CNameMapping as Ninetailed } from './Ninetailed/constants'; - +import { CNameMapping as XPixel } from './XPixel/constants'; // for sdk side native integration identification // add a mapping from common names to index.js exported key names as identified by Rudder const commonNames = { @@ -161,6 +161,7 @@ const commonNames = { ...ActiveCampaign, ...Sprig, ...SpotifyPixel, + ...XPixel, }; export { commonNames }; diff --git a/packages/analytics-js-cookies/CHANGELOG.md b/packages/analytics-js-cookies/CHANGELOG.md index 6253ffa077..0840cf5d27 100644 --- a/packages/analytics-js-cookies/CHANGELOG.md +++ b/packages/analytics-js-cookies/CHANGELOG.md @@ -2,6 +2,11 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver). +## [0.3.6](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-cookies@0.3.5...@rudderstack/analytics-js-cookies@0.3.6) (2024-08-16) + +### Dependency Updates + +* `@rudderstack/analytics-js-common` updated to version `3.9.0` ## [0.3.5](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-cookies@0.3.4...@rudderstack/analytics-js-cookies@0.3.5) (2024-08-02) ### Dependency Updates diff --git a/packages/analytics-js-cookies/CHANGELOG_LATEST.md b/packages/analytics-js-cookies/CHANGELOG_LATEST.md index 92324862b1..574b5cb24c 100644 --- a/packages/analytics-js-cookies/CHANGELOG_LATEST.md +++ b/packages/analytics-js-cookies/CHANGELOG_LATEST.md @@ -1,5 +1,5 @@ -## [0.3.5](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-cookies@0.3.4...@rudderstack/analytics-js-cookies@0.3.5) (2024-08-02) +## [0.3.6](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-cookies@0.3.5...@rudderstack/analytics-js-cookies@0.3.6) (2024-08-16) ### Dependency Updates -* `@rudderstack/analytics-js-common` updated to version `3.8.1` +* `@rudderstack/analytics-js-common` updated to version `3.9.0` diff --git a/packages/analytics-js-cookies/package.json b/packages/analytics-js-cookies/package.json index 73197e3055..46eb374dd5 100644 --- a/packages/analytics-js-cookies/package.json +++ b/packages/analytics-js-cookies/package.json @@ -1,6 +1,6 @@ { "name": "@rudderstack/analytics-js-cookies", - "version": "0.3.5", + "version": "0.3.6", "description": "RudderStack JavaScript SDK Cookies Utilities", "main": "dist/npm/modern/cjs/index.cjs", "module": "dist/npm/modern/esm/index.mjs", diff --git a/packages/analytics-js-cookies/project.json b/packages/analytics-js-cookies/project.json index 4630b42a97..2540a2f118 100644 --- a/packages/analytics-js-cookies/project.json +++ b/packages/analytics-js-cookies/project.json @@ -51,9 +51,9 @@ "github": { "executor": "@jscutlery/semver:github", "options": { - "tag": "@rudderstack/analytics-js-cookies@0.3.5", - "title": "@rudderstack/analytics-js-cookies@0.3.5", - "discussion-category": "@rudderstack/analytics-js-cookies@0.3.5", + "tag": "@rudderstack/analytics-js-cookies@0.3.6", + "title": "@rudderstack/analytics-js-cookies@0.3.6", + "discussion-category": "@rudderstack/analytics-js-cookies@0.3.6", "notesFile": "./packages/analytics-js-cookies/CHANGELOG_LATEST.md" } } diff --git a/packages/analytics-js-integrations/CHANGELOG.md b/packages/analytics-js-integrations/CHANGELOG.md index e7fccf75b7..078408a093 100644 --- a/packages/analytics-js-integrations/CHANGELOG.md +++ b/packages/analytics-js-integrations/CHANGELOG.md @@ -2,6 +2,16 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver). +## [3.8.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-integrations@3.7.0...@rudderstack/analytics-js-integrations@3.8.0) (2024-08-16) + +### Dependency Updates + +* `@rudderstack/analytics-js-common` updated to version `3.9.0` + +### Features + +* onboarded XPixel Integration ([#1783](https://github.com/rudderlabs/rudder-sdk-js/issues/1783)) ([cf9b8cc](https://github.com/rudderlabs/rudder-sdk-js/commit/cf9b8cc41de341be781fae3108e4a07f2b553dda)) + ## [3.7.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-integrations@3.6.0...@rudderstack/analytics-js-integrations@3.7.0) (2024-08-02) ### Dependency Updates diff --git a/packages/analytics-js-integrations/CHANGELOG_LATEST.md b/packages/analytics-js-integrations/CHANGELOG_LATEST.md index 601bdbb838..b3d295f33c 100644 --- a/packages/analytics-js-integrations/CHANGELOG_LATEST.md +++ b/packages/analytics-js-integrations/CHANGELOG_LATEST.md @@ -1,15 +1,10 @@ -## [3.7.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-integrations@3.6.0...@rudderstack/analytics-js-integrations@3.7.0) (2024-08-02) +## [3.8.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-integrations@3.7.0...@rudderstack/analytics-js-integrations@3.8.0) (2024-08-16) ### Dependency Updates -* `@rudderstack/analytics-js-common` updated to version `3.8.1` +* `@rudderstack/analytics-js-common` updated to version `3.9.0` ### Features -* criteo add support for multiple hash methods ([#1812](https://github.com/rudderlabs/rudder-sdk-js/issues/1812)) ([23a0e37](https://github.com/rudderlabs/rudder-sdk-js/commit/23a0e37d274647cb3e2505694522080d7f5b98f3)) - - -### Bug Fixes - -* npm sanity suites ([#1810](https://github.com/rudderlabs/rudder-sdk-js/issues/1810)) ([22e43da](https://github.com/rudderlabs/rudder-sdk-js/commit/22e43da01f750a5cb23a2fce50de3744c54a197e)) +* onboarded XPixel Integration ([#1783](https://github.com/rudderlabs/rudder-sdk-js/issues/1783)) ([cf9b8cc](https://github.com/rudderlabs/rudder-sdk-js/commit/cf9b8cc41de341be781fae3108e4a07f2b553dda)) diff --git a/packages/analytics-js-integrations/__tests__/integrations/XPixel/browser.test.js b/packages/analytics-js-integrations/__tests__/integrations/XPixel/browser.test.js new file mode 100644 index 0000000000..413bca31b4 --- /dev/null +++ b/packages/analytics-js-integrations/__tests__/integrations/XPixel/browser.test.js @@ -0,0 +1,214 @@ +import { XPixel } from '../../../src/integrations/XPixel'; + +afterAll(() => { + jest.restoreAllMocks(); +}); +const destinationInfo = { + areTransformationsConnected: false, + destinationId: 'sample-destination-id', +}; + +const basicConfig = { + pixelId: '12567839', + eventsMapping: [ + { from: 'Sign Up', to: '123' }, + { from: 'Custom', to: '987' }, + { from: 'Page View', to: '456' }, + { from: 'Page View', to: '467' }, + { from: 'product_added', to: '789' }, + ], +}; + +describe('XPixel init tests', () => { + beforeAll(() => { + // Add a dummy script as it is required by the init script + const scriptElement = document.createElement('script'); + scriptElement.type = 'text/javascript'; + scriptElement.id = 'dummyScript'; + const headElements = document.getElementsByTagName('head'); + headElements[0].insertBefore(scriptElement, headElements[0].firstChild); + }); + + let xPixel; + + test('Testing init call of XPixel', () => { + xPixel = new XPixel(basicConfig, { logLevel: 'debug' }, destinationInfo); + xPixel.init(); + expect(typeof window.twq).toBe('function'); + const isReady = xPixel.isReady(); + expect(isReady).toBeTruthy(); + }); +}); + +describe('xPixel page', () => { + let xPixel; + beforeEach(() => { + xPixel = new XPixel(basicConfig, { logLevel: 'debug' }); + xPixel.init(); + window.twq = jest.fn(); + }); + + test('send pageview', () => { + xPixel.page({ + message: { + context: {}, + properties: { + category: 'test cat', + path: '/test', + url: 'http://localhost', + referrer: '', + title: 'test page', + testDimension: 'abc', + value: 35.0, + currency: 'GBP', + }, + }, + }); + expect(window.twq.mock.calls[0]).toEqual(['event', '456', { currency: 'GBP', value: 35 }]); + expect(window.twq.mock.calls[1]).toEqual(['event', '467', { currency: 'GBP', value: 35 }]); + }); +}); + +describe('XPixel Track event', () => { + let xPixel; + beforeEach(() => {}); + test('Testing Track Simple Event with contents build properties.products', () => { + xPixel = new XPixel(basicConfig, { logLevel: 'DEBUG' }, destinationInfo); + xPixel.init(); + window.twq = jest.fn(); + xPixel.track({ + message: { + context: {}, + event: 'Custom', + properties: { + customProp: 'testProp', + order_id: 'transactionId', + value: 35.0, + coupon: 'APPARELSALE', + currency: 'GBP', + products: [ + { + customPropProd: 'testPropProd', + product_id: 'abc', + category: 'Merch', + name: 'Food', + brand: '', + variant: 'Extra topped', + price: 3.0, + quantity: 2, + currency: 'GBP', + position: 1, + value: 6.0, + typeOfProduct: 'Food', + }, + ], + }, + }, + }); + expect(window.twq.mock.calls[0]).toEqual([ + 'event', + '987', + { + currency: 'GBP', + value: 35, + contents: [ + { + content_type: 'product', + content_id: 'abc', + content_name: 'Food', + price: 3, + num_items: 2, + }, + ], + }, + ]); + }); + + test('Testing Track product_added with contents', () => { + xPixel = new XPixel(basicConfig, { logLevel: 'DEBUG' }); + xPixel.init(); + window.twq = jest.fn(); + xPixel.track({ + message: { + context: {}, + event: 'product_added', + properties: { + customProp: 'testProp', + event_id: 'purchaseId', + order_id: 'transactionId', + value: 35.0, + currency: 'GBP', + contents: { + content_type: 'product', + content_id: 'abc', + content_name: 'Food/Drink', + price: 3, + num_items: 2, + }, + }, + }, + }); + expect(window.twq.mock.calls[0]).toEqual([ + 'event', + '789', + { + currency: 'GBP', + value: 35, + event_id: 'purchaseId', + contents: [ + { + content_type: 'product', + content_id: 'abc', + content_name: 'Food/Drink', + price: 3, + num_items: 2, + }, + ], + }, + ]); + }); + + test('Test for empty properties', () => { + xPixel = new XPixel(basicConfig, { logLevel: 'DEBUG' }); + xPixel.init(); + window.twq.track = jest.fn(); + xPixel.track({ + message: { + type: 'track', + context: {}, + event: 'Sign Up', + properties: {}, + }, + }); + expect(window.twq.mock.calls[1]).toEqual(['event', '123', {}]); + }); + + test('Test for no Event name', () => { + xPixel = new XPixel(basicConfig, { logLevel: 'DEBUG' }); + xPixel.init(); + window.twq.track = jest.fn(); + xPixel.track({ + message: { + type: 'track', + context: {}, + properties: {}, + }, + }); + expect(window.twq).not.toHaveBeenCalledWith(); + }); + + test('Test for no Event Id for input event', () => { + xPixel = new XPixel(basicConfig, { logLevel: 'DEBUG' }); + xPixel.init(); + window.twq.track = jest.fn(); + xPixel.track({ + message: { + type: 'track', + context: {}, + event: 'addToCart', + properties: {}, + }, + }); + expect(window.twq).not.toHaveBeenCalledWith(); + }); +}); diff --git a/packages/analytics-js-integrations/package.json b/packages/analytics-js-integrations/package.json index 7e0167e445..ea4494253b 100644 --- a/packages/analytics-js-integrations/package.json +++ b/packages/analytics-js-integrations/package.json @@ -1,6 +1,6 @@ { "name": "@rudderstack/analytics-js-integrations", - "version": "3.7.0", + "version": "3.8.0", "private": true, "description": "RudderStack JavaScript SDK device mode integrations", "main": "dist/npm/modern/cjs/index.js", diff --git a/packages/analytics-js-integrations/project.json b/packages/analytics-js-integrations/project.json index e8888f008b..02bf4d5568 100644 --- a/packages/analytics-js-integrations/project.json +++ b/packages/analytics-js-integrations/project.json @@ -51,9 +51,9 @@ "github": { "executor": "@jscutlery/semver:github", "options": { - "tag": "@rudderstack/analytics-js-integrations@3.7.0", - "title": "@rudderstack/analytics-js-integrations@3.7.0", - "discussion-category": "@rudderstack/analytics-js-integrations@3.7.0", + "tag": "@rudderstack/analytics-js-integrations@3.8.0", + "title": "@rudderstack/analytics-js-integrations@3.8.0", + "discussion-category": "@rudderstack/analytics-js-integrations@3.8.0", "notesFile": "./packages/analytics-js-integrations/CHANGELOG_LATEST.md" } } diff --git a/packages/analytics-js-integrations/src/integrations/XPixel/browser.js b/packages/analytics-js-integrations/src/integrations/XPixel/browser.js new file mode 100644 index 0000000000..fac5ece2ab --- /dev/null +++ b/packages/analytics-js-integrations/src/integrations/XPixel/browser.js @@ -0,0 +1,57 @@ +/* eslint-disable class-methods-use-this */ +import { + NAME, + DISPLAY_NAME, +} from '@rudderstack/analytics-js-common/constants/integrations/XPixel/constants'; +import Logger from '../../utils/logger'; +import { getHashFromArrayWithDuplicate } from '../../utils/commonUtils'; +import { getTrackResponse, sendEvent } from './utils'; +import { loadNativeSdk } from './nativeSdkLoader'; + +const logger = new Logger(DISPLAY_NAME); +class XPixel { + constructor(config, analytics, destinationInfo) { + if (analytics.logLevel) { + logger.setLogLevel(analytics.logLevel); + } + this.analytics = analytics; + this.pixelId = config.pixelId; + this.eventsMapping = config.eventsMapping; + this.name = NAME; + ({ + shouldApplyDeviceModeTransformation: this.shouldApplyDeviceModeTransformation, + propagateEventsUntransformedOnError: this.propagateEventsUntransformedOnError, + destinationId: this.destinationId, + } = destinationInfo ?? {}); + } + + init() { + loadNativeSdk(this.pixelId); + } + + isLoaded() { + return !!window.twq; + } + + isReady() { + return this.isLoaded(); + } + + track(rudderElement) { + const { event } = rudderElement.message; + if (!event) { + logger.error('Event name is missing'); + return; + } + const properties = getTrackResponse(rudderElement.message); + const standardEventsMap = getHashFromArrayWithDuplicate(this.eventsMapping); + sendEvent(event, properties, standardEventsMap); + } + + page(rudderElement) { + const properties = getTrackResponse(rudderElement.message); + const standardEventsMap = getHashFromArrayWithDuplicate(this.eventsMapping); + sendEvent('Page View', properties, standardEventsMap); + } +} +export default XPixel; diff --git a/packages/analytics-js-integrations/src/integrations/XPixel/index.js b/packages/analytics-js-integrations/src/integrations/XPixel/index.js new file mode 100644 index 0000000000..5aad816c97 --- /dev/null +++ b/packages/analytics-js-integrations/src/integrations/XPixel/index.js @@ -0,0 +1 @@ +export { default as XPixel } from './browser'; diff --git a/packages/analytics-js-integrations/src/integrations/XPixel/nativeSdkLoader.js b/packages/analytics-js-integrations/src/integrations/XPixel/nativeSdkLoader.js new file mode 100644 index 0000000000..4fc767ff8e --- /dev/null +++ b/packages/analytics-js-integrations/src/integrations/XPixel/nativeSdkLoader.js @@ -0,0 +1,22 @@ +import { LOAD_ORIGIN } from '@rudderstack/analytics-js-common/v1.1/utils/constants'; + +function loadNativeSdk(pixelId) { + !(function (e, t, n, s, u, a) { + e.twq || + ((s = e.twq = + function () { + s.exe ? s.exe.apply(s, arguments) : s.queue.push(arguments); + }), + (s.version = '1.1'), + (s.queue = []), + (u = t.createElement(n)), + (u.async = !0), + (u.src = 'https://static.ads-twitter.com/uwt.js'), + (a = t.getElementsByTagName(n)[0]), + u.setAttribute('data-loader', LOAD_ORIGIN), + a.parentNode.insertBefore(u, a)); + })(window, document, 'script'); + twq('config', pixelId); +} + +export { loadNativeSdk }; diff --git a/packages/analytics-js-integrations/src/integrations/XPixel/utils.js b/packages/analytics-js-integrations/src/integrations/XPixel/utils.js new file mode 100644 index 0000000000..ae2b789816 --- /dev/null +++ b/packages/analytics-js-integrations/src/integrations/XPixel/utils.js @@ -0,0 +1,64 @@ +import { + trackPropertyMapping, + DISPLAY_NAME, +} from '@rudderstack/analytics-js-common/constants/integrations/XPixel/constants'; +import { removeUndefinedAndNullValues } from '../../utils/commonUtils'; +import { constructPayload } from '../../utils/utils'; +import Logger from '../../utils/logger'; + +const logger = new Logger(DISPLAY_NAME); + +const getContents = message => { + let contents = []; + const { properties } = message; + const { products } = properties; + if (Array.isArray(products)) { + contents = products.map(product => { + const singleProduct = { + content_type: product.contentType || product.content_type || 'product', + content_id: product.product_id, + content_name: product.name, + price: product.price, + num_items: product.quantity, + group_id: product.groupId || product.group_id, + }; + return removeUndefinedAndNullValues(singleProduct); + }); + } else { + return []; + } + return contents; +}; + +const getTrackResponse = message => { + let properties = constructPayload(message, trackPropertyMapping); // constructing properties + + // if contents is not an array + if (properties?.contents && !Array.isArray(properties.contents)) { + properties.contents = [properties.contents]; + } + + if (message.properties?.products && (!properties || (properties && !properties?.contents))) { + // retreiving data from products only when contents is not present + + properties = { + ...properties, + contents: getContents(message), + }; + } + + return removeUndefinedAndNullValues(properties); +}; + +const sendEvent = (event, properties, standardEventsMap) => { + const eventIds = standardEventsMap[event?.toLowerCase()]; + if (Array.isArray(eventIds)) { + eventIds.forEach(eventId => { + window.twq('event', eventId, properties); + }); + } else { + logger.error(`Event name (${event}) is not valid, must be mapped to atleast one Event ID`); + } +}; + +export { getTrackResponse, sendEvent }; diff --git a/packages/analytics-js-integrations/src/integrations/index.js b/packages/analytics-js-integrations/src/integrations/index.js index 4469a06588..591fb539a0 100644 --- a/packages/analytics-js-integrations/src/integrations/index.js +++ b/packages/analytics-js-integrations/src/integrations/index.js @@ -76,6 +76,7 @@ import * as Sprig from './Sprig'; import * as SpotifyPixel from './SpotifyPixel'; import * as CommandBar from './CommandBar'; import * as Ninetailed from './Ninetailed'; +import * as XPixel from './XPixel'; // the key names should match the destination.name value to keep parity everywhere // (config-plan name, native destination.name , exported integration name(this one below)) @@ -158,6 +159,7 @@ const integrations = { SPRIG: Sprig.default, SPOTIFYPIXEL: SpotifyPixel.default, NINETAILED: Ninetailed.default, + XPIXEL: XPixel.default, }; export { integrations }; diff --git a/packages/analytics-js-plugins/CHANGELOG.md b/packages/analytics-js-plugins/CHANGELOG.md index c8eaa8b07f..8ff134d6be 100644 --- a/packages/analytics-js-plugins/CHANGELOG.md +++ b/packages/analytics-js-plugins/CHANGELOG.md @@ -2,6 +2,13 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver). +## [3.4.9](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-plugins@3.4.8...@rudderstack/analytics-js-plugins@3.4.9) (2024-08-16) + +### Dependency Updates + +* `@rudderstack/analytics-js-common` updated to version `3.9.0` +* `@rudderstack/analytics-js` updated to version `3.7.8` +* `@rudderstack/analytics-js-cookies` updated to version `0.3.6` ## [3.4.8](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-plugins@3.4.7...@rudderstack/analytics-js-plugins@3.4.8) (2024-08-16) ### Dependency Updates diff --git a/packages/analytics-js-plugins/CHANGELOG_LATEST.md b/packages/analytics-js-plugins/CHANGELOG_LATEST.md index 7748a324db..32007f2af0 100644 --- a/packages/analytics-js-plugins/CHANGELOG_LATEST.md +++ b/packages/analytics-js-plugins/CHANGELOG_LATEST.md @@ -1,5 +1,7 @@ -## [3.4.8](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-plugins@3.4.7...@rudderstack/analytics-js-plugins@3.4.8) (2024-08-16) +## [3.4.9](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-plugins@3.4.8...@rudderstack/analytics-js-plugins@3.4.9) (2024-08-16) ### Dependency Updates -* `@rudderstack/analytics-js` updated to version `3.7.7` +* `@rudderstack/analytics-js-common` updated to version `3.9.0` +* `@rudderstack/analytics-js` updated to version `3.7.8` +* `@rudderstack/analytics-js-cookies` updated to version `0.3.6` diff --git a/packages/analytics-js-plugins/package.json b/packages/analytics-js-plugins/package.json index 4eba457569..25245d81f3 100644 --- a/packages/analytics-js-plugins/package.json +++ b/packages/analytics-js-plugins/package.json @@ -1,6 +1,6 @@ { "name": "@rudderstack/analytics-js-plugins", - "version": "3.4.8", + "version": "3.4.9", "private": true, "description": "RudderStack JavaScript SDK plugins", "main": "dist/npm/modern/cjs/index.cjs", diff --git a/packages/analytics-js-plugins/project.json b/packages/analytics-js-plugins/project.json index 32211beadc..42506dc7df 100644 --- a/packages/analytics-js-plugins/project.json +++ b/packages/analytics-js-plugins/project.json @@ -51,9 +51,9 @@ "github": { "executor": "@jscutlery/semver:github", "options": { - "tag": "@rudderstack/analytics-js-plugins@3.4.8", - "title": "@rudderstack/analytics-js-plugins@3.4.8", - "discussion-category": "@rudderstack/analytics-js-plugins@3.4.8", + "tag": "@rudderstack/analytics-js-plugins@3.4.9", + "title": "@rudderstack/analytics-js-plugins@3.4.9", + "discussion-category": "@rudderstack/analytics-js-plugins@3.4.9", "notesFile": "./packages/analytics-js-plugins/CHANGELOG_LATEST.md" } } diff --git a/packages/analytics-js-service-worker/CHANGELOG.md b/packages/analytics-js-service-worker/CHANGELOG.md index 95acf169a2..b30e67b80c 100644 --- a/packages/analytics-js-service-worker/CHANGELOG.md +++ b/packages/analytics-js-service-worker/CHANGELOG.md @@ -2,6 +2,11 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver). +## [3.1.9](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-service-worker@3.1.8...@rudderstack/analytics-js-service-worker@3.1.9) (2024-08-16) + +### Dependency Updates + +* `@rudderstack/analytics-js-common` updated to version `3.9.0` ## [3.1.8](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-service-worker@3.1.7...@rudderstack/analytics-js-service-worker@3.1.8) (2024-08-16) diff --git a/packages/analytics-js-service-worker/CHANGELOG_LATEST.md b/packages/analytics-js-service-worker/CHANGELOG_LATEST.md index 6e8057edb2..a082206621 100644 --- a/packages/analytics-js-service-worker/CHANGELOG_LATEST.md +++ b/packages/analytics-js-service-worker/CHANGELOG_LATEST.md @@ -1,7 +1,5 @@ -## [3.1.8](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-service-worker@3.1.7...@rudderstack/analytics-js-service-worker@3.1.8) (2024-08-16) +## [3.1.9](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-service-worker@3.1.8...@rudderstack/analytics-js-service-worker@3.1.9) (2024-08-16) +### Dependency Updates -### Bug Fixes - -* upgrade axios to a safe version ([#1827](https://github.com/rudderlabs/rudder-sdk-js/issues/1827)) ([bafe698](https://github.com/rudderlabs/rudder-sdk-js/commit/bafe6983c8e4db9e8055a96b8a7ab50c738b056d)) - +* `@rudderstack/analytics-js-common` updated to version `3.9.0` diff --git a/packages/analytics-js-service-worker/package.json b/packages/analytics-js-service-worker/package.json index 3c808b3ff2..2f789a38a4 100644 --- a/packages/analytics-js-service-worker/package.json +++ b/packages/analytics-js-service-worker/package.json @@ -1,6 +1,6 @@ { "name": "@rudderstack/analytics-js-service-worker", - "version": "3.1.8", + "version": "3.1.9", "description": "RudderStack JavaScript Service Worker SDK", "main": "dist/npm/modern/cjs/index.cjs", "module": "dist/npm/modern/esm/index.mjs", diff --git a/packages/analytics-js-service-worker/project.json b/packages/analytics-js-service-worker/project.json index 879e3a7967..2c575e7e1d 100644 --- a/packages/analytics-js-service-worker/project.json +++ b/packages/analytics-js-service-worker/project.json @@ -51,9 +51,9 @@ "github": { "executor": "@jscutlery/semver:github", "options": { - "tag": "@rudderstack/analytics-js-service-worker@3.1.8", - "title": "rudderstack/analytics-js-service-worker@3.1.8", - "discussion-category": "rudderstack/analytics-js-service-worker@3.1.8", + "tag": "@rudderstack/analytics-js-service-worker@3.1.9", + "title": "rudderstack/analytics-js-service-worker@3.1.9", + "discussion-category": "rudderstack/analytics-js-service-worker@3.1.9", "notesFile": "./packages/analytics-js-service-worker/CHANGELOG_LATEST.md" } } diff --git a/packages/analytics-js/CHANGELOG.md b/packages/analytics-js/CHANGELOG.md index 409a13097a..76485a8470 100644 --- a/packages/analytics-js/CHANGELOG.md +++ b/packages/analytics-js/CHANGELOG.md @@ -2,6 +2,13 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver). +## [3.7.9](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js@3.7.8...@rudderstack/analytics-js@3.7.9) (2024-08-16) + +### Dependency Updates + +* `@rudderstack/analytics-js-cookies` updated to version `0.3.6` +* `@rudderstack/analytics-js-common` updated to version `3.9.0` +* `@rudderstack/analytics-js-plugins` updated to version `3.4.9` ## [3.7.8](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js@3.7.7...@rudderstack/analytics-js@3.7.8) (2024-08-16) ### Dependency Updates diff --git a/packages/analytics-js/CHANGELOG_LATEST.md b/packages/analytics-js/CHANGELOG_LATEST.md index bf2574c69a..2c5048db40 100644 --- a/packages/analytics-js/CHANGELOG_LATEST.md +++ b/packages/analytics-js/CHANGELOG_LATEST.md @@ -1,5 +1,7 @@ -## [3.7.8](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js@3.7.7...@rudderstack/analytics-js@3.7.8) (2024-08-16) +## [3.7.9](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js@3.7.8...@rudderstack/analytics-js@3.7.9) (2024-08-16) ### Dependency Updates -* `@rudderstack/analytics-js-plugins` updated to version `3.4.8` +* `@rudderstack/analytics-js-cookies` updated to version `0.3.6` +* `@rudderstack/analytics-js-common` updated to version `3.9.0` +* `@rudderstack/analytics-js-plugins` updated to version `3.4.9` diff --git a/packages/analytics-js/package.json b/packages/analytics-js/package.json index 7d2518301f..bc91edce8f 100644 --- a/packages/analytics-js/package.json +++ b/packages/analytics-js/package.json @@ -1,6 +1,6 @@ { "name": "@rudderstack/analytics-js", - "version": "3.7.8", + "version": "3.7.9", "description": "RudderStack JavaScript SDK", "main": "dist/npm/modern/cjs/index.cjs", "module": "dist/npm/modern/esm/index.mjs", diff --git a/packages/analytics-js/project.json b/packages/analytics-js/project.json index a1225a89b6..e089f08a05 100644 --- a/packages/analytics-js/project.json +++ b/packages/analytics-js/project.json @@ -59,9 +59,9 @@ "github": { "executor": "@jscutlery/semver:github", "options": { - "tag": "@rudderstack/analytics-js@3.7.8", - "title": "@rudderstack/analytics-js@3.7.8", - "discussion-category": "@rudderstack/analytics-js@3.7.8", + "tag": "@rudderstack/analytics-js@3.7.9", + "title": "@rudderstack/analytics-js@3.7.9", + "discussion-category": "@rudderstack/analytics-js@3.7.9", "notesFile": "./packages/analytics-js/CHANGELOG_LATEST.md" } } diff --git a/packages/analytics-js/public/index.html b/packages/analytics-js/public/index.html index 651e4b19f5..5fc96a57cf 100644 --- a/packages/analytics-js/public/index.html +++ b/packages/analytics-js/public/index.html @@ -59,16 +59,28 @@ } }; window.rudderAnalyticsMount = function() { - if (typeof globalThis === "undefined") { - Object.defineProperty(Object.prototype, "__globalThis_magic__", { - get: function get() { - return this; - }, - configurable: true - }); - __globalThis_magic__.globalThis = __globalThis_magic__; - delete Object.prototype.__globalThis_magic__; - } + (function() { + if (typeof globalThis === "undefined") { + let getGlobal = function() { + if (typeof self !== "undefined") { + return self; + } + if (typeof window !== "undefined") { + return window; + } + return null; + }; + + let global = getGlobal(); + + if (global) { + Object.defineProperty(global, 'globalThis', { + value: global, + configurable: true + }); + } + } + })(); // Commented out SDK script addition // as the build process automatically adds the script diff --git a/packages/analytics-v1.1/CHANGELOG.md b/packages/analytics-v1.1/CHANGELOG.md index 4fbdc62678..ce6b15d69b 100644 --- a/packages/analytics-v1.1/CHANGELOG.md +++ b/packages/analytics-v1.1/CHANGELOG.md @@ -2,6 +2,11 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver). +## [2.48.16](https://github.com/rudderlabs/rudder-sdk-js/compare/rudder-sdk-js@2.48.15...rudder-sdk-js@2.48.16) (2024-08-16) + +### Dependency Updates + +* `@rudderstack/analytics-js-common` updated to version `3.9.0` ## [2.48.15](https://github.com/rudderlabs/rudder-sdk-js/compare/rudder-sdk-js@2.48.14...rudder-sdk-js@2.48.15) (2024-08-02) ### Dependency Updates diff --git a/packages/analytics-v1.1/CHANGELOG_LATEST.md b/packages/analytics-v1.1/CHANGELOG_LATEST.md index e66a7dfc26..74849ee2cc 100644 --- a/packages/analytics-v1.1/CHANGELOG_LATEST.md +++ b/packages/analytics-v1.1/CHANGELOG_LATEST.md @@ -1,10 +1,5 @@ -## [2.48.15](https://github.com/rudderlabs/rudder-sdk-js/compare/rudder-sdk-js@2.48.14...rudder-sdk-js@2.48.15) (2024-08-02) +## [2.48.16](https://github.com/rudderlabs/rudder-sdk-js/compare/rudder-sdk-js@2.48.15...rudder-sdk-js@2.48.16) (2024-08-16) ### Dependency Updates -* `@rudderstack/analytics-js-common` updated to version `3.8.1` - -### Bug Fixes - -* npm sanity suites ([#1810](https://github.com/rudderlabs/rudder-sdk-js/issues/1810)) ([22e43da](https://github.com/rudderlabs/rudder-sdk-js/commit/22e43da01f750a5cb23a2fce50de3744c54a197e)) - +* `@rudderstack/analytics-js-common` updated to version `3.9.0` diff --git a/packages/analytics-v1.1/package.json b/packages/analytics-v1.1/package.json index a045cbf482..adb14446b1 100644 --- a/packages/analytics-v1.1/package.json +++ b/packages/analytics-v1.1/package.json @@ -1,6 +1,6 @@ { "name": "rudder-sdk-js", - "version": "2.48.15", + "version": "2.48.16", "description": "RudderStack JavaScript SDK", "main": "dist/npm/index.js", "module": "dist/npm/index.es.js", diff --git a/packages/analytics-v1.1/project.json b/packages/analytics-v1.1/project.json index 2d307e2650..4d0626ee32 100644 --- a/packages/analytics-v1.1/project.json +++ b/packages/analytics-v1.1/project.json @@ -59,9 +59,9 @@ "github": { "executor": "@jscutlery/semver:github", "options": { - "tag": "rudder-sdk-js@2.48.15", - "title": "rudder-sdk-js@2.48.15", - "discussion-category": "rudder-sdk-js@2.48.15", + "tag": "rudder-sdk-js@2.48.16", + "title": "rudder-sdk-js@2.48.16", + "discussion-category": "rudder-sdk-js@2.48.16", "notesFile": "./packages/analytics-v1.1/CHANGELOG_LATEST.md" } } diff --git a/packages/loading-scripts/CHANGELOG.md b/packages/loading-scripts/CHANGELOG.md index 0752390cef..3bbb6251ee 100644 --- a/packages/loading-scripts/CHANGELOG.md +++ b/packages/loading-scripts/CHANGELOG.md @@ -2,6 +2,11 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver). +## [3.0.26](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-loading-scripts@3.0.25...@rudderstack/analytics-js-loading-scripts@3.0.26) (2024-08-16) + +### Dependency Updates + +* `@rudderstack/analytics-js` updated to version `3.7.9` ## [3.0.25](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-loading-scripts@3.0.24...@rudderstack/analytics-js-loading-scripts@3.0.25) (2024-08-16) ### Dependency Updates diff --git a/packages/loading-scripts/CHANGELOG_LATEST.md b/packages/loading-scripts/CHANGELOG_LATEST.md index e334666101..0c58ad7f31 100644 --- a/packages/loading-scripts/CHANGELOG_LATEST.md +++ b/packages/loading-scripts/CHANGELOG_LATEST.md @@ -1,5 +1,5 @@ -## [3.0.25](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-loading-scripts@3.0.24...@rudderstack/analytics-js-loading-scripts@3.0.25) (2024-08-16) +## [3.0.26](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-loading-scripts@3.0.25...@rudderstack/analytics-js-loading-scripts@3.0.26) (2024-08-16) ### Dependency Updates -* `@rudderstack/analytics-js` updated to version `3.7.8` +* `@rudderstack/analytics-js` updated to version `3.7.9` diff --git a/packages/loading-scripts/package.json b/packages/loading-scripts/package.json index 08ab36bf52..b5f724af4a 100644 --- a/packages/loading-scripts/package.json +++ b/packages/loading-scripts/package.json @@ -1,6 +1,6 @@ { "name": "@rudderstack/analytics-js-loading-scripts", - "version": "3.0.25", + "version": "3.0.26", "private": true, "description": "Loading script for RudderStack JavaScript SDK", "main": "./src/index.js", diff --git a/packages/loading-scripts/project.json b/packages/loading-scripts/project.json index f24c90129f..65cb068f91 100644 --- a/packages/loading-scripts/project.json +++ b/packages/loading-scripts/project.json @@ -51,9 +51,9 @@ "github": { "executor": "@jscutlery/semver:github", "options": { - "tag": "@rudderstack/analytics-js-loading-scripts@3.0.25", - "title": "@rudderstack/analytics-js-loading-scripts@3.0.25", - "discussion-category": "@rudderstack/analytics-js-loading-scripts@3.0.25", + "tag": "@rudderstack/analytics-js-loading-scripts@3.0.26", + "title": "@rudderstack/analytics-js-loading-scripts@3.0.26", + "discussion-category": "@rudderstack/analytics-js-loading-scripts@3.0.26", "notesFile": "./packages/loading-scripts/CHANGELOG_LATEST.md" } } diff --git a/packages/loading-scripts/src/index.ts b/packages/loading-scripts/src/index.ts index 311e2ce017..64a3f55d56 100644 --- a/packages/loading-scripts/src/index.ts +++ b/packages/loading-scripts/src/index.ts @@ -99,18 +99,28 @@ if (Array.isArray(rudderanalytics)) { window.rudderAnalyticsMount = () => { /* eslint-disable */ // globalThis polyfill as polyfill-fastly.io one does not work in legacy safari - if (typeof globalThis === 'undefined') { - Object.defineProperty(Object.prototype, '__globalThis_magic__', { - get: function get() { - return this; - }, - configurable: true, - }); - // @ts-ignore - __globalThis_magic__.globalThis = __globalThis_magic__; - // @ts-ignore - delete Object.prototype.__globalThis_magic__; - } + (function () { + if (typeof globalThis === 'undefined') { + let getGlobal = function () { + if (typeof self !== 'undefined') { + return self; + } + if (typeof window !== 'undefined') { + return window; + } + return null; + }; + + let global = getGlobal(); + + if (global) { + Object.defineProperty(global, 'globalThis', { + value: global, + configurable: true, + }); + } + } + })(); /* eslint-enable */ window.rudderAnalyticsAddScript( diff --git a/packages/sanity-suite/CHANGELOG.md b/packages/sanity-suite/CHANGELOG.md index ddda02a1da..3af2b07a32 100644 --- a/packages/sanity-suite/CHANGELOG.md +++ b/packages/sanity-suite/CHANGELOG.md @@ -2,6 +2,11 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver). +## [3.1.16](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-sanity-suite@3.1.15...@rudderstack/analytics-js-sanity-suite@3.1.16) (2024-08-16) + +### Dependency Updates + +* `@rudderstack/analytics-js` updated to version `3.7.9` ## [3.1.15](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-sanity-suite@3.1.14...@rudderstack/analytics-js-sanity-suite@3.1.15) (2024-08-16) ### Dependency Updates diff --git a/packages/sanity-suite/package.json b/packages/sanity-suite/package.json index ec9c09ed59..0d6a3b49df 100644 --- a/packages/sanity-suite/package.json +++ b/packages/sanity-suite/package.json @@ -1,6 +1,6 @@ { "name": "@rudderstack/analytics-js-sanity-suite", - "version": "3.1.15", + "version": "3.1.16", "private": true, "description": "Sanity suite for testing JS SDK package", "main": "./dist/v3/cdn/testBook.js", diff --git a/packages/sanity-suite/public/v3/index-cdn.html b/packages/sanity-suite/public/v3/index-cdn.html index 9fda0446f7..9a6fe3e463 100644 --- a/packages/sanity-suite/public/v3/index-cdn.html +++ b/packages/sanity-suite/public/v3/index-cdn.html @@ -81,16 +81,28 @@ } }; window.rudderAnalyticsMount = function() { - if (typeof globalThis === "undefined") { - Object.defineProperty(Object.prototype, "__globalThis_magic__", { - get: function get() { - return this; - }, - configurable: true - }); - __globalThis_magic__.globalThis = __globalThis_magic__; - delete Object.prototype.__globalThis_magic__; - } + (function() { + if (typeof globalThis === "undefined") { + let getGlobal = function() { + if (typeof self !== "undefined") { + return self; + } + if (typeof window !== "undefined") { + return window; + } + return null; + }; + + let global = getGlobal(); + + if (global) { + Object.defineProperty(global, 'globalThis', { + value: global, + configurable: true + }); + } + } + })(); window.rudderAnalyticsAddScript("".concat(sdkBaseUrl, "/").concat(window.rudderAnalyticsBuildType, "/").concat(sdkName), "data-rsa-write-key", "__WRITE_KEY__"); }; if (typeof Promise === "undefined" || typeof globalThis === "undefined") { diff --git a/packages/sanity-suite/public/v3/index-local.html b/packages/sanity-suite/public/v3/index-local.html index 447a493a1e..5e0e7479a3 100644 --- a/packages/sanity-suite/public/v3/index-local.html +++ b/packages/sanity-suite/public/v3/index-local.html @@ -81,16 +81,28 @@ } }; window.rudderAnalyticsMount = function() { - if (typeof globalThis === "undefined") { - Object.defineProperty(Object.prototype, "__globalThis_magic__", { - get: function get() { - return this; - }, - configurable: true - }); - __globalThis_magic__.globalThis = __globalThis_magic__; - delete Object.prototype.__globalThis_magic__; - } + (function() { + if (typeof globalThis === "undefined") { + let getGlobal = function() { + if (typeof self !== "undefined") { + return self; + } + if (typeof window !== "undefined") { + return window; + } + return null; + }; + + let global = getGlobal(); + + if (global) { + Object.defineProperty(global, 'globalThis', { + value: global, + configurable: true + }); + } + } + })(); // window.rudderAnalyticsAddScript("".concat(sdkBaseUrl, "/").concat(window.rudderAnalyticsBuildType, "/").concat(sdkName), "data-rsa-write-key", "__WRITE_KEY__"); }; if (typeof Promise === "undefined" || typeof globalThis === "undefined") { diff --git a/packages/sanity-suite/public/v3/index-npm-bundled.html b/packages/sanity-suite/public/v3/index-npm-bundled.html index 7bc80d37e7..a2c1b28c1f 100644 --- a/packages/sanity-suite/public/v3/index-npm-bundled.html +++ b/packages/sanity-suite/public/v3/index-npm-bundled.html @@ -95,16 +95,28 @@ src="https://polyfill-fastly.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise%2CglobalThis" >