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

Rajul/dv360 add to list device and contact info actions #2389

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"name": "Start dev server",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "yarn",
"runtimeArgs": ["server", "dev"],
"runtimeArgs": ["serve", "dev"],
"restart": true,
"console": "integratedTerminal",
"port": 47082,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pandas as pd

# Load the CSV files
file1 = 'Documents/Google Conversion IDs Sept 2024.csv'
file2 = 'Downloads/Rajul Query.csv'

# Read the CSV files into DataFrames
df1 = pd.read_csv(file1)
df2 = pd.read_csv(file2)

# Combine the DataFrames based on a common column (e.g., 'id')
# You can use 'inner', 'outer', 'left', or 'right' joins based on your needs
combined_df = pd.merge(df1, df2, on='SOURCE_ID', how='inner')

# Save the combined DataFrame to a new CSV file
combined_df.to_csv('combined_file.csv', index=False)

print("Files combined successfully!")
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
import nock from 'nock'
import { createTestEvent, createTestIntegration, IntegrationError } from '@segment/actions-core'
import Destination from '../index'

const audienceName = 'Test Audience'
const testDestination = createTestIntegration(Destination)

const createAudienceInput = {
settings: {},
audienceName: audienceName,
audienceSettings: { // Using audienceSettings as specified
advertiserId: '12345',
audienceType: 'CUSTOMER_MATCH_CONTACT_INFO',
membershipDurationDays: '30',
token: 'temp-token',
description: 'Test description',
},
}

const getAudienceInput = {
settings: {},
audienceSettings: {
advertiserId: '12345',
token: 'temp-token',
},
externalId: 'audience-id-123',
}

//Create Audience Tests

describe('Audience Destination', () => {
describe('createAudience', () => {
it('creates an audience successfully', async () => {
nock('https://displayvideo.googleapis.com')
.post('/v3/firstAndThirdPartyAudiences?advertiserId=12345', {
displayName: audienceName,
audienceType: 'CUSTOMER_MATCH_CONTACT_INFO',
membershipDurationDays: '30',
description: 'Test description',
audienceSource: 'AUDIENCE_SOURCE_UNSPECIFIED',
firstAndThirdPartyAudienceType: 'FIRST_AND_THIRD_PARTY_AUDIENCE_TYPE_FIRST_PARTY',
})
.matchHeader('Authorization', 'Bearer temp-token')
.reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' })

const result = await testDestination.createAudience(createAudienceInput)
expect(result).toEqual({ externalId: 'audience-id-123' })
})

it('errors out when no audience name is provided', async () => {
createAudienceInput.audienceName = ''

await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError(IntegrationError)
})

it('errors out when no advertiser ID is provided', async () => {
createAudienceInput.audienceSettings.advertiserId = ''

await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError(IntegrationError)
})

it('errors out when no audience type is provided', async () => {
createAudienceInput.audienceSettings.audienceType = ''

await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError(IntegrationError)
})

it('errors out when no membership duration days is provided', async () => {
createAudienceInput.audienceSettings.membershipDurationDays = ''

await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError(IntegrationError)
})
})

//Get Audience Tests

describe('getAudience', () => {
it('should succeed when provided with a valid audience ID', async () => {
nock('https://displayvideo.googleapis.com')
.get(`/v3/firstAndThirdPartyAudiences/audience-id-123?advertiserId=12345`)
.matchHeader('Authorization', 'Bearer temp-token')
.reply(200, {
firstAndThirdPartyAudienceId: 'audience-id-123',
})

const result = await testDestination.getAudience(getAudienceInput)
expect(result).toEqual({ externalId: 'audience-id-123' })
})

it('should fail when the audience ID is missing', async () => {
const missingIdInput = {
...getAudienceInput,
externalId: '', // Simulate missing audience ID
}

await expect(testDestination.getAudience(missingIdInput)).rejects.toThrowError(
new IntegrationError('Failed to retrieve audience ID value', 'MISSING_REQUIRED_FIELD', 400)
)
})
})
})

//Payloads for editing customer match list

const payloadContactInfo = {
emails: '[email protected]',
phoneNumbers: '1234567890',
zipCodes: '12345',
firstName: 'John',
lastName: 'Doe',
countryCode: '+1'
}

const payloadDeviceId = {
mobileDeviceIds: '123'
}

//Edit Customer Match Members - Contact Info List

