diff --git a/packages/warehouse-destinations/src/destinations/bigquery/generated-types.ts b/packages/warehouse-destinations/src/destinations/bigquery/generated-types.ts index 4ab2786ec6..0c09b0440f 100644 --- a/packages/warehouse-destinations/src/destinations/bigquery/generated-types.ts +++ b/packages/warehouse-destinations/src/destinations/bigquery/generated-types.ts @@ -1,3 +1,8 @@ // Generated file. DO NOT MODIFY IT BY HAND. -export interface Settings {} +export interface Settings { + /** + * The ID of the existing BigQuery warehouse instance to use. + */ + warehouseId: string +} diff --git a/packages/warehouse-destinations/src/destinations/bigquery/index.ts b/packages/warehouse-destinations/src/destinations/bigquery/index.ts index 872b257362..875d611cca 100644 --- a/packages/warehouse-destinations/src/destinations/bigquery/index.ts +++ b/packages/warehouse-destinations/src/destinations/bigquery/index.ts @@ -1,14 +1,80 @@ +import { defaultValues } from '@segment/actions-core' import type { WarehouseDestinationDefinition } from '@segment/actions-core' import { Settings } from './generated-types' +import sendCustomEvent from './sendCustomEvent' +import journeysDefaultFields from './sendCustomEvent/journeys-default-fields' +import audienceDefaultFields from './sendCustomEvent/audience-default-fields' const destination: WarehouseDestinationDefinition = { name: 'BigQuery', slug: 'bigquery', mode: 'warehouse', - settings: {}, + settings: { + warehouseId: { + label: 'Warehouse ID', + description: 'The ID of the existing BigQuery warehouse instance to use.', + type: 'string', + required: true + } + }, - actions: {} + presets: [ + { + name: 'Linked Audience Entity Added', + partnerAction: 'sendCustomEvent', + mapping: { + ...defaultValues(sendCustomEvent.fields), + ...defaultValues(audienceDefaultFields) + }, + type: 'specificEvent', + eventSlug: 'warehouse_entity_added_track' + }, + { + name: 'Linked Audience Associated Entity Removed', + partnerAction: 'sendCustomEvent', + mapping: { + ...defaultValues(sendCustomEvent.fields), + ...defaultValues(audienceDefaultFields) + }, + type: 'specificEvent', + eventSlug: 'warehouse_entity_removed_track' + }, + { + name: 'Linked Audience Profile Entered', + partnerAction: 'sendCustomEvent', + mapping: { + ...defaultValues(sendCustomEvent.fields), + ...defaultValues(audienceDefaultFields) + }, + type: 'specificEvent', + eventSlug: 'warehouse_audience_entered_track' + }, + { + name: 'Linked Audience Profile Exited', + partnerAction: 'sendCustomEvent', + mapping: { + ...defaultValues(sendCustomEvent.fields), + ...defaultValues(audienceDefaultFields) + }, + type: 'specificEvent', + eventSlug: 'warehouse_audience_exited_track' + }, + { + name: 'Journeys Step Entered', + partnerAction: 'sendCustomEvent', + mapping: { + ...defaultValues(sendCustomEvent.fields), + ...defaultValues(journeysDefaultFields) + }, + type: 'specificEvent', + eventSlug: 'journeys_step_entered_track' + } + ], + + actions: { + sendCustomEvent + } } export default destination diff --git a/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/audience-default-fields.ts b/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/audience-default-fields.ts new file mode 100644 index 0000000000..aa6a0bd600 --- /dev/null +++ b/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/audience-default-fields.ts @@ -0,0 +1,28 @@ +export default { + // note that this must be `properties` to be processed by the warehouse pipeline + properties: { + label: 'Columns', + description: `Additional columns to write to BigQuery.`, + type: 'object', + defaultObjectUI: 'keyvalue', + required: true, + additionalProperties: true, + default: { + entity_context: { + '@json': { + mode: 'encode', + value: { + '@path': '$.properties.data_graph_entity_context' + } + } + }, + user_id: { '@path': '$.userId' }, + audience_key: { '@path': '$.properties.audience_key' }, + personas_computation_key: { '@path': '$.context.personas.computation_key' }, + personas_computation_id: { '@path': '$.context.personas.computation_id' }, + personas_computation_run_id: { '@path': '$.context.personas.computation_run_id' }, + personas_activation_id: { '@path': '$.context.personas.event_emitter_id' }, + event_name: { '@path': '$.event' } + } + } +} diff --git a/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/generated-types.ts b/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/generated-types.ts new file mode 100644 index 0000000000..139d89a2c2 --- /dev/null +++ b/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/generated-types.ts @@ -0,0 +1,26 @@ +// Generated file. DO NOT MODIFY IT BY HAND. + +export interface Payload { + /** + * The name of the table. + */ + event: string + /** + * Additional columns to write to BigQuery. + */ + properties: { + [k: string]: unknown + } + /** + * Name of column for the unique identifier for the message. + */ + messageId: string + /** + * The type of event. + */ + type: string + /** + * Time when event was received. + */ + receivedAt: string | number +} diff --git a/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/index.ts b/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/index.ts new file mode 100644 index 0000000000..5e58c6a5cb --- /dev/null +++ b/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/index.ts @@ -0,0 +1,62 @@ +import { ActionDefinition } from '@segment/actions-core/destination-kit' +import { Settings } from '../generated-types' +import { Payload } from './generated-types' + +const action: ActionDefinition = { + title: 'Send Custom Event', + description: 'Record custom events in BigQuery', + fields: { + event: { + label: 'Table Name', + description: 'The name of the table.', + type: 'string', + required: true, + default: { '@path': '$.event' }, + unsafe_hidden: true + }, + // note that this must be `properties` to be processed by the warehouse pipeline + properties: { + label: 'Columns', + description: `Additional columns to write to BigQuery.`, + type: 'object', + defaultObjectUI: 'keyvalue', + required: true, + additionalProperties: true, + default: { + user_id: { '@path': '$.userId' } + } + }, + // These are all required for data to be processed by the warehouse pipeline + messageId: { + label: 'ID', + description: 'Name of column for the unique identifier for the message.', + type: 'string', + required: true, + default: { '@path': '$.messageId' }, + readOnly: true + }, + type: { + label: 'Event Type', + description: 'The type of event.', + type: 'string', + required: true, + default: { '@path': '$.type' }, + readOnly: true, + // this is required for the warehouse pipeline to process the event, + // but it's removed before being sent to BigQuery + unsafe_hidden: true + }, + receivedAt: { + label: 'Received At', + description: 'Time when event was received.', + type: 'datetime', + required: true, + default: { '@path': '$.receivedAt' } + } + }, + perform: () => { + return undefined + } +} + +export default action diff --git a/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/journeys-default-fields.ts b/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/journeys-default-fields.ts new file mode 100644 index 0000000000..a08bebe613 --- /dev/null +++ b/packages/warehouse-destinations/src/destinations/bigquery/sendCustomEvent/journeys-default-fields.ts @@ -0,0 +1,35 @@ +export default { + // note that this must be `properties` to be processed by the warehouse pipeline + properties: { + label: 'Columns', + description: `Additional columns to write to BigQuery.`, + type: 'object', + defaultObjectUI: 'keyvalue', + required: true, + additionalProperties: true, + default: { + journey_metadata: { + '@json': { + mode: 'encode', + value: { + '@path': '$.properties.journey_metadata' + } + } + }, + journey_context: { + '@json': { + mode: 'encode', + value: { + '@path': '$.properties.journey_context' + } + } + }, + user_id: { '@path': '$.userId' }, + personas_computation_key: { '@path': '$.context.personas.computation_key' }, + personas_computation_id: { '@path': '$.context.personas.computation_id' }, + personas_activation_id: { '@path': '$.context.personas.event_emitter_id' }, + personas_computation_class: { '@path': '$.context.personas.computation_class' }, + event_name: { '@path': '$.event' } + } + } +}