diff --git a/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/userList.test.ts b/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/userList.test.ts index 9a00ad33491..361b214c1a1 100644 --- a/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/userList.test.ts +++ b/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/userList.test.ts @@ -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: 'test@gmail.com', + 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' }) + + nock(`https://googleads.googleapis.com/${API_VERSION}/offlineDataJob:addOperations`) + .post(/.*/) + .reply(200, { data: 'offlineDataJob' }) + + nock(`https://googleads.googleapis.com/${API_VERSION}/offlineDataJob:run`) + .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, @@ -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/${customerId}/userLists/1234:addOperations`) + .post(/.*/, (body: Record) => { + const operations = body.operations as Array> + return operations.every((op) => 'create' in op && !('remove' in op)) + }) + .reply(200, {}) + + nock(`https://googleads.googleapis.com/${API_VERSION}/customers/${customerId}/userLists/1234:run`) + .post(/.*/) + .reply(200, {}) + + const events: SegmentEvent[] = [ + createTestEvent({ + timestamp, + event: 'updated', + properties: { + email: 'test@gmail.com', + 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 + }) + }) + + 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' }) diff --git a/packages/destination-actions/src/destinations/google-enhanced-conversions/functions.ts b/packages/destination-actions/src/destinations/google-enhanced-conversions/functions.ts index 697c16b7c49..725a8aa9605 100644 --- a/packages/destination-actions/src/destinations/google-enhanced-conversions/functions.ts +++ b/packages/destination-actions/src/destinations/google-enhanced-conversions/functions.ts @@ -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')) ) { addUserIdentifiers.push({ create: { userIdentifiers: identifierFunctions[idType](payload) } }) } else if ( @@ -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 (