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

Destination for Kevel Audience #1902

Closed
wants to merge 5 commits into from
Closed
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

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,67 @@
import type { DestinationDefinition } from '@segment/actions-core'
import type { Settings } from './generated-types'

import syncKevelAudience from './syncKevelAudience'

const destination: DestinationDefinition<Settings> = {
name: 'Kevel Audience (Actions)',
slug: 'actions-kevel-audience',
description:
"Share Segment user attributes and Segment Audiences from `track` and `identify` events to Kevel Audience using Kevel Audience tracking events and sharing data as `customFields`. By configuring Kevel Audience user attributes, this data can then be made available on the user's profile. Only users with a Segment userId will be synced.",
mode: 'cloud',

authentication: {
scheme: 'custom',
fields: {
audienceDomain: {
label: 'Kevel Audience Domain',
description: 'Your Kevel Audience root subdomain. Example: "cdp.yourdomain.com".',
type: 'string',
required: true
},
userIdType: {
label: 'Kevel Audience user ID Type to map your Segment ID to',
description: 'The Kevel Audience User ID Type to use. Example: "crm".',
type: 'string',
required: true
},
clientId: {
label: 'Kevel Audience client ID',
description: 'The Kevel Audience client ID to identify the event. Example: "brand-name".',
type: 'string',
required: true
},
siteId: {
label: 'Kevel Audience site ID',
description: 'The Kevel Audience site ID to identify the event. Example: "segment-app".',
type: 'string',
required: true
},
apiKey: {
label: 'Kevel Audience API Key',
description:
'The Kevel Audience API Key to authorize the requests. Get yours from your Customer Success representative.',
type: 'string',
required: true
},
eventType: {
label: 'Event Type',
description: 'The type of event to send to Kevel Audience. Example: "segmentSync".',
type: 'string',
required: true
}
}
},
extendRequest() {
return {
headers: {
'Content-Type': 'application/json'
}
}
},
actions: {
syncKevelAudience
}
}

export default destination
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import nock from 'nock'
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import Destination from '../../index'

const testDestination = createTestIntegration(Destination)

const goodTrackEvent = createTestEvent({
type: 'track',
userId: 'uid1',
context: {
personas: {
computation_class: 'audience',
computation_key: 'kevel_segment_test_name'
},
traits: {
email: 'test@email.com'
}
},
properties: {
audience_key: 'kevel_segment_test_name',
kevel_segment_test_name: true
}
})

const goodIdentifyEvent = createTestEvent({
type: 'identify',
userId: 'uid1',
context: {
personas: {
computation_class: 'audience',
computation_key: 'kevel_segment_test_name'
}
},
traits: {
audience_key: 'kevel_segment_test_name',
kevel_segment_test_name: true
},
properties: undefined
})

describe('KevelAuddience.syncKevelAudience', () => {
it('should not throw an error if the audience creation succeed - track', async () => {
const baseUrl = 'https://tr.domain.brand.com/'

nock(baseUrl)
.post('/events/server', (body) => body.customData.kevel_segment_test_name === true)
.reply(200)

await expect(
testDestination.testAction('syncKevelAudience', {
event: goodTrackEvent,
settings: {
audienceDomain: 'domain.brand.com',
userIdType: 'email_sha256',
apiKey: 'api_key',
clientId: 'client_id',
siteId: 'site_id',
eventType: 'segmentSync'
},
useDefaultMappings: true
})
).resolves.not.toThrowError()
})

it('should not throw an error if the audience creation succeed - identify', async () => {
const baseUrl = 'https://tr.domain.brand.com'

nock(baseUrl)
.post('/events/server', (body) => body.customData.kevel_segment_test_name === true)
.reply(200)

await expect(
testDestination.testAction('syncKevelAudience', {
event: goodIdentifyEvent,
settings: {
audienceDomain: 'domain.brand.com',
userIdType: 'email_sha256',
apiKey: 'api_key',
clientId: 'client_id',
siteId: 'site_id',
eventType: 'segmentSync'
},
useDefaultMappings: true
})
).resolves.not.toThrowError()
})
})

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,55 @@
import type { ActionDefinition } from '@segment/actions-core'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'

const action: ActionDefinition<Settings, Payload> = {
title: 'Sync with Kevel Audience',
description:
"Share Segment user attributes and Segment Audiences from `track` and `identify` events to Kevel Audience using Kevel Audience tracking events and sharing data as `customFields`. By configuring Kevel Audience user attributes, this data can then be made available on the user's profile. Only users with a Segment userId will be synced.",
defaultSubscription: 'type = "track" or type = "identify"',
fields: {
segment_user_id: {
label: 'User ID',
description: "The user's unique ID",
type: 'string',
unsafe_hidden: true,
required: true,
default: { '@path': '$.userId' }
},
traits_or_props: {
label: 'Traits or properties object',
description: 'A computed object for track and identify events. This field should not need to be edited.',
type: 'object',
required: true,
unsafe_hidden: true,
default: {
'@if': {
exists: { '@path': '$.properties' },
then: { '@path': '$.properties' },
else: { '@path': '$.traits' }
}
}
}
},
perform: async (request, data) => {
const baseUrl = `https://tr.${data.settings.audienceDomain}/events/server` // TODO event tracker
const payload = {
clientId: data.settings.clientId,
siteId: data.settings.siteId,
type: 'custom',
customType: data.settings.eventType,
user: {
type: data.settings.userIdType,
id: data.payload.segment_user_id
},
customData: data.payload.traits_or_props
}

return request(`${baseUrl}`, {
json: payload,
method: 'POST'
})
}
}

export default action
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import syncAudience from './syncAudience'
import syncTraits from './syncTraits'

const destination: DestinationDefinition<Settings> = {
name: 'Kevel (Actions)',
slug: 'actions-kevel',
name: 'Kevel UserDB (Actions)',
slug: 'actions-kevel-userdb',
description:
'Send Segment user profiles and Segment Audiences to Kevel. Only users with a Segment userId will be synced.',
'Send Segment user profiles and Segment Audiences to Kevel UserDB for campaign targeting. Only users with a Segment userId will be synced.',
mode: 'cloud',

authentication: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Kevel.syncAudience', () => {
).resolves.not.toThrowError()
})

it('should not throw an error if the audience creation succeed - track', async () => {
it('should not throw an error if the audience creation succeed - identify', async () => {
const userId = 'uid1'
const networkId1 = 'networkId1'
const baseUrl = `https://e-${networkId1}.adzerk.net/udb/${networkId1}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { Payload } from './generated-types'

const action: ActionDefinition<Settings, Payload> = {
title: 'Sync Audience',
description: 'Sync a Segment Engage Audience to a Kevel Segment. Only users with a Segment userId will be synced.',
description:
'Sync a Segment Engage Audience to a Kevel UserDB Interest. Only users with a Segment userId will be synced. Read the [documentation for more details](https://dev.kevel.com/reference/add-interest-to-user).',
defaultSubscription: 'type = "track" or type = "identify"',
fields: {
segment_computation_key: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { Payload } from './generated-types'

const action: ActionDefinition<Settings, Payload> = {
title: 'Sync Traits',
description: 'Sync user profile traits from Segment to Kevel',
description:
'Sync user profile traits and segments from Segment to Kevel UserDB using `customProperties`. Read the [documentation for more details](https://dev.kevel.com/reference/set-custom-properties-alternative).',
defaultSubscription: 'type = "identify"',
fields: {
segment_user_id: {
Expand Down
Loading