Skip to content

Commit

Permalink
Added stats for listId to see the whether entire batch has same listI…
Browse files Browse the repository at this point in the history
…d or not (#2616)

Co-authored-by: Gaurav Kochar <[email protected]>
  • Loading branch information
Innovative-GauravKochar and Gaurav Kochar authored Dec 3, 2024
1 parent 23e031d commit 9d46f95
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const action: ActionDefinition<Settings, Payload> = {
const profileId = await createProfile(request, email, external_id, phone_number, additionalAttributes)
return await addProfileToList(request, profileId, list_id)
},
performBatch: async (request, { payload }) => {
performBatch: async (request, { payload, statsContext, features }) => {
// Filtering out profiles that do not contain either an email, external_id or valid phone number.
payload = payload.filter((profile) => {
// Validate and convert the phone number using the provided country code
Expand All @@ -80,6 +80,16 @@ const action: ActionDefinition<Settings, Payload> = {
}
return profile.email || profile.external_id || profile.phone_number
})
const statsClient = statsContext?.statsClient
const tags = statsContext?.tags

if (features && features['klaviyo-list-id']) {
const set = new Set()
payload.forEach((profile) => {
set.add(profile.list_id)
})
statsClient?.histogram(`klaviyo_list_id`, set.size, tags)
}
const listId = payload[0]?.list_id
const importJobPayload = createImportJobPayload(payload, listId)
return sendImportJobRequest(request, importJobPayload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const action: ActionDefinition<Settings, Payload> = {
)
return await removeProfileFromList(request, profileIds, list_id)
},
performBatch: async (request, { payload }) => {
performBatch: async (request, { payload, features, statsContext }) => {
// Filtering out profiles that do not contain either an email, valid phone_number or external_id.
const filteredPayload = payload.filter((profile) => {
// Validate and convert the phone number using the provided country code
Expand All @@ -81,6 +81,17 @@ const action: ActionDefinition<Settings, Payload> = {
}
return profile.email || profile.external_id || profile.phone_number
})
const statsClient = statsContext?.statsClient
const tags = statsContext?.tags

if (features && features['klaviyo-list-id']) {
const set = new Set()
payload.forEach((profile) => {
set.add(profile.list_id)
})
statsClient?.histogram(`klaviyo_list_id`, set.size, tags)
}

const listId = filteredPayload[0]?.list_id
const emails = filteredPayload.map((profile) => profile.email).filter((email) => email) as string[]
const externalIds = filteredPayload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const action: ActionDefinition<Settings, Payload> = {
json: subData
})
},
performBatch: async (request, { payload }) => {
performBatch: async (request, { payload, statsContext, features }) => {
// remove payloads that have niether email or phone_number
const filteredPayload = payload.filter((profile) => {
// Validate and convert the phone number using the provided country code
Expand Down Expand Up @@ -137,6 +137,16 @@ const action: ActionDefinition<Settings, Payload> = {
'Exceeded maximum allowed batches due to unique list_id and custom_source pairings'
)
}
const statsClient = statsContext?.statsClient
const tags = statsContext?.tags

if (features && features['klaviyo-list-id']) {
const set = new Set()
payload.forEach((profile) => {
set.add(profile.list_id)
})
statsClient?.histogram(`klaviyo_list_id`, set.size, tags)
}
const requests: Promise<ModifiedResponse<Response>>[] = []
batches.forEach((key) => {
const { list_id, custom_source, profiles } = sortedProfilesObject[key]
Expand Down

0 comments on commit 9d46f95

Please sign in to comment.