diff --git a/.size-limit.js b/.size-limit.js index fabaf5138..e9cad1dcc 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -13,7 +13,7 @@ module.exports = [ name: 'All Integrations - CDN', path: 'dist/legacy/js-integrations/*.min.js', gzip: true, - limit: '446.5 kB', + limit: '447.3 kB', }, { name: 'Core - NPM', diff --git a/__tests__/integrations/TikTokAds/tiktokads.test.js b/__tests__/integrations/TikTokAds/tiktokads.test.js index db7e62958..9cd265e48 100644 --- a/__tests__/integrations/TikTokAds/tiktokads.test.js +++ b/__tests__/integrations/TikTokAds/tiktokads.test.js @@ -1,231 +1,244 @@ -import TiktokAds from "../../../src/integrations/TiktokAds/browser"; +import TiktokAds from '../../../src/integrations/TiktokAds/browser'; -beforeAll(() => { }); +beforeAll(() => {}); afterAll(() => { - jest.restoreAllMocks(); + jest.restoreAllMocks(); }); describe('tiktokads init tests', () => { - let tiktokads; - test('Testing init call of TiktokAds', () => { - tiktokads = new TiktokAds({ - pixelCode: "12567839", eventsToStandard: [ - { from: 'Sign Up', to: 'Signup' }, - { to: 'Lead', from: 'orderCompleted' }, - { from: 'Page View', to: 'PageVisit' }, - { from: 'productAdded', to: 'AddToCart' } - ] - }, { loglevel: "debug" }); - tiktokads.init(); - expect(typeof window.ttq).toBe('object'); - }); + let tiktokads; + test('Testing init call of TiktokAds', () => { + tiktokads = new TiktokAds( + { + pixelCode: '12567839', + eventsToStandard: [ + { from: 'Sign Up', to: 'Signup' }, + { to: 'Lead', from: 'orderCompleted' }, + { from: 'Page View', to: 'PageVisit' }, + { from: 'productAdded', to: 'AddToCart' }, + ], + }, + { loglevel: 'debug' }, + ); + tiktokads.init(); + expect(typeof window.ttq).toBe('object'); + }); }); -describe("tiktokads page", () => { - let tiktokads; - beforeEach(() => { - tiktokads = new TiktokAds({ - pixelCode: "12567839", eventsToStandard: [ - { from: 'Sign Up', to: 'Signup' }, - { to: 'Lead', from: 'orderCompleted' }, - { from: 'Page View', to: 'PageVisit' }, - { from: 'productAdded', to: 'AddToCart' }, - ] - }, { loglevel: "debug" }); - tiktokads.init(); - window.ttq.page = jest.fn(); - }); +describe('tiktokads page', () => { + let tiktokads; + beforeEach(() => { + tiktokads = new TiktokAds( + { + pixelCode: '12567839', + eventsToStandard: [ + { from: 'Sign Up', to: 'Signup' }, + { to: 'Lead', from: 'orderCompleted' }, + { from: 'Page View', to: 'PageVisit' }, + { from: 'productAdded', to: 'AddToCart' }, + ], + }, + { loglevel: 'debug' }, + ); + tiktokads.init(); + window.ttq.page = jest.fn(); + }); - test("send pageview", () => { - tiktokads.page({ - message: { - context: {}, - properties: { - category: "test cat", - path: "/test", - url: "http://localhost", - referrer: "", - title: "test page", - testDimension: "abc" - }, - }, - }); - expect(window.ttq.page.mock.calls[0][0]).toEqual(); + test('send pageview', () => { + tiktokads.page({ + message: { + context: {}, + properties: { + category: 'test cat', + path: '/test', + url: 'http://localhost', + referrer: '', + title: 'test page', + testDimension: 'abc', + }, + }, }); + expect(window.ttq.page.mock.calls[0][0]).toEqual(); + }); }); -describe("TiktokAds Track event", () => { - let tiktokads; - beforeEach(() => { - tiktokads = new TiktokAds({ - pixelCode: "12567839", eventsToStandard: [ - { from: 'Sign Up', to: 'Signup' }, - { to: 'Lead', from: 'orderCompleted' }, - { from: 'Page View', to: 'PageVisit' }, - { from: 'Custom', to: 'AddToCart' }, - ] - }, { loglevel: "DEBUG" }); - tiktokads.init(); - window.ttq.track = jest.fn(); +describe('TiktokAds Track event', () => { + let tiktokads; + beforeEach(() => { + tiktokads = new TiktokAds( + { + pixelCode: '12567839', + eventsToStandard: [ + { from: 'Sign Up', to: 'Signup' }, + { to: 'Lead', from: 'orderCompleted' }, + { from: 'Page View', to: 'PageVisit' }, + { from: 'Custom', to: 'AddToCart' }, + ], + }, + { loglevel: 'DEBUG' }, + ); + tiktokads.init(); + window.ttq.track = jest.fn(); + }); + test('Testing Track Custom Events with no content_type in payload', () => { + tiktokads.track({ + message: { + context: {}, + event: 'Custom', + properties: { + customProp: 'testProp', + checkout_id: 'what is checkout id here??', + event_id: 'purchaseId', + order_id: 'transactionId', + value: 35.0, + shipping: 4.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', + }, + ], + }, + }, }); - test("Testing Track Custom Events with no content_type in payload", () => { - tiktokads.track({ - message: { - context: {}, - event: "Custom", - properties: { - "customProp": "testProp", - checkout_id: 'what is checkout id here??', - event_id: 'purchaseId', - order_id: "transactionId", - value: 35.00, - shipping: 4.00, - coupon: 'APPARELSALE', - currency: 'GBP', - products: [ - { - "customPropProd": "testPropProd", - product_id: 'abc', - category: 'Merch', - name: 'Food', - brand: '', - variant: 'Extra topped', - price: 3.00, - quantity: 2, - currency: 'GBP', - position: 1, - value: 6.00, - typeOfProduct: 'Food', - } - ] - }, - } - }); - expect(window.ttq.track.mock.calls[0][0]).toEqual("AddToCart"); - expect(window.ttq.track.mock.calls[0][1]).toEqual({ - value: 35.00, - "currency": "GBP", - "partner_name": "RudderStack", - contents: [ - { - "content_category": "Merch", - "content_id": "abc", - "content_name": "Food", - "content_type": "product", - price: 3.00, - quantity: 2, - - } - ] - }); + expect(window.ttq.track.mock.calls[0][0]).toEqual('AddToCart'); + expect(window.ttq.track.mock.calls[0][1]).toEqual({ + value: 35.0, + currency: 'GBP', + event_id: 'purchaseId', + partner_name: 'RudderStack', + contents: [ + { + content_category: 'Merch', + content_id: 'abc', + content_name: 'Food', + content_type: 'product', + price: 3.0, + quantity: 2, + }, + ], }); - test("Testing Track Custom Events with content type in payload and multiple products", () => { - tiktokads.track({ - message: { - context: {}, - event: "Custom", - properties: { - "customProp": "testProp", - checkout_id: 'what is checkout id here??', - event_id: 'purchaseId', - order_id: "transactionId", - value: 35.00, - shipping: 4.00, - coupon: 'APPARELSALE', - currency: 'GBP', - products: [ - { - "customPropProd": "testPropProd", - product_id: 'abc', - category: 'Merch', - name: 'Drink', - brand: '', - variant: 'Extra topped', - price: 3.00, - quantity: 2, - currency: 'GBP', - position: 1, - value: 6.00, - typeOfProduct: 'Food', - url: 'https://www.example.com/product/bacon-jam', - image_url: 'https://www.example.com/product/bacon-jam.jpg' - }, - { - product_id: 'PRODUCT_ID', - category: 'Wholesaler', - name: 'Drink', - brand: '', - variant: 'Extra Cheese', - price: 50.00, - quantity: 1, - currency: 'GBP', - position: 1, - value: 30.00, - typeOfProduct: 'Food', - content_type: 'CONTENT_TYPE', - url: 'https://www.example.com/product/bacon-jam', - image_url: 'https://www.example.com/product/bacon-jam.jpg' - } - ] - } - } - }); - expect(window.ttq.track.mock.calls[0][0]).toEqual("AddToCart"); - expect(window.ttq.track.mock.calls[0][1]).toEqual({ - value: 35.00, - "currency": "GBP", - "partner_name": "RudderStack", - contents: [ - { - "content_category": "Merch", - "content_id": "abc", - "content_name": "Drink", - "content_type": "product", - price: 3.00, - quantity: 2, - - }, - { - "content_category": "Wholesaler", - "content_id": "PRODUCT_ID", - "content_name": "Drink", - "content_type": "CONTENT_TYPE", - price: 50.00, - quantity: 1, - - } - ] - }); + }); + test('Testing Track Custom Events with content type in payload and multiple products', () => { + tiktokads.track({ + message: { + context: {}, + event: 'Custom', + properties: { + customProp: 'testProp', + checkout_id: 'what is checkout id here??', + event_id: 'purchaseId', + order_id: 'transactionId', + value: 35.0, + shipping: 4.0, + coupon: 'APPARELSALE', + currency: 'GBP', + products: [ + { + customPropProd: 'testPropProd', + product_id: 'abc', + category: 'Merch', + name: 'Drink', + brand: '', + variant: 'Extra topped', + price: 3.0, + quantity: 2, + currency: 'GBP', + position: 1, + value: 6.0, + typeOfProduct: 'Food', + url: 'https://www.example.com/product/bacon-jam', + image_url: 'https://www.example.com/product/bacon-jam.jpg', + }, + { + product_id: 'PRODUCT_ID', + category: 'Wholesaler', + name: 'Drink', + brand: '', + variant: 'Extra Cheese', + price: 50.0, + quantity: 1, + currency: 'GBP', + position: 1, + value: 30.0, + typeOfProduct: 'Food', + content_type: 'CONTENT_TYPE', + url: 'https://www.example.com/product/bacon-jam', + image_url: 'https://www.example.com/product/bacon-jam.jpg', + }, + ], + }, + }, }); -}); - -describe("TiktokAds Identify event", () => { - let tiktokads; - beforeEach(() => { - tiktokads = new TiktokAds({ - pixelCode: "12567839", eventsToStandard: [ - { from: 'Sign Up', to: 'Signup' }, - { to: 'Lead', from: 'orderCompleted' }, - { from: 'Page View', to: 'PageVisit' }, - { from: 'productAdded', to: 'AddToCart' }, - ] - }, { loglevel: "DEBUG" }); - tiktokads.init(); - window.ttq.identify = jest.fn(); + expect(window.ttq.track.mock.calls[0][0]).toEqual('AddToCart'); + expect(window.ttq.track.mock.calls[0][1]).toEqual({ + value: 35.0, + currency: 'GBP', + event_id: 'purchaseId', + partner_name: 'RudderStack', + contents: [ + { + content_category: 'Merch', + content_id: 'abc', + content_name: 'Drink', + content_type: 'product', + price: 3.0, + quantity: 2, + }, + { + content_category: 'Wholesaler', + content_id: 'PRODUCT_ID', + content_name: 'Drink', + content_type: 'CONTENT_TYPE', + price: 50.0, + quantity: 1, + }, + ], }); - test("Testing Identify Custom Events", () => { - - tiktokads.identify({ - message: { - "userId": "rudder01", - context: { - traits: { - email: "abc@ruddertack.com" - } - }, + }); +}); - } - }); - expect(window.ttq.identify.mock.calls[0][0]).toEqual({ email: "abc@ruddertack.com" }); +describe('TiktokAds Identify event', () => { + let tiktokads; + beforeEach(() => { + tiktokads = new TiktokAds( + { + pixelCode: '12567839', + eventsToStandard: [ + { from: 'Sign Up', to: 'Signup' }, + { to: 'Lead', from: 'orderCompleted' }, + { from: 'Page View', to: 'PageVisit' }, + { from: 'productAdded', to: 'AddToCart' }, + ], + }, + { loglevel: 'DEBUG' }, + ); + tiktokads.init(); + window.ttq.identify = jest.fn(); + }); + test('Testing Identify Custom Events', () => { + tiktokads.identify({ + message: { + userId: 'rudder01', + context: { + traits: { + email: 'abc@ruddertack.com', + }, + }, + }, }); + expect(window.ttq.identify.mock.calls[0][0]).toEqual({ email: 'abc@ruddertack.com' }); + }); }); diff --git a/src/integrations/TiktokAds/constants.js b/src/integrations/TiktokAds/constants.js index 4b186c40e..ad3e18220 100644 --- a/src/integrations/TiktokAds/constants.js +++ b/src/integrations/TiktokAds/constants.js @@ -3,67 +3,67 @@ const CNameMapping = { [NAME]: NAME, TiktokAds: NAME, TIKTOK_ADS: NAME, - "Tiktok ads": NAME, - "Tiktok Ads": NAME, - "Tik Tok Ads": NAME, - "tik tok ads": NAME, - tiktokads: NAME + 'Tiktok ads': NAME, + 'Tiktok Ads': NAME, + 'Tik Tok Ads': NAME, + 'tik tok ads': NAME, + tiktokads: NAME, }; const PARTNER_NAME = 'RudderStack'; const trackMapping = [ { - "destKey": "event_id", - "sourceKeys": "properties.eventId" + destKey: 'event_id', + sourceKeys: ['properties.eventId', 'properties.event_id', 'messageId'], }, { - "destKey": "test_event_code", - "sourceKeys": "testEventCode" + destKey: 'test_event_code', + sourceKeys: 'testEventCode', }, { - "destKey": "contents", - "sourceKeys": "properties.contents" + destKey: 'contents', + sourceKeys: 'properties.contents', }, { - "destKey": "content_category", - "sourceKeys": "properties.category" + destKey: 'content_category', + sourceKeys: 'properties.category', }, { - "destKey": "status", - "sourceKeys": "properties.status" + destKey: 'status', + sourceKeys: 'properties.status', }, { - "destKey": "content_name", - "sourceKeys": "properties.name" + destKey: 'content_name', + sourceKeys: 'properties.name', }, { - "destKey": "content_id", - "sourceKeys": ["properties.product_id", "properties.productId"] + destKey: 'content_id', + sourceKeys: ['properties.product_id', 'properties.productId'], }, { - "destKey": "content_type", - "sourceKeys": ["properties.contentType", "properties.content_type"] + destKey: 'content_type', + sourceKeys: ['properties.contentType', 'properties.content_type'], }, { - "destKey": "currency", - "sourceKeys": "properties.currency" + destKey: 'currency', + sourceKeys: 'properties.currency', }, { - "destKey": "value", - "sourceKeys": "properties.value" + destKey: 'value', + sourceKeys: 'properties.value', }, { - "destKey": "description", - "sourceKeys": "properties.description" + destKey: 'description', + sourceKeys: 'properties.description', }, { - "destKey": "email", - "sourceKeys": ["context.traits.email", "traits.email", "properties.email"] + destKey: 'email', + sourceKeys: ['context.traits.email', 'traits.email', 'properties.email'], }, { - "destKey": "phone", - "sourceKeys": ["context.traits.phone", "traits.phone", "properties.phone"] - } + destKey: 'phone', + sourceKeys: ['context.traits.phone', 'traits.phone', 'properties.phone'], + }, ]; const eventNameMapping = { 'product added to wishlist': 'AddToWishlist', @@ -82,5 +82,4 @@ const eventNameMapping = { subscribe: 'Subscribe', }; - export { NAME, CNameMapping, PARTNER_NAME, trackMapping, eventNameMapping };