Skip to content

Commit e84db52

Browse files
authored
Add Actions and settings for Redshift (#3357)
1 parent 6f4e33b commit e84db52

File tree

6 files changed

+225
-3
lines changed

6 files changed

+225
-3
lines changed

packages/warehouse-destinations/src/destinations/redshift/generated-types.ts

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,80 @@
1+
import { defaultValues } from '@segment/actions-core'
12
import type { WarehouseDestinationDefinition } from '@segment/actions-core'
23
import { Settings } from './generated-types'
4+
import sendCustomEvent from './sendCustomEvent'
5+
import audienceDefaultFields from './sendCustomEvent/audience-default-fields'
6+
import journeysDefaultFields from './sendCustomEvent/journeys-default-fields'
37

48
const destination: WarehouseDestinationDefinition<Settings> = {
59
name: 'Redshift',
610
slug: 'redshift',
711
mode: 'warehouse',
812

9-
settings: {},
13+
settings: {
14+
warehouseId: {
15+
label: 'Warehouse ID',
16+
description: 'The ID of the existing Redshift warehouse instance to use.',
17+
type: 'string',
18+
required: true
19+
}
20+
},
1021

11-
actions: {}
22+
presets: [
23+
{
24+
name: 'Linked Audience Entity Added',
25+
partnerAction: 'sendCustomEvent',
26+
mapping: {
27+
...defaultValues(sendCustomEvent.fields),
28+
...defaultValues(audienceDefaultFields)
29+
},
30+
type: 'specificEvent',
31+
eventSlug: 'warehouse_entity_added_track'
32+
},
33+
{
34+
name: 'Linked Audience Associated Entity Removed',
35+
partnerAction: 'sendCustomEvent',
36+
mapping: {
37+
...defaultValues(sendCustomEvent.fields),
38+
...defaultValues(audienceDefaultFields)
39+
},
40+
type: 'specificEvent',
41+
eventSlug: 'warehouse_entity_removed_track'
42+
},
43+
{
44+
name: 'Linked Audience Profile Entered',
45+
partnerAction: 'sendCustomEvent',
46+
mapping: {
47+
...defaultValues(sendCustomEvent.fields),
48+
...defaultValues(audienceDefaultFields)
49+
},
50+
type: 'specificEvent',
51+
eventSlug: 'warehouse_audience_entered_track'
52+
},
53+
{
54+
name: 'Linked Audience Profile Exited',
55+
partnerAction: 'sendCustomEvent',
56+
mapping: {
57+
...defaultValues(sendCustomEvent.fields),
58+
...defaultValues(audienceDefaultFields)
59+
},
60+
type: 'specificEvent',
61+
eventSlug: 'warehouse_audience_exited_track'
62+
},
63+
{
64+
name: 'Journeys Step Entered',
65+
partnerAction: 'sendCustomEvent',
66+
mapping: {
67+
...defaultValues(sendCustomEvent.fields),
68+
...defaultValues(journeysDefaultFields)
69+
},
70+
type: 'specificEvent',
71+
eventSlug: 'journeys_step_entered_track'
72+
}
73+
],
74+
75+
actions: {
76+
sendCustomEvent
77+
}
1278
}
1379

1480
export default destination
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export default {
2+
// note that this must be `properties` to be processed by the warehouse pipeline
3+
properties: {
4+
label: 'Columns',
5+
description: `Additional columns to write to Redshift.`,
6+
type: 'object',
7+
defaultObjectUI: 'keyvalue',
8+
required: true,
9+
additionalProperties: true,
10+
default: {
11+
entity_context: {
12+
'@json': {
13+
mode: 'encode',
14+
value: {
15+
'@path': '$.properties.data_graph_entity_context'
16+
}
17+
}
18+
},
19+
user_id: { '@path': '$.userId' },
20+
audience_key: { '@path': '$.properties.audience_key' },
21+
personas_computation_key: { '@path': '$.context.personas.computation_key' },
22+
personas_computation_id: { '@path': '$.context.personas.computation_id' },
23+
personas_computation_run_id: { '@path': '$.context.personas.computation_run_id' },
24+
personas_activation_id: { '@path': '$.context.personas.event_emitter_id' },
25+
event_name: { '@path': '$.event' }
26+
}
27+
}
28+
}

packages/warehouse-destinations/src/destinations/redshift/sendCustomEvent/generated-types.ts

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import type { ActionDefinition } from '@segment/actions-core'
2+
import type { Settings } from '../generated-types'
3+
import type { Payload } from './generated-types'
4+
5+
const action: ActionDefinition<Settings, Payload> = {
6+
title: 'Send Custom Event',
7+
description: 'Record custom events in Redshift',
8+
fields: {
9+
event: {
10+
label: 'Table Name',
11+
description: 'The name of the table.',
12+
type: 'string',
13+
required: true,
14+
default: { '@path': '$.event' },
15+
unsafe_hidden: true
16+
},
17+
// note that this must be `properties` to be processed by the warehouse pipeline
18+
properties: {
19+
label: 'Columns',
20+
description: `Additional columns to write to Redshift.`,
21+
type: 'object',
22+
defaultObjectUI: 'keyvalue',
23+
required: true,
24+
additionalProperties: true,
25+
default: {
26+
user_id: { '@path': '$.userId' }
27+
}
28+
},
29+
// These are all required for data to be processed by the warehouse pipeline
30+
messageId: {
31+
label: 'ID',
32+
description: 'Name of column for the unique identifier for the message.',
33+
type: 'string',
34+
required: true,
35+
default: { '@path': '$.messageId' },
36+
readOnly: true
37+
},
38+
type: {
39+
label: 'Event Type',
40+
description: 'The type of event.',
41+
type: 'string',
42+
required: true,
43+
default: { '@path': '$.type' },
44+
readOnly: true,
45+
// this is required for the warehouse pipeline to process the event,
46+
// but it's removed before being sent to Redshift
47+
unsafe_hidden: true
48+
},
49+
receivedAt: {
50+
label: 'Received At',
51+
description: 'Time when event was received.',
52+
type: 'datetime',
53+
required: true,
54+
default: { '@path': '$.receivedAt' }
55+
}
56+
},
57+
perform: () => {
58+
return undefined
59+
}
60+
}
61+
62+
export default action
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export default {
2+
// note that this must be `properties` to be processed by the warehouse pipeline
3+
properties: {
4+
label: 'Columns',
5+
description: `Additional columns to write to Redshift.`,
6+
type: 'object',
7+
defaultObjectUI: 'keyvalue',
8+
required: true,
9+
additionalProperties: true,
10+
default: {
11+
journey_metadata: {
12+
'@json': {
13+
mode: 'encode',
14+
value: {
15+
'@path': '$.properties.journey_metadata'
16+
}
17+
}
18+
},
19+
journey_context: {
20+
'@json': {
21+
mode: 'encode',
22+
value: {
23+
'@path': '$.properties.journey_context'
24+
}
25+
}
26+
},
27+
user_id: { '@path': '$.userId' },
28+
personas_computation_key: { '@path': '$.context.personas.computation_key' },
29+
personas_computation_id: { '@path': '$.context.personas.computation_id' },
30+
personas_activation_id: { '@path': '$.context.personas.event_emitter_id' },
31+
personas_computation_class: { '@path': '$.context.personas.computation_class' },
32+
event_name: { '@path': '$.event' }
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)