Skip to content

Commit

Permalink
Add syncMode
Browse files Browse the repository at this point in the history
  • Loading branch information
maryamsharif committed Jul 18, 2024
1 parent 0d665eb commit 282469c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ const formatPhone = (phone: string, hash_data?: boolean): string => {
return sha256SmartHash(formattedPhone)
}

const extractUserIdentifiers = (payloads: UserListPayload[], audienceSettings: AudienceSettings) => {
const extractUserIdentifiers = (payloads: UserListPayload[], audienceSettings: AudienceSettings, syncMode?: string) => {
const removeUserIdentifiers = []
const addUserIdentifiers = []
// Map user data to Google Ads API format
Expand Down Expand Up @@ -395,9 +395,9 @@ const extractUserIdentifiers = (payloads: UserListPayload[], audienceSettings: A
}
// Map user data to Google Ads API format
for (const payload of payloads) {
if (payload.event_name == 'Audience Entered') {
if (payload.event_name == 'Audience Entered' || syncMode == 'add') {
addUserIdentifiers.push(identifierFunctions[audienceSettings.external_id_type](payload))
} else if (payload.event_name == 'Audience Exited') {
} else if (payload.event_name == 'Audience Exited' || syncMode == 'delete') {
removeUserIdentifiers.push(identifierFunctions[audienceSettings.external_id_type](payload))
}
}
Expand Down Expand Up @@ -512,7 +512,8 @@ export const handleUpdate = async (
audienceSettings: CreateAudienceInput['audienceSettings'],
payloads: UserListPayload[],
hookOutputs: string,
statsContext: StatsContext | undefined
syncMode?: string,
statsContext?: StatsContext
) => {
// Format the user data for Google Ads API
const [adduserIdentifiers, removeUserIdentifiers] = extractUserIdentifiers(payloads, audienceSettings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ const action: ActionDefinition<Settings, Payload> = {
title: 'Customer Match User List',
description: 'Sync a Segment Engage Audience into a Google Customer Match User List.',
defaultSubscription: 'event = "Audience Entered" or event = "Audience Exited"',
syncMode: {
description: 'Define how the records will be synced from RETL to Google',
label: 'How to sync records',
default: 'add',
choices: [
{ label: 'Adds users to the connected Google Customer Match User List', value: 'add' },
{ label: 'Remove users from the connected Google Customer Match User List', value: 'delete' }
]
},
fields: {
first_name: {
label: 'First Name',
Expand Down Expand Up @@ -241,24 +250,26 @@ const action: ActionDefinition<Settings, Payload> = {
}
}
},
perform: async (request, { settings, audienceSettings, payload, hookOutputs, statsContext }) => {
perform: async (request, { settings, audienceSettings, payload, hookOutputs, statsContext, syncMode }) => {
hookOutputs?.retlOnMappingSave?.outputs.id
return await handleUpdate(
request,
settings,
audienceSettings,
[payload],
hookOutputs?.retlOnMappingSave?.outputs.id,
syncMode,
statsContext
)
},
performBatch: async (request, { settings, audienceSettings, payload, hookOutputs, statsContext }) => {
performBatch: async (request, { settings, audienceSettings, payload, hookOutputs, statsContext, syncMode }) => {
return await handleUpdate(
request,
settings,
audienceSettings,
payload,
hookOutputs?.retlOnMappingSave?.outputs.id,
syncMode,
statsContext
)
}
Expand Down

0 comments on commit 282469c

Please sign in to comment.