Skip to content

STRATCONN-6051 - [Clay] - New Destination #3092

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

Merged
merged 5 commits into from
Jul 29, 2025
Merged
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
@@ -0,0 +1,64 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for actions-clay destination: pageVisit action - all fields 1`] = `
Object {
"anonymousId": "eu76@B#kao",
"ip": "eu76@B#kao",
"messageId": Any<String>,
"name": "eu76@B#kao",
"page": Object {
"path": "eu76@B#kao",
"referrer": "eu76@B#kao",
"search": "eu76@B#kao",
"title": "eu76@B#kao",
"url": "eu76@B#kao",
},
"properties": Object {
"testType": "eu76@B#kao",
},
"timestamp": Any<String>,
"type": "page",
"userAgent": "eu76@B#kao",
"userId": "eu76@B#kao",
}
`;

exports[`Testing snapshot for actions-clay destination: pageVisit action - required fields 1`] = `
Object {
"ip": "eu76@B#kao",
"messageId": Any<String>,
"type": "page",
}
`;

exports[`Testing snapshot for actions-clay destination: track action - all fields 1`] = `
Object {
"anonymousId": "NHQVrUx(HtHKStZdY",
"event": "NHQVrUx(HtHKStZdY",
"ip": "NHQVrUx(HtHKStZdY",
"messageId": Any<String>,
"page": Object {
"path": "NHQVrUx(HtHKStZdY",
"referrer": "NHQVrUx(HtHKStZdY",
"search": "NHQVrUx(HtHKStZdY",
"title": "NHQVrUx(HtHKStZdY",
"url": "NHQVrUx(HtHKStZdY",
},
"properties": Object {
"testType": "NHQVrUx(HtHKStZdY",
},
"timestamp": Any<String>,
"type": "track",
"userAgent": "NHQVrUx(HtHKStZdY",
"userId": "NHQVrUx(HtHKStZdY",
}
`;

exports[`Testing snapshot for actions-clay destination: track action - required fields 1`] = `
Object {
"event": "NHQVrUx(HtHKStZdY",
"ip": "NHQVrUx(HtHKStZdY",
"messageId": Any<String>,
"type": "track",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import nock from 'nock'
import { createTestIntegration } from '@segment/actions-core'
import Definition, { CLAY_API_BASE_URL } from '../index'

const testDestination = createTestIntegration(Definition)

describe('Clay', () => {
describe('testAuthentication', () => {
it('should validate authentication inputs', async () => {
nock(CLAY_API_BASE_URL).get('/segment/test_connection_key/auth').reply(200, {})

await expect(
testDestination.testAuthentication({
connection_key: 'test_connection_key',
secret_key: 'test_secret_key'
})
).resolves.not.toThrowError()
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import { generateTestData } from '../../../lib/test-data'
import destination from '../index'
import nock from 'nock'

const testDestination = createTestIntegration(destination)
const destinationSlug = 'actions-clay'

describe(`Testing snapshot for ${destinationSlug} destination:`, () => {
for (const actionSlug in destination.actions) {
it(`${actionSlug} action - required fields`, async () => {
const seedName = `${destinationSlug}#${actionSlug}`
const action = destination.actions[actionSlug]
const [eventData, settingsData] = generateTestData(seedName, destination, action, true)

nock(/.*/).persist().get(/.*/).reply(200)
nock(/.*/).persist().post(/.*/).reply(200)
nock(/.*/).persist().put(/.*/).reply(200)

const event = createTestEvent({
properties: eventData
})

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
settings: settingsData,
auth: undefined
})

const request = responses[0].request
const rawBody = await request.text()

try {
const json = JSON.parse(rawBody)
expect(json).toMatchSnapshot({
messageId: expect.any(String)
})
return
} catch (err) {
expect(rawBody).toMatchSnapshot()
}

expect(request.headers).toMatchSnapshot()
})

it(`${actionSlug} action - all fields`, async () => {
const seedName = `${destinationSlug}#${actionSlug}`
const action = destination.actions[actionSlug]
const [eventData, settingsData] = generateTestData(seedName, destination, action, false)

nock(/.*/).persist().get(/.*/).reply(200)
nock(/.*/).persist().post(/.*/).reply(200)
nock(/.*/).persist().put(/.*/).reply(200)

const event = createTestEvent({
properties: eventData
})

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
settings: settingsData,
auth: undefined
})

const request = responses[0].request
const rawBody = await request.text()

try {
const json = JSON.parse(rawBody)
expect(json).toMatchSnapshot({
messageId: expect.any(String),
timestamp: expect.any(String)
})
return
} catch (err) {
expect(rawBody).toMatchSnapshot()
}
})
}
})

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

62 changes: 62 additions & 0 deletions packages/destination-actions/src/destinations/clay/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { DestinationDefinition } from '@segment/actions-core'
import { defaultValues } from '@segment/actions-core'
import type { Settings } from './generated-types'
import pageVisit from './pageVisit'
import track from './track'

export const CLAY_API_BASE_URL = 'https://segment-session.clay.com'

const presets: DestinationDefinition['presets'] = [
{
name: 'Page Visit',
subscribe: 'type = "page"',
partnerAction: 'pageVisit',
mapping: defaultValues(pageVisit.fields),
type: 'automatic'
},
{
name: 'Track Calls',
subscribe: 'type = "track"',
partnerAction: 'track',
mapping: defaultValues(track.fields),
type: 'automatic'
}
]

const destination: DestinationDefinition<Settings> = {
name: 'Clay',
slug: 'actions-clay',
mode: 'cloud',
authentication: {
scheme: 'custom',
fields: {
connection_key: {
label: 'Connection Key',
description: 'Your Clay connection key',
type: 'string',
required: true
},
secret_key: {
label: 'Secret Key',
description: 'Your Clay secret key',
type: 'string',
required: true
}
},
testAuthentication: (request, { settings }) => {
return request(`${CLAY_API_BASE_URL}/segment/${settings.connection_key}/auth`, {
method: 'GET',
headers: {
Authorization: `Bearer ${settings.secret_key}`
}
})
}
},
presets,
actions: {
pageVisit,
track
}
}

export default destination
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for Clay's pageVisit destination action: all fields 1`] = `
Object {
"anonymousId": "zZg8#WaG5V1[W1",
"ip": "zZg8#WaG5V1[W1",
"messageId": Any<String>,
"name": "zZg8#WaG5V1[W1",
"page": Object {
"path": "zZg8#WaG5V1[W1",
"referrer": "zZg8#WaG5V1[W1",
"search": "zZg8#WaG5V1[W1",
"title": "zZg8#WaG5V1[W1",
"url": "zZg8#WaG5V1[W1",
},
"properties": Object {
"testType": "zZg8#WaG5V1[W1",
},
"timestamp": Any<String>,
"type": "page",
"userAgent": "zZg8#WaG5V1[W1",
"userId": "zZg8#WaG5V1[W1",
}
`;

exports[`Testing snapshot for Clay's pageVisit destination action: required fields 1`] = `
Object {
"anonymousId": "anonId1234",
"ip": "zZg8#WaG5V1[W1",
"messageId": Any<String>,
"page": Object {
"path": "/academy/",
"referrer": "",
"search": "",
"title": "Analytics Academy",
"url": "https://segment.com/academy/",
},
"properties": Object {
"ip": "zZg8#WaG5V1[W1",
"messageId": "zZg8#WaG5V1[W1",
},
"timestamp": Any<String>,
"type": "page",
"userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1",
"userId": "user1234",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { createTestIntegration } from '@segment/actions-core'
import nock from 'nock'
import Destination, { CLAY_API_BASE_URL } from '../../index'

const testDestination = createTestIntegration(Destination)

describe('Clay.pageVisit', () => {
it('sends page event to Clay with correct payload', async () => {
nock(CLAY_API_BASE_URL).post('/segment/test_connection_key/events').reply(200, {})

const responses = await testDestination.testAction('pageVisit', {
settings: {
connection_key: 'test_connection_key',
secret_key: 'test_secret_key'
},
mapping: {
type: 'page',
timestamp: '2023-03-03T00:00:00.000Z',
page: {
title: 'Example Page',
url: 'https://example.com/page',
path: '/page',
referrer: 'https://google.com'
},
ip: '192.168.0.1',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36',
anonymousId: 'anonymous_user_123',
userId: 'user_456',
messageId: 'segment_message_789'
}
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
expect((responses[0].options.headers as any)?.get?.('authorization')).toBe('Bearer test_secret_key')

const payload = JSON.parse(responses[0].options.body?.toString() ?? '')
expect(payload).toMatchObject({
type: 'page',
timestamp: '2023-03-03T00:00:00.000Z',
page: {
title: 'Example Page',
url: 'https://example.com/page',
path: '/page',
referrer: 'https://google.com'
},
ip: '192.168.0.1',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36',
anonymousId: 'anonymous_user_123',
userId: 'user_456',
messageId: 'segment_message_789'
})
})

it('handles minimal required fields', async () => {
nock(CLAY_API_BASE_URL).post('/segment/test_connection_key/events').reply(200, {})

const responses = await testDestination.testAction('pageVisit', {
settings: {
connection_key: 'test_connection_key',
secret_key: 'test_secret_key'
},
mapping: {
type: 'page',
ip: '192.168.0.1',
messageId: 'segment_message_minimal'
}
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
expect((responses[0].options.headers as any)?.get?.('authorization')).toBe('Bearer test_secret_key')

const payload = JSON.parse(responses[0].options.body?.toString() ?? '')
expect(payload).toMatchObject({
type: 'page',
ip: '192.168.0.1',
messageId: 'segment_message_minimal'
})
})
})
Loading
Loading