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

Subscribe to more events (Redo without required type) #986

Merged
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
Expand Up @@ -19,7 +19,6 @@ Object {
exports[`Testing snapshot for actions-heap destination: trackEvent action - all fields 1`] = `
Object {
"app_id": "kFJwrNh$DP38FB",
"event": "kFJwrNh$DP38FB",
"idempotency_key": "kFJwrNh$DP38FB",
"identity": "kFJwrNh$DP38FB",
"properties": Object {
Expand All @@ -33,7 +32,6 @@ Object {
exports[`Testing snapshot for actions-heap destination: trackEvent action - required fields 1`] = `
Object {
"app_id": "kFJwrNh$DP38FB",
"event": "kFJwrNh$DP38FB",
"idempotency_key": "kFJwrNh$DP38FB",
"identity": "kFJwrNh$DP38FB",
"properties": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import identifyUser from './identifyUser'
const presets: DestinationDefinition['presets'] = [
{
name: 'Track Calls',
subscribe: 'type = "track"',
subscribe: 'type = "track" or type = "page" or type = "screen"',
partnerAction: 'trackEvent',
mapping: defaultValues(trackEvent.fields)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
exports[`Testing snapshot for Heap's trackEvent destination action: all fields 1`] = `
Object {
"app_id": "xqYHVWXiU0In",
"event": "xqYHVWXiU0In",
"idempotency_key": "xqYHVWXiU0In",
"identity": "xqYHVWXiU0In",
"properties": Object {
Expand All @@ -17,7 +16,6 @@ Object {
exports[`Testing snapshot for Heap's trackEvent destination action: required fields 1`] = `
Object {
"app_id": "xqYHVWXiU0In",
"event": "xqYHVWXiU0In",
"idempotency_key": "xqYHVWXiU0In",
"identity": "xqYHVWXiU0In",
"properties": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,29 @@ describe('Heap.trackEvent', () => {
expect(responses[0].status).toBe(200)
expect(responses[0].data).toMatchObject({})
})

it('should get event field for different event type', async () => {
const event: Partial<SegmentEvent> = createTestEvent({
timestamp,
event: undefined,
userId,
messageId,
name: 'Home Page',
type: 'page'
})
body.identity = userId
body.event = 'Home Page'
nock('https://heapanalytics.com').post('/api/track', body).reply(200, body)

const responses = await testDestination.testAction('trackEvent', {
event,
useDefaultMappings: true,
settings: {
appId: HEAP_TEST_APP_ID
}
})
expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
expect(responses[0].data).toEqual(expect.objectContaining({ event: 'Home Page' }))
})
})

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
Expand Up @@ -11,7 +11,7 @@ type HeapEvent = {
app_id: string
identity?: string
user_id?: number
event: string
event: string | undefined
properties: {
[k: string]: unknown
}
Expand All @@ -22,7 +22,7 @@ type HeapEvent = {
const action: ActionDefinition<Settings, Payload> = {
title: 'Track Event',
description: 'Send an event to Heap.',
defaultSubscription: 'type = "track"',
defaultSubscription: 'type = "track" or type = "page" or type = "screen"',
fields: {
message_id: {
label: 'Message ID',
Expand Down Expand Up @@ -53,10 +53,9 @@ const action: ActionDefinition<Settings, Payload> = {
}
},
event: {
label: 'Event Type',
label: 'Track Event Type',
type: 'string',
description: 'The name of the event. Limited to 1024 characters.',
required: true,
description: 'Name of the user action. This only exists on track events. Limited to 1024 characters.',
default: {
'@path': '$.event'
}
Expand Down Expand Up @@ -85,6 +84,22 @@ const action: ActionDefinition<Settings, Payload> = {
default: {
'@path': '$.context.library.name'
}
},
type: {
label: 'Type',
type: 'string',
description: 'The type of call. Can be track, page, or screen.',
default: {
'@path': '$.type'
}
},
name: {
label: 'Page or Screen Name',
type: 'string',
description: 'The name of the page or screen being viewed. This only exists for page and screen events.',
default: {
'@path': '$.name'
}
}
},
perform: (request, { payload, settings }) => {
Expand All @@ -101,7 +116,7 @@ const action: ActionDefinition<Settings, Payload> = {
const eventProperties = Object.assign(defaultEventProperties, flatten)
const event: HeapEvent = {
app_id: settings.appId,
event: payload.event,
event: getEventName(payload),
properties: eventProperties,
idempotency_key: payload.message_id
}
Expand All @@ -125,4 +140,16 @@ const action: ActionDefinition<Settings, Payload> = {
}
}

const getEventName = (payload: Payload) => {
switch (payload.type) {
case 'track':
return payload.event
case 'page':
case 'screen':
return payload.name
default:
return undefined
}
}

export default action