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

Allowing pre-hashed emails for Criteo Audiences. #2681

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,27 @@ const getOperationFromPayload = async (
for (const event of payload) {
let email = undefined

if (!audience_key && event.audience_key)
audience_key = event.audience_key
if (!audience_key && event.audience_key) audience_key = event.audience_key

email = event.hash_emails ? hash(event.email) : event.email
if (email) add_user_list.push(email)
}

const contactlist_id = await getContactListId(request, advertiser_id, audience_key, credentials)
const operation: Operation = {
operation_type: "add",
operation_type: 'add',
contactlist_id: contactlist_id,
user_list: add_user_list,
user_list: add_user_list
}
return operation;
return operation
}

const processPayload = async (
request: RequestClient,
settings: Settings,
payload: Payload[]
): Promise<Response> => {
const processPayload = async (request: RequestClient, settings: Settings, payload: Payload[]): Promise<Response> => {
const credentials: ClientCredentials = {
client_id: settings.client_id,
client_secret: settings.client_secret
}
const operation: Operation = await getOperationFromPayload(request, settings.advertiser_id, payload, credentials);
const operation: Operation = await getOperationFromPayload(request, settings.advertiser_id, payload, credentials)
return await patchContactList(request, operation, credentials)
}

Expand All @@ -58,15 +53,15 @@ const action: ActionDefinition<Settings, Payload> = {
fields: {
audience_key: {
label: 'Audience key',
description: "Unique name for personas audience",
description: 'Unique name for personas audience',
type: 'string',
default: {
'@path': '$.properties.audience_key'
}
},
event: {
label: 'Event name',
description: "Event for audience entering or exiting",
description: 'Event for audience entering or exiting',
type: 'string',
default: {
'@path': '$.event'
Expand All @@ -76,26 +71,25 @@ const action: ActionDefinition<Settings, Payload> = {
label: 'Email',
description: "The user's email",
type: 'string',
format: 'email',
default: {
'@path': '$.context.traits.email'
}
},
hash_emails: {
label: 'Hash Emails',
description: "Hash emails before sending them to Criteo (may lower your audience's match rate). If deactivated, emails will be sent unhashed to Criteo's API and will be hashed upon reception at Criteo's server.",
description:
"Hash emails before sending them to Criteo (may lower your audience's match rate). If deactivated, emails will be sent unhashed to Criteo's API and will be hashed upon reception at Criteo's server.",
type: 'boolean',
default: false,
required: false
},
}
},
perform: async (request, { settings, payload }) => {
return await processPayload(request, settings, [payload])
},

performBatch: async (request, { settings, payload }) => {
return await processPayload(request, settings, payload)

}
}
export default action
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import type { RequestClient } from '@segment/actions-core'


const getOperationFromPayload = async (
request: RequestClient,
advertiser_id: string,
Expand All @@ -18,8 +17,7 @@ const getOperationFromPayload = async (
for (const event of payload) {
let email = undefined

if (!audience_key && event.audience_key)
audience_key = event.audience_key
if (!audience_key && event.audience_key) audience_key = event.audience_key

email = event.hash_emails ? hash(event.email) : event.email
if (email) remove_user_list.push(email)
Expand All @@ -28,24 +26,19 @@ const getOperationFromPayload = async (
const contactlist_id = await getContactListId(request, advertiser_id, audience_key, credentials)

const operation: Operation = {
operation_type: "remove",
operation_type: 'remove',
contactlist_id: contactlist_id,
user_list: remove_user_list,
user_list: remove_user_list
}
return operation;
return operation
}

const processPayload = async (
request: RequestClient,
settings: Settings,
payload: Payload[]
): Promise<Response> => {

const processPayload = async (request: RequestClient, settings: Settings, payload: Payload[]): Promise<Response> => {
const credentials: ClientCredentials = {
client_id: settings.client_id,
client_secret: settings.client_secret
}
const operation: Operation = await getOperationFromPayload(request, settings.advertiser_id, payload, credentials);
const operation: Operation = await getOperationFromPayload(request, settings.advertiser_id, payload, credentials)
return await patchContactList(request, operation, credentials)
}

Expand All @@ -56,15 +49,15 @@ const action: ActionDefinition<Settings, Payload> = {
fields: {
audience_key: {
label: 'Audience key',
description: "Unique name for personas audience",
description: 'Unique name for personas audience',
type: 'string',
default: {
'@path': '$.properties.audience_key'
}
},
event: {
label: 'Event name',
description: "Event for audience entering or exiting",
description: 'Event for audience entering or exiting',
type: 'string',
default: {
'@path': '$.event'
Expand All @@ -74,18 +67,18 @@ const action: ActionDefinition<Settings, Payload> = {
label: 'Email',
description: "The user's email",
type: 'string',
format: 'email',
default: {
'@path': '$.context.traits.email'
}
},
hash_emails: {
label: 'Hash Emails',
description: "Hash emails before sending them to Criteo (may lower your audience's match rate). If deactivated, emails will be sent unhashed to Criteo's API and will be hashed upon reception at Criteo's server.",
description:
"Hash emails before sending them to Criteo (may lower your audience's match rate). If deactivated, emails will be sent unhashed to Criteo's API and will be hashed upon reception at Criteo's server.",
type: 'boolean',
default: false,
required: false
},
}
},
perform: async (request, { settings, payload }) => {
return await processPayload(request, settings, [payload])
Expand All @@ -95,5 +88,4 @@ const action: ActionDefinition<Settings, Payload> = {
}
}


export default action
Loading