Skip to content

Commit

Permalink
Optimizely data platform changes (#1906)
Browse files Browse the repository at this point in the history
* changes to ODP Destination

* fixing tests

* adding campaign_id to email action

* fixing preset
  • Loading branch information
joe-ayoub-segment authored Mar 5, 2024
1 parent e0a5d6b commit 82a80b9
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Object {
],
"timestamp": "p$KWIG5p0vR(@gNw)lv@",
"total": "p$KWIG5p0vR(@gNw)lv@",
"type": "p$KWIG5p0vR(@gNw)lv@",
"user_identifiers": Object {
"anonymousId": "p$KWIG5p0vR(@gNw)lv@",
"email": "agijit@cove.ly",
Expand All @@ -26,6 +27,7 @@ Object {
"action": "p$KWIG5p0vR(@gNw)lv@",
"order_id": "p$KWIG5p0vR(@gNw)lv@",
"timestamp": "p$KWIG5p0vR(@gNw)lv@",
"type": "p$KWIG5p0vR(@gNw)lv@",
"user_identifiers": Object {},
}
`;
Expand All @@ -35,6 +37,7 @@ Object {
"action": "SjDZyt(p",
"campaign": "SjDZyt(p",
"campaign_event_value": "SjDZyt(p",
"campaign_id": "SjDZyt(p",
"timestamp": "SjDZyt(p",
"type": "email",
"user_identifiers": Object {
Expand All @@ -51,6 +54,7 @@ Object {
"action": "SjDZyt(p",
"campaign": "SjDZyt(p",
"campaign_event_value": null,
"campaign_id": "SjDZyt(p",
"timestamp": "SjDZyt(p",
"type": "email",
"user_identifiers": Object {
Expand All @@ -66,6 +70,7 @@ Object {
"testType": "3!#ax",
},
"timestamp": "3!#ax",
"type": "3!#ax",
"user_identifiers": Object {
"anonymousId": "3!#ax",
"email": "elenal@fen.uz",
Expand All @@ -77,8 +82,8 @@ Object {

exports[`Testing snapshot for actions-optimizely-data-platform destination: nonEcommCustomEvent action - required fields 1`] = `
Object {
"action": "3!#ax",
"timestamp": "3!#ax",
"type": "3!#ax",
"user_identifiers": Object {},
}
`;
Expand All @@ -94,13 +99,16 @@ Object {
},
"age": 89357760918978.56,
"company": "WnJP3)h29qx6Q9XcA@qx",
"dob": "2021-02-01T00:00:00.000Z",
"dob_day": 1,
"dob_month": 2,
"dob_year": 2021,
"first_name": "WnJP3)h29qx6Q9XcA@qx",
"gender": "WnJP3)h29qx6Q9XcA@qx",
"image_url": "WnJP3)h29qx6Q9XcA@qx",
"last_name": "WnJP3)h29qx6Q9XcA@qx",
"name": "WnJP3)h29qx6Q9XcA@qx",
"phone": "WnJP3)h29qx6Q9XcA@qx",
"testType": "WnJP3)h29qx6Q9XcA@qx",
"title": "WnJP3)h29qx6Q9XcA@qx",
"user_identifiers": Object {
"anonymousId": "WnJP3)h29qx6Q9XcA@qx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Object {
],
"timestamp": "FX3MHiX9P^tIkXKVCa",
"total": "FX3MHiX9P^tIkXKVCa",
"type": "FX3MHiX9P^tIkXKVCa",
"user_identifiers": Object {
"anonymousId": "FX3MHiX9P^tIkXKVCa",
"email": "oriiwo@hovevut.bn",
Expand All @@ -26,6 +27,7 @@ Object {
"action": "FX3MHiX9P^tIkXKVCa",
"order_id": "FX3MHiX9P^tIkXKVCa",
"timestamp": "FX3MHiX9P^tIkXKVCa",
"type": "FX3MHiX9P^tIkXKVCa",
"user_identifiers": Object {},
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,26 @@ describe('OptimizelyDataPlatform.trackEvent', () => {
apiKey: 'abc123',
region: 'US'
},
useDefaultMappings: true
mapping: {
user_identifiers: {
anonymousId: 'anonId1234',
userId: 'user1234'
},
event_type: 'whatever',
event_action: 'purchase',
products: [
{ product_id: '12345', qty: 2 },
{ product_id: '67890', qty: 5 }
],
order_id: '1234',
total: 20,
timestamp: '2024-03-01T18:11:27.649Z'
}
})

const expectedBody = `"{\\"user_identifiers\\":{\\"anonymousId\\":\\"anonId1234\\",\\"userId\\":\\"user1234\\"},\\"action\\":\\"purchase\\",\\"timestamp\\":\\"${productEvent.timestamp}\\",\\"order_id\\":\\"1234\\",\\"total\\":\\"20\\",\\"products\\":[{\\"product_id\\":\\"12345\\",\\"qty\\":2},{\\"product_id\\":\\"67890\\",\\"qty\\":5}]}"`

expect(response[0].status).toBe(201)
expect(response[0].options.body).toMatchInlineSnapshot(expectedBody)
expect(response[0].options.body).toMatchInlineSnapshot(
`"{\\"user_identifiers\\":{\\"anonymousId\\":\\"anonId1234\\",\\"userId\\":\\"user1234\\"},\\"action\\":\\"purchase\\",\\"type\\":\\"whatever\\",\\"timestamp\\":\\"2024-03-01T18:11:27.649Z\\",\\"order_id\\":\\"1234\\",\\"total\\":\\"20\\",\\"products\\":[{\\"product_id\\":\\"12345\\",\\"qty\\":2},{\\"product_id\\":\\"67890\\",\\"qty\\":5}]}"`
)
})
})

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
@@ -1,15 +1,21 @@
import { ActionDefinition } from '@segment/actions-core'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import { user_identifiers, event_action, products, order_id, total, timestamp } from '../fields'
import { user_identifiers, event_type, products, order_id, total, timestamp } from '../fields'
import { hosts } from '../utils'

const action: ActionDefinition<Settings, Payload> = {
title: 'Ecommerce Event',
description: 'Send Segment Ecommerce track() events to Optimizely Data Platform',
fields: {
user_identifiers: user_identifiers,
event_action: { ...event_action },
event_type: { ...event_type },
event_action: {
label: 'Optimizely Event Action',
description: 'The name of the Optimizely Event Action.',
type: 'string',
required: true
},
products: { ...products },
order_id: { ...order_id },
total: { ...total },
Expand All @@ -21,6 +27,7 @@ const action: ActionDefinition<Settings, Payload> = {
const body = {
user_identifiers: payload.user_identifiers,
action: payload.event_action,
type: payload.event_type,
timestamp: payload.timestamp,
order_id: payload.order_id,
total: payload.total,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Object {
"action": "4v7TZkJBZ*J1n#7wW@T%",
"campaign": "4v7TZkJBZ*J1n#7wW@T%",
"campaign_event_value": "4v7TZkJBZ*J1n#7wW@T%",
"campaign_id": "4v7TZkJBZ*J1n#7wW@T%",
"timestamp": "4v7TZkJBZ*J1n#7wW@T%",
"type": "email",
"user_identifiers": Object {
Expand All @@ -21,6 +22,7 @@ Object {
"action": "4v7TZkJBZ*J1n#7wW@T%",
"campaign": "4v7TZkJBZ*J1n#7wW@T%",
"campaign_event_value": null,
"campaign_id": "4v7TZkJBZ*J1n#7wW@T%",
"timestamp": "4v7TZkJBZ*J1n#7wW@T%",
"type": "email",
"user_identifiers": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,20 @@ describe('OptimizelyDataPlatform.emailEvent', () => {
apiKey: 'abc123',
region: 'US'
},
useDefaultMappings: true
mapping: {
user_identifiers: {
anonymousId: 'anonId1234',
userId: 'user1234',
email: 'test@test.com'
},
event_type: 'email',
event_action: 'opened',
campaign: 'opti-test-campaign',
timestamp: '2024-03-01T18:11:27.649Z'
}
})

const expectedBody = `"{\\"type\\":\\"email\\",\\"action\\":\\"Email Opened\\",\\"campaign\\":\\"opti-test-campaign\\",\\"user_identifiers\\":{\\"anonymousId\\":\\"anonId1234\\",\\"userId\\":\\"user1234\\",\\"email\\":\\"test.email@test.com\\"},\\"campaign_event_value\\":\\"https://url-from-email-clicked.com\\",\\"timestamp\\":\\"${emailEvent.timestamp}\\"}"`

expect(response[0].status).toBe(201)
expect(response[0].options.body).toMatchInlineSnapshot(expectedBody)
expect(response[0].options.body).toMatchInlineSnapshot(`"{\\"type\\":\\"email\\",\\"action\\":\\"opened\\",\\"campaign\\":\\"opti-test-campaign\\",\\"user_identifiers\\":{\\"anonymousId\\":\\"anonId1234\\",\\"userId\\":\\"user1234\\",\\"email\\":\\"test@test.com\\"},\\"campaign_event_value\\":null,\\"timestamp\\":\\"2024-03-01T18:11:27.649Z\\"}"`)
})
})

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
@@ -1,22 +1,19 @@
import type { ActionDefinition } from '@segment/actions-core'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import { timestamp, email_action_identifiers, event_action } from '../fields'
import { timestamp, email_action_identifiers } from '../fields'
import { hosts } from '../utils'

