-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/sdk-1301-create-a-cookie-setter-p…
…rovider-for-service
- Loading branch information
Showing
4 changed files
with
302 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,41 @@ describe('BingAds Track event', () => { | |
bingAds.init(); | ||
window.bing12567839.push = jest.fn((_, y, z) => output.push({ event: y, ...z })); | ||
}); | ||
|
||
test('Test for custom properties with enhanced conversions using email only', () => { | ||
bingAds = new BingAds( | ||
{ tagID: '12567839', enableEnhancedConversions: true }, | ||
{ loglevel: 'DEBUG' }, | ||
); | ||
bingAds.init(); | ||
window.bing12567839.push = jest.fn((_, y, z) => output.push({ event: y, ...z })); | ||
bingAds.track({ | ||
message: { | ||
type: 'track', | ||
context: { | ||
traits: { email: '[email protected]' }, | ||
}, | ||
event, | ||
properties: { | ||
event_action: 'button_click', | ||
category: 'Food', | ||
currency: 'INR', | ||
customProp: 'custom', | ||
}, | ||
}, | ||
}); | ||
expect(output[0]).toEqual({ | ||
event: 'button_click', | ||
event_label: event, | ||
event_category: 'Food', | ||
currency: 'INR', | ||
customProp: 'custom', | ||
ecomm_pagetype: 'other', | ||
pid: { | ||
'': '', | ||
em: 'ee278943de84e5d6243578ee1a1057bcce0e50daad9755f45dfa64b60b13bc5d', | ||
}, | ||
}); | ||
}); | ||
test('Test for all properties not null', () => { | ||
bingAds.track({ | ||
message: { | ||
|
@@ -83,7 +117,7 @@ describe('BingAds Track event', () => { | |
}, | ||
}, | ||
}); | ||
expect(output[0]).toEqual({ | ||
expect(output[1]).toEqual({ | ||
event: 'button_click', | ||
event_label: event, | ||
event_category: 'Food', | ||
|
@@ -117,7 +151,7 @@ describe('BingAds Track event', () => { | |
}, | ||
}, | ||
}); | ||
expect(output[1]).toEqual({ | ||
expect(output[2]).toEqual({ | ||
event: 'button_click', | ||
event_label: event, | ||
event_category: 'Food', | ||
|
@@ -137,7 +171,7 @@ describe('BingAds Track event', () => { | |
}, | ||
}); | ||
|
||
expect(output[2]).toEqual({ | ||
expect(output[3]).toEqual({ | ||
event: 'track', | ||
event_label: event, | ||
ecomm_pagetype: 'other', | ||
|
@@ -163,4 +197,62 @@ describe('BingAds Track event', () => { | |
expect(error).toEqual('Event type not present'); | ||
} | ||
}); | ||
test('Test for all properties not null with pid data present in context.traits', () => { | ||
bingAds = new BingAds( | ||
{ tagID: '12567839', enableEnhancedConversions: true }, | ||
{ loglevel: 'DEBUG' }, | ||
); | ||
bingAds.init(); | ||
window.bing12567839.push = jest.fn((_, y, z) => output.push({ event: y, ...z })); | ||
|
||
bingAds.track({ | ||
message: { | ||
type: 'track', | ||
context: { | ||
traits: { | ||
pid: { | ||
phn: '422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8', | ||
em: 'ee278943de84e5d6243578ee1a1057bcce0e50daad9755f45dfa64b60b13bc5d', | ||
}, | ||
}, | ||
}, | ||
event, | ||
properties: { | ||
event_action: 'button_click', | ||
category: 'Food', | ||
currency: 'INR', | ||
total: 18.9, | ||
value: 20, | ||
revenue: 25.5, | ||
ecomm_category: '80', | ||
transaction_id: 'txn-123', | ||
ecomm_pagetype: 'Cart', | ||
query, | ||
products, | ||
}, | ||
}, | ||
}); | ||
expect(output[4]).toEqual({ | ||
event: 'button_click', | ||
event_label: event, | ||
event_category: 'Food', | ||
currency: 'INR', | ||
revenue_value: 18.9, | ||
search_term: query, | ||
ecomm_query: query, | ||
ecomm_category: '80', | ||
transaction_id: 'txn-123', | ||
ecomm_pagetype: 'Cart', | ||
ecomm_prodid: ['123', '345'], | ||
items: [ | ||
{ id: '123', price: 14.99, quantity: 2 }, | ||
{ id: '345', price: 3.99, quantity: 1 }, | ||
], | ||
ecomm_totalvalue: 18.9, | ||
pid: { | ||
phn: '422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8', | ||
em: 'ee278943de84e5d6243578ee1a1057bcce0e50daad9755f45dfa64b60b13bc5d', | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { | |
buildCommonPayload, | ||
buildEcommPayload, | ||
handleProductsArray, | ||
constructPidPayload, | ||
} from '../../../src/integrations/BingAds/utils'; | ||
import { query, products } from './__fixtures__/data'; | ||
|
||
|
@@ -136,3 +137,98 @@ describe('Build ecomm payload utility tests', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('Construct PID payload for enahcned conversions', () => { | ||
it('should return undefined when both email and phone are undefined', () => { | ||
// Arrange | ||
const message = {}; | ||
|
||
// Act | ||
const result = constructPidPayload(message); | ||
|
||
// Assert | ||
expect(result).toEqual(undefined); | ||
}); | ||
|
||
// Returns undefined when email is invalid | ||
it('should return undefined when email is invalid and phone is not given', () => { | ||
// Arrange | ||
const message = { | ||
context: { | ||
traits: { | ||
email: 'invalidemail', | ||
}, | ||
}, | ||
}; | ||
|
||
// Act | ||
const result = constructPidPayload(message); | ||
|
||
// Assert | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
// Returns an object with only email property when only email is defined | ||
it('should return an object with only email property when only email is defined', () => { | ||
// Arrange | ||
const message = { | ||
context: { | ||
traits: { | ||
email: '[email protected]', | ||
}, | ||
}, | ||
}; | ||
|
||
// Act | ||
const result = constructPidPayload(message); | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
em: '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b', | ||
'': '', | ||
}); | ||
}); | ||
|
||
// Returns an object with only phone property when only phone is defined | ||
it('should return an object with only phone property when only phone is defined', () => { | ||
// Arrange | ||
const message = { | ||
traits: { | ||
phone: '1234567890', | ||
}, | ||
}; | ||
|
||
// Act | ||
const result = constructPidPayload(message); | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
ph: '422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8', | ||
'': '', | ||
}); | ||
}); | ||
|
||
// Returns an object with both email and phone properties when both are defined | ||
it('should return an object with both email and phone properties when both are defined', () => { | ||
// Arrange | ||
const message = { | ||
context: { | ||
traits: { | ||
email: '[email protected]', | ||
}, | ||
}, | ||
traits: { | ||
phone: '1234567890', | ||
}, | ||
}; | ||
|
||
// Act | ||
const result = constructPidPayload(message); | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
em: '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b', | ||
ph: '422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters