Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,67 @@ describe('GoogleEnhancedConversions', () => {
)
})

it('sends an event with default mappings - syncMode = mirror and event = updated', async () => {
const event = createTestEvent({
timestamp,
event: 'updated',
properties: {
gclid: '54321',
email: '[email protected]',
orderId: '1234',
phone: '3234567890',
firstName: 'Jane',
lastName: 'Doe',
currency: 'USD',
value: '123',
address: {
street: '123 Street SW',
city: 'San Diego',
state: 'CA',
postalCode: '982004'
}
}
})

nock(`https://googleads.googleapis.com/${API_VERSION}/customers/${customerId}/offlineUserDataJobs:create`)
.post(/.*/)
.reply(200, { data: 'offlineDataJob' })
Comment thread
varadarajan-tw marked this conversation as resolved.

nock(`https://googleads.googleapis.com/${API_VERSION}/offlineDataJob:addOperations`)
.post(/.*/)
.reply(200, { data: 'offlineDataJob' })

nock(`https://googleads.googleapis.com/${API_VERSION}/offlineDataJob:run`)
Comment thread
varadarajan-tw marked this conversation as resolved.
.post(/.*/)
.reply(200, { data: 'offlineDataJob' })

const responses = await testDestination.testAction('userList', {
event,
mapping: {
ad_user_data_consent_state: 'GRANTED',
ad_personalization_consent_state: 'GRANTED',
external_audience_id: '1234',
__segment_internal_sync_mode: 'mirror',
retlOnMappingSave: {
outputs: {
id: '1234',
name: 'Test List',
external_id_type: 'CONTACT_INFO'
}
}
},
useDefaultMappings: true,
settings: {
customerId
}
})

expect(responses.length).toEqual(3)
expect(responses[1].options.body).toMatchInlineSnapshot(
`"{\\"operations\\":[{\\"create\\":{\\"userIdentifiers\\":[{\\"hashedEmail\\":\\"87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674\\"},{\\"hashedPhoneNumber\\":\\"0506a1f3f4c515fd310fce54d253b731f71e33e7e7d2b10848528ca4411120b0\\"},{\\"addressInfo\\":{\\"hashedFirstName\\":\\"4f23798d92708359b734a18172c9c864f1d48044a754115a0d4b843bca3a5332\\",\\"hashedLastName\\":\\"fd53ef835b15485572a6e82cf470dcb41fd218ae5751ab7531c956a2a6bcd3c7\\",\\"countryCode\\":\\"\\",\\"postalCode\\":\\"\\"}}]}}],\\"enable_warnings\\":true}"`
)
})

it('sends an event with default mappings - syncMode = delete', async () => {
const event = createTestEvent({
timestamp,
Expand Down Expand Up @@ -1531,7 +1592,52 @@ describe('GoogleEnhancedConversions', () => {
})
})

it('Could not deteremine operation type due to invalid event name or syncMode', async () => {
it('treats updated event as add when syncMode = mirror', async () => {
nock(`https://googleads.googleapis.com/${API_VERSION}/customers/${customerId}/offlineUserDataJobs:create`)
.post(/.*/)
.reply(200, { resourceName: 'customers/1234/userLists/1234' })

nock(`https://googleads.googleapis.com/${API_VERSION}/customers/1234/userLists/1234:addOperations`)
.post(/.*/, (body: Record<string, unknown>) => {
const operations = body.operations as Array<Record<string, unknown>>
return operations.every((op) => 'create' in op && !('remove' in op))
})
.reply(200, {})

nock(`https://googleads.googleapis.com/${API_VERSION}/customers/1234/userLists/1234:run`)
Comment thread
varadarajan-tw marked this conversation as resolved.
Outdated
.post(/.*/)
.reply(200, {})

const events: SegmentEvent[] = [
createTestEvent({
timestamp,
event: 'updated',
properties: {
email: '[email protected]',
phone: '3234567890',
firstName: 'Jane',
lastName: 'Doe'
}
})
]

const responses = await testDestination.executeBatch('userList', {
events,
mapping: {
...mapping,
__segment_internal_sync_mode: 'mirror'
},
settings: {
customerId
}
})

expect(responses[0]).toMatchObject({
status: 200
})
})
Comment thread
varadarajan-tw marked this conversation as resolved.

it('Could not determine operation type due to invalid event name or syncMode', async () => {
nock(`https://googleads.googleapis.com/${API_VERSION}/customers/${customerId}/offlineUserDataJobs:create`)
.post(/.*/)
.reply(200, { resourceName: 'customers/1234/userLists/1234' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ const extractUserIdentifiers = (
if (
payload.event_name === 'Audience Entered' ||
syncMode === 'add' ||
(syncMode === 'mirror' && payload.event_name === 'new')
(syncMode === 'mirror' && (payload.event_name === 'new' || payload.event_name === 'updated'))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More improvements for this are on the way with standardized audience membership evaluators

) {
addUserIdentifiers.push({ create: { userIdentifiers: identifierFunctions[idType](payload) } })
} else if (
Expand Down Expand Up @@ -969,7 +969,7 @@ const determineOperationType = (payload: UserListPayload, syncMode?: string) =>
if (
payload.event_name === 'Audience Entered' ||
syncMode === 'add' ||
(syncMode === 'mirror' && payload.event_name === 'new')
(syncMode === 'mirror' && (payload.event_name === 'new' || payload.event_name === 'updated'))
) {
return 'add'
} else if (
Expand Down
Loading