const action: ActionDefinition<Settings, Payload> = {
title: 'Email Event',
description: 'Send Segment track() events containing email related details to Optimizely Data Platform',
description: 'Send email related Segment track() events to Optimizely Data Platform',
fields: {
user_identifiers: email_action_identifiers,
event_action: event_action,
campaign_id: {
label: 'Campaign ID',
description: 'The campaign unique identifier',
event_action: {
label: 'Optimizely Event Action',
description: 'The name of the Optimizely Event Action.',
type: 'string',
default: {
'@path': '$.properties.campaign_id'
}
required: true
},
campaign: {
label: 'Campaign Name',
Expand All @@ -27,6 +24,14 @@ const action: ActionDefinition<Settings, Payload> = {
'@path': '$.properties.campaign_name'
}
},
campaign_id: {
label: 'Campaign ID',
description: 'The campaign unique identifier',
type: 'string',
default: {
'@path': '$.properties.campaign_id'
}
},
link_url: {
label: 'Link URL',
description: 'URL of the link which was clicked',
Expand All @@ -44,6 +49,7 @@ const action: ActionDefinition<Settings, Payload> = {
type: 'email',
action: payload.event_action,
campaign: payload.campaign,
campaign_id: payload.campaign_id,
user_identifiers: payload.user_identifiers,
campaign_event_value: payload.link_url ?? null,
timestamp: payload.timestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { InputField, Directive } from '@segment/actions-core/destination-kit/types'

export const event_action: InputField = {
label: 'Optimizely Event Name',
description: 'The name of the Optimizely event to send',
export const event_type: InputField = {
label: 'Optimizely Event Type',
description: 'The Optimizely Event Type.',
type: 'string',
required: true,
default: {
'@path': '$.event'
}
}

export const event_action: InputField = {
label: 'Optimizely Event Action',
description: 'The name of the Optimizely Event Action.',
type: 'string',
required: false
}

export const data: InputField = {
label: 'Event Properties',
description: 'Additional information to send with your custom event',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'customEvent',
mapping: {
...singleProductFields,
event_action: 'product_viewed'
event_type: 'product',
event_action: 'detail'
},
type: 'automatic'
},
Expand All @@ -81,7 +82,8 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'customEvent',
mapping: {
...singleProductFields,
event_action: 'product_added_to_cart'
event_type: 'product',
event_action: 'add_to_cart'
},
type: 'automatic'
},
Expand All @@ -91,7 +93,8 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'customEvent',
mapping: {
...singleProductFields,
event_action: 'product_removed_from_cart'
event_type: 'product',
event_action: 'remove_from_cart'
},
type: 'automatic'
},
Expand All @@ -101,7 +104,18 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'customEvent',
mapping: {
...defaultValues(customEvent.fields),
event_action: 'purchase_completed'
event_type: 'order',
event_action: 'purchase'
},
type: 'automatic'
},
{
name: 'Email Sent',
subscribe: 'type = "track" and event = "Email Sent"',
partnerAction: 'emailEvent',
mapping: {
...defaultValues(emailEvent.fields),
event_action: 'sent'
},
type: 'automatic'
},
Expand All @@ -111,7 +125,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'emailEvent',
mapping: {
...defaultValues(emailEvent.fields),
event_action: 'email_clicked'
event_action: 'click'
},
type: 'automatic'
},
Expand All @@ -121,7 +135,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'emailEvent',
mapping: {
...defaultValues(emailEvent.fields),
event_action: 'email_opened'
event_action: 'open'
},
type: 'automatic'
},
Expand All @@ -131,7 +145,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'emailEvent',
mapping: {
...defaultValues(emailEvent.fields),
event_action: 'email_unsubscribed'
event_action: 'unsubscribe'
},
type: 'automatic'
},
Expand All @@ -141,7 +155,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'emailEvent',
mapping: {
...defaultValues(emailEvent.fields),
event_action: 'email_marked_as_spam'
event_action: 'spam_report'
},
type: 'automatic'
}
Expand Down
Loading

0 comments on commit 82a80b9

Please sign in to comment.