Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customer Match User List Action #2109

Merged
merged 22 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/browser-destinations/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ const unobfuscatedOutput = {
mainFields: ['exports', 'module', 'browser', 'main'],
extensions: ['.ts', '.js'],
fallback: {
vm: require.resolve('vm-browserify')
vm: require.resolve('vm-browserify'),
crypto: false
}
},
devServer: {
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/hashing-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Checks if value is already hashed with sha256 to avoid double hashing
*/
import * as crypto from 'crypto'

const sha256HashedRegex = /^[a-f0-9]{64}$/i

export function sha256SmartHash(value: string): string {
if (sha256HashedRegex.test(value)) {
return value
}
return crypto.createHash('sha256').update(value).digest('hex')
}
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export {
export { get } from './get'
export { omit } from './omit'
export { removeUndefined } from './remove-undefined'
export { sha256SmartHash } from './hashing-utils'
export { time, duration } from './time'

export { realTypeOf, isObject, isArray, isString } from './real-type-of'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import nock from 'nock'
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import GoogleEnhancedConversions from '../index'
import { API_VERSION } from '../functions'

const testDestination = createTestIntegration(GoogleEnhancedConversions)
const timestamp = new Date('Thu Jun 10 2021 11:08:04 GMT-0700 (Pacific Daylight Time)').toISOString()
const customerId = '1234'

describe('GoogleEnhancedConversions', () => {
describe('userList', () => {
it('sends an event with default mappings', async () => {
const event = createTestEvent({
timestamp,
event: 'Audience Entered',
properties: {
gclid: '54321',
email: 'test@gmail.com',
orderId: '1234',
phone: '1234567890',
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',
retlOnMappingSave: {
outputs: {
id: '1234',
name: 'Test List',
external_id_type: 'CONTACT_INFO'
}
}
},
useDefaultMappings: true,
settings: {
customerId
}
})

expect(responses.length).toEqual(3)
expect(responses[0].options.body).toMatchInlineSnapshot(
`"{\\"job\\":{\\"type\\":\\"CUSTOMER_MATCH_USER_LIST\\",\\"customerMatchUserListMetadata\\":{\\"userList\\":\\"customers/1234/userLists/1234\\",\\"consent\\":{\\"adUserData\\":\\"GRANTED\\",\\"adPersonalization\\":\\"GRANTED\\"}}}}"`
)
expect(responses[1].options.body).toMatchInlineSnapshot(
`"{\\"operations\\":[{\\"create\\":{\\"userIdentifiers\\":[{\\"hashedEmail\\":\\"87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674\\"},{\\"hashedPhoneNumber\\":\\"422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8\\"},{\\"addressInfo\\":{\\"hashedFirstName\\":\\"4f23798d92708359b734a18172c9c864f1d48044a754115a0d4b843bca3a5332\\",\\"hashedLastName\\":\\"fd53ef835b15485572a6e82cf470dcb41fd218ae5751ab7531c956a2a6bcd3c7\\",\\"countryCode\\":\\"\\",\\"postalCode\\":\\"\\"}}]}}],\\"enable_warnings\\":true}"`
)
})
})
})
Loading
Loading