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

[algolia-insights] update presets for conversion events #2770

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
@@ -1,4 +1,4 @@
import type { ActionDefinition, Preset } from '@segment/actions-core'
import type { ActionDefinition, BaseActionDefinition, Preset } from '@segment/actions-core'
import { defaultValues } from '@segment/actions-core'
import {
AlgoliaBehaviourURL,
Expand All @@ -11,147 +11,149 @@ import type { Payload } from './generated-types'

const notUndef = (thing: unknown) => typeof thing !== 'undefined'

export const conversionEvents: ActionDefinition<Settings, Payload> = {
title: 'Conversion Events',
description:
'In ecommerce, conversions are purchase events often but not always involving multiple products. Outside of a conversion can be any positive signal associated with an index record. Query ID is optional and indicates that the view events is the result of a search query.',
fields: {
eventSubtype: {
label: 'Event Subtype',
description: 'Sub-type of the event, "purchase" or "addToCart".',
type: 'string',
required: false,
choices: [
{ value: 'purchase', label: 'Purchase' },
{ value: 'addToCart', label: 'Add To Cart' }
],
default: 'purchase'
const getEventFields = (subtype: AlgoliaEventSubtype = 'purchase'): BaseActionDefinition['fields'] => ({
eventSubtype: {
label: 'Event Subtype',
description: 'Sub-type of the event, "purchase" or "addToCart".',
type: 'string',
required: false,
choices: [
{ value: 'purchase', label: 'Purchase' },
{ value: 'addToCart', label: 'Add To Cart' }
],
default: subtype
},
products: {
label: 'Product Details',
description:
'Populates the ObjectIDs field in the Algolia Insights API. An array of objects representing the purchased items. Each object must contain a product_id field.',
type: 'object',
multiple: true,
defaultObjectUI: 'keyvalue',
properties: {
product_id: { label: 'product_id', type: 'string', required: true },
price: { label: 'price', type: 'number', required: false },
quantity: { label: 'quantity', type: 'number', required: false },
discount: { label: 'discount', type: 'number', required: false },
queryID: { label: 'queryID', type: 'string', required: false }
},
products: {
label: 'Product Details',
description:
'Populates the ObjectIDs field in the Algolia Insights API. An array of objects representing the purchased items. Each object must contain a product_id field.',
type: 'object',
multiple: true,
defaultObjectUI: 'keyvalue',
properties: {
product_id: { label: 'product_id', type: 'string', required: true },
price: { label: 'price', type: 'number', required: false },
quantity: { label: 'quantity', type: 'number', required: false },
discount: { label: 'discount', type: 'number', required: false },
queryID: { label: 'queryID', type: 'string', required: false }
},
required: true,
default: {
'@arrayPath': [
'$.properties.products',
{
product_id: {
'@path': '$.product_id'
},
price: {
'@path': '$.price'
},
quantity: {
'@path': '$.quantity'
},
discount: {
'@path': '$.discount'
},
queryID: {
'@path': '$.queryID'
}
required: true,
default: {
'@arrayPath': [
'$.properties.products',
{
product_id: {
'@path': '$.product_id'
},
price: {
'@path': '$.price'
},
quantity: {
'@path': '$.quantity'
},
discount: {
'@path': '$.discount'
},
queryID: {
'@path': '$.queryID'
}
]
}
},
index: {
label: 'Index',
description: 'Name of the targeted search index.',
type: 'string',
required: true,
default: {
'@path': '$.properties.search_index'
}
},
queryID: {
label: 'Query ID',
description: 'Query ID of the list on which the item was purchased.',
type: 'string',
required: false,
default: {
'@if': {
exists: { '@path': '$.properties.query_id' },
then: { '@path': '$.properties.query_id' },
else: { '@path': '$.integrations.Algolia Insights (Actions).query_id' }
}
}
},
userToken: {
type: 'string',
required: true,
description: 'The ID associated with the user.',
label: 'User Token',
default: {
'@if': {
exists: { '@path': '$.userId' },
then: { '@path': '$.userId' },
else: { '@path': '$.anonymousId' }
}
]
}
},
index: {
label: 'Index',
description: 'Name of the targeted search index.',
type: 'string',
required: true,
default: {
'@path': '$.properties.search_index'
}
},
queryID: {
label: 'Query ID',
description: 'Query ID of the list on which the item was purchased.',
type: 'string',
required: false,
default: {
'@if': {
exists: { '@path': '$.properties.query_id' },
then: { '@path': '$.properties.query_id' },
else: { '@path': '$.integrations.Algolia Insights (Actions).query_id' }
}
},
timestamp: {
type: 'string',
required: false,
description: 'The timestamp of the event.',
label: 'Timestamp',
default: { '@path': '$.timestamp' }
},
value: {
type: 'number',
required: false,
description: 'The value of the cart that is being converted.',
label: 'Value',
default: { '@path': '$.properties.value' }
},
currency: {
type: 'string',
required: false,
description:
'Currency of the objects associated with the event in 3-letter ISO 4217 format. Required when `value` or `price` is set.',
label: 'Currency',
default: { '@path': '$.properties.currency' }
},
extraProperties: {
label: 'Extra Properties',
required: false,
description:
'Additional fields for this event. This field may be useful for Algolia Insights fields which are not mapped in Segment.',
type: 'object',
default: {
'@path': '$.properties'
}
},
userToken: {
type: 'string',
required: true,
description: 'The ID associated with the user.',
label: 'User Token',
default: {
'@if': {
exists: { '@path': '$.userId' },
then: { '@path': '$.userId' },
else: { '@path': '$.anonymousId' }
}
},
eventName: {
label: 'Event Name',
description: "The name of the event to send to Algolia. Defaults to 'Conversion Event'",
type: 'string',
required: false,
default: 'Conversion Event'
},
eventType: {
label: 'Event Type',
description: "The type of event to send to Algolia. Defaults to 'conversion'",
type: 'string',
required: false,
default: 'conversion',
choices: [
{ label: 'View', value: 'view' },
{ label: 'Conversion', value: 'conversion' },
{ label: 'Click', value: 'click' }
]
}
},
timestamp: {
type: 'string',
required: false,
description: 'The timestamp of the event.',
label: 'Timestamp',
default: { '@path': '$.timestamp' }
},
value: {
type: 'number',
required: false,
description: 'The value of the cart that is being converted.',
label: 'Value',
default: { '@path': '$.properties.value' }
},
currency: {
type: 'string',
required: false,
description:
'Currency of the objects associated with the event in 3-letter ISO 4217 format. Required when `value` or `price` is set.',
label: 'Currency',
default: { '@path': '$.properties.currency' }
},
extraProperties: {
label: 'Extra Properties',
required: false,
description:
'Additional fields for this event. This field may be useful for Algolia Insights fields which are not mapped in Segment.',
type: 'object',
default: {
'@path': '$.properties'
}
},
eventName: {
label: 'Event Name',
description: "The name of the event to send to Algolia. Defaults to 'Conversion Event'",
type: 'string',
required: false,
default: 'Conversion Event'
},
eventType: {
label: 'Event Type',
description: "The type of event to send to Algolia. Defaults to 'conversion'",
type: 'string',
required: false,
default: 'conversion',
choices: [
{ label: 'View', value: 'view' },
{ label: 'Conversion', value: 'conversion' },
{ label: 'Click', value: 'click' }
]
}
})

export const conversionEvents: ActionDefinition<Settings, Payload> = {
title: 'Conversion Events',
description:
'In ecommerce, conversions are purchase or add-to-cart events often but not always involving multiple products. Outside of ecommerce, a conversion can be any positive signal associated with an index record. Query ID is optional and indicates that the event is the result of a search query.',
fields: getEventFields(),
defaultSubscription: 'type = "track" and event = "Order Completed"',
perform: (request, data) => {
const objectData = data.payload.products.some(({ queryID, price, discount, quantity }) => {
Expand Down Expand Up @@ -188,10 +190,18 @@ export const conversionEvents: ActionDefinition<Settings, Payload> = {
}

/** used in the quick setup */
export const conversionPresets: Preset = {
name: 'Send conversion events to Algolia',
export const purchasePreset: Preset = {
name: 'Send purchase events to Algolia',
subscribe: conversionEvents.defaultSubscription as string,
partnerAction: 'conversionEvents',
mapping: defaultValues(conversionEvents.fields),
type: 'automatic'
}

export const addToCartPreset: Preset = {
name: 'Send add-to-cart events to Algolia',
subscribe: 'type = "track" and event = "Product Added"',
partnerAction: 'conversionEvents',
mapping: defaultValues(getEventFields('addToCart')),
type: 'automatic'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import type { Settings } from './generated-types'

import { productClickedEvents, productClickPresets } from './productClickedEvents'

import { conversionEvents, conversionPresets } from './conversionEvents'
import { conversionEvents, purchasePreset, addToCartPreset } from './conversionEvents'

import { productViewedEvents, productViewedPresets } from './productViewedEvents'
import { AlgoliaApiPermissions, algoliaApiPermissionsUrl } from './algolia-insight-api'

import { productAddedEvents, productAddedPresets } from './productAddedEvents'
import { productAddedEvents } from './productAddedEvents'

import { productListFilteredEvents, productListFilteredPresets } from './productListFilteredEvents'

Expand Down Expand Up @@ -64,9 +64,9 @@ const destination: DestinationDefinition<Settings> = {
type: 'automatic'
},
productClickPresets,
conversionPresets,
purchasePreset,
addToCartPreset,
productViewedPresets,
productAddedPresets,
productListFilteredPresets
],
actions: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { ActionDefinition, Preset } from '@segment/actions-core'
import { defaultValues } from '@segment/actions-core'
import type { ActionDefinition } from '@segment/actions-core'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import { AlgoliaBehaviourURL, AlgoliaConversionEvent, AlgoliaEventType } from '../algolia-insight-api'

export const productAddedEvents: ActionDefinition<Settings, Payload> = {
title: 'Product Added Events',
title: '[Deprecated] Product Added Events',
description:
'Product added events for ecommerce use cases for a customer adding an item to their cart. Query ID is optional and indicates that the event was the result of a search query.',
'Product added events for ecommerce use cases for a customer adding an item to their cart. Query ID is optional and indicates that the event was the result of a search query. **Important** This Action is deprecated. Use the **Conversion Events** Action instead.',
fields: {
product: {
label: 'Product ID',
Expand Down Expand Up @@ -111,11 +110,3 @@ export const productAddedEvents: ActionDefinition<Settings, Payload> = {
})
}
}

export const productAddedPresets: Preset = {
name: 'Send product added events to Algolia',
subscribe: productAddedEvents.defaultSubscription as string,
partnerAction: 'productAddedEvents',
mapping: defaultValues(productAddedEvents.fields),
type: 'automatic'
}
Loading