diff --git a/packages/destination-actions/src/destinations/heap/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/heap/__tests__/__snapshots__/snapshot.test.ts.snap index d94e6cc065..3c20756a85 100644 --- a/packages/destination-actions/src/destinations/heap/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/heap/__tests__/__snapshots__/snapshot.test.ts.snap @@ -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 { @@ -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 { diff --git a/packages/destination-actions/src/destinations/heap/index.ts b/packages/destination-actions/src/destinations/heap/index.ts index 15e9dde925..1ece2f8e57 100644 --- a/packages/destination-actions/src/destinations/heap/index.ts +++ b/packages/destination-actions/src/destinations/heap/index.ts @@ -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) }, diff --git a/packages/destination-actions/src/destinations/heap/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/heap/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap index f07f0a71af..b806d0d773 100644 --- a/packages/destination-actions/src/destinations/heap/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/heap/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap @@ -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 { @@ -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 { diff --git a/packages/destination-actions/src/destinations/heap/trackEvent/__tests__/index.test.ts b/packages/destination-actions/src/destinations/heap/trackEvent/__tests__/index.test.ts index 70d065bee9..1a93a4f2bf 100644 --- a/packages/destination-actions/src/destinations/heap/trackEvent/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/heap/trackEvent/__tests__/index.test.ts @@ -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 = 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' })) + }) }) diff --git a/packages/destination-actions/src/destinations/heap/trackEvent/generated-types.ts b/packages/destination-actions/src/destinations/heap/trackEvent/generated-types.ts index d79f03f412..1e3986ca46 100644 --- a/packages/destination-actions/src/destinations/heap/trackEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/heap/trackEvent/generated-types.ts @@ -14,9 +14,9 @@ export interface Payload { */ anonymous_id?: string | null /** - * The name of the event. Limited to 1024 characters. + * Name of the user action. This only exists on track events. Limited to 1024 characters. */ - event: string + event?: string /** * An object with key-value properties you want associated with the event. Each key and property must either be a number or string with fewer than 1024 characters. */ @@ -31,4 +31,12 @@ export interface Payload { * The name of the SDK used to send events */ library_name?: string + /** + * The type of call. Can be track, page, or screen. + */ + type?: string + /** + * The name of the page or screen being viewed. This only exists for page and screen events. + */ + name?: string } diff --git a/packages/destination-actions/src/destinations/heap/trackEvent/index.ts b/packages/destination-actions/src/destinations/heap/trackEvent/index.ts index d23983eb20..ceda53c52d 100644 --- a/packages/destination-actions/src/destinations/heap/trackEvent/index.ts +++ b/packages/destination-actions/src/destinations/heap/trackEvent/index.ts @@ -11,7 +11,7 @@ type HeapEvent = { app_id: string identity?: string user_id?: number - event: string + event: string | undefined properties: { [k: string]: unknown } @@ -22,7 +22,7 @@ type HeapEvent = { const action: ActionDefinition = { 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', @@ -53,10 +53,9 @@ const action: ActionDefinition = { } }, 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' } @@ -85,6 +84,22 @@ const action: ActionDefinition = { 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 }) => { @@ -101,7 +116,7 @@ const action: ActionDefinition = { 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 } @@ -125,4 +140,16 @@ const action: ActionDefinition = { } } +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