describe('Edit Customer Match Members - Contact Info List', () => {
const event = createTestEvent({
event: 'Audience Entered',
type: 'track',
properties: {},
context: {
traits: payloadContactInfo,
personas: {
external_audience_id: 'audience-id-123',
audience_settings: {
advertiserId: "12345",
token: 'temp-token'
}
}
},
})
it('should add customer match members successfully', async () => {
nock('https://displayvideo.googleapis.com')
.post('/v3/firstAndThirdPartyAudiences/audience-id-123:editCustomerMatchMembers', {
advertiserId: '12345',
addedContactInfoList: {
contactInfos: [{
hashedEmails: '87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674',
hashedPhoneNumbers: 'c775e7b757ede630cd0aa1113bd102661ab38829ca52a6422ab782862f268646',
zipCodes: '12345',
hashedFirstName: '96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a',
hashedLastName: '799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f',
countryCode: '+1',
}],
consent: {
adUserData: 'CONSENT_STATUS_GRANTED',
adPersonalization: 'CONSENT_STATUS_GRANTED'
}
}
})
.matchHeader('Authorization', 'Bearer temp-token')
.reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' });
const result = await testDestination.testAction('addToAudContactInfo', {
event,
useDefaultMappings: true
})
expect(result).toContainEqual(expect.objectContaining({
data: expect.objectContaining({
firstAndThirdPartyAudienceId: 'audience-id-123',
})
}))
})
it('should remove customer match members successfully', async () => {
nock('https://displayvideo.googleapis.com')
.post('/v3/firstAndThirdPartyAudiences/audience-id-123:editCustomerMatchMembers', {
advertiserId: '12345',
removedContactInfoList: {
contactInfos: [{
hashedEmails: '87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674',
hashedPhoneNumbers: 'c775e7b757ede630cd0aa1113bd102661ab38829ca52a6422ab782862f268646',
zipCodes: '12345',
hashedFirstName: '96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a',
hashedLastName: '799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f',
countryCode: '+1',
}],
consent: {
adUserData: 'CONSENT_STATUS_GRANTED',
adPersonalization: 'CONSENT_STATUS_GRANTED'
}
}
})
.matchHeader('Authorization', 'Bearer temp-token')
.reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' });
const result = await testDestination.testAction('removeFromAudContactInfo', {
event,
useDefaultMappings: true
})
expect(result).toContainEqual(expect.objectContaining({
data: expect.objectContaining({
firstAndThirdPartyAudienceId: 'audience-id-123',
})
}))
})

})

//Edit Customer Match Members - Mobile Device ID List

describe('Edit Customer Match Members - Mobile Device ID List', () => {
const event = createTestEvent({
event: 'Audience Entered',
type: 'track',
properties: {},
context: {
traits: payloadDeviceId,
personas: {
external_audience_id: 'audience-id-123',
audience_settings: {
advertiserId: "12345",
token: 'temp-token'
}
}
},
})
it('should remove customer match members successfully', async () => {
nock('https://displayvideo.googleapis.com')
.post('/v3/firstAndThirdPartyAudiences/audience-id-123:editCustomerMatchMembers', {
advertiserId: '12345',
addedMobileDeviceIdList: {
mobileDeviceIds: ['123'],
consent: {
adUserData: 'CONSENT_STATUS_GRANTED',
adPersonalization: 'CONSENT_STATUS_GRANTED'
}
}
})
.matchHeader('Authorization', 'Bearer temp-token')
.reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' });
console.log("event:", event)
const result = await testDestination.testAction('addToAudMobileDeviceId', {
event,
useDefaultMappings: true
})
expect(result).toContainEqual(expect.objectContaining({
data: expect.objectContaining({
firstAndThirdPartyAudienceId: 'audience-id-123',
})
}))
})
it('should remove customer match members successfully', async () => {
nock('https://displayvideo.googleapis.com')
.post('/v3/firstAndThirdPartyAudiences/audience-id-123:editCustomerMatchMembers', {
advertiserId: '12345',
removedMobileDeviceIdList: {
mobileDeviceIds: ['123'],
consent: {
adUserData: 'CONSENT_STATUS_GRANTED',
adPersonalization: 'CONSENT_STATUS_GRANTED'
}
}
})
.matchHeader('Authorization', 'Bearer temp-token')
.reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' });
const result = await testDestination.testAction('removeFromAudMobileDeviceId', {
event,
useDefaultMappings: true
})
expect(result).toContainEqual(expect.objectContaining({
data: expect.objectContaining({
firstAndThirdPartyAudienceId: 'audience-id-123',
})
}))
})

})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { ActionDefinition } from '@segment/actions-core'
import type { AudienceSettings, Settings } from '../generated-types'
import type { Payload } from './generated-types'
import { emails, phoneNumbers, zipCodes, firstName, lastName, countryCode, external_id, advertiser_id } from '../properties'
import { editContactInfo } from '../functions'

const action: ActionDefinition<Settings, Payload, AudienceSettings> = {
title: 'Edit Customer Match Members - Contact Info List',
description: 'Add or update customer match members in Google Display & Video 360 Contact Info List Audience.',
defaultSubscription: 'event = "Audience Entered"',
fields: {
emails: { ...emails },
phoneNumbers: { ...phoneNumbers },
zipCodes: { ...zipCodes },
firstName: { ...firstName },
lastName: { ...lastName },
countryCode: { ...countryCode },
external_id: { ...external_id },
advertiser_id: { ...advertiser_id }
},
perform: async (request, { payload, statsContext }) => {
statsContext?.statsClient?.incr('editCustomerMatchMembers', 1, statsContext?.tags)
return editContactInfo(request, [payload], 'add', statsContext)
},
performBatch: async (request, { payload, statsContext }) => {
statsContext?.statsClient?.incr('editCustomerMatchMembers.batch', 1, statsContext?.tags)
return editContactInfo(request, payload, 'add', statsContext)
}
}

export default action

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading