Skip to content
Draft
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

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,9 +1,9 @@
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import { formatPhone, handleArrayInput, formatString, formatAddress } from '../formatter'
import { getUser } from '../utils'
import { TikTokPixel } from '../types'
import { commonFields } from '../common_fields'
import { commonFields } from '../reportWebEvent/fields/common_fields'

// Change from unknown to the partner SDK types
const action: BrowserActionDefinition<Settings, TikTokPixel, Payload> = {
Expand Down Expand Up @@ -40,19 +40,9 @@ const action: BrowserActionDefinition<Settings, TikTokPixel, Payload> = {
}
}
},
perform: (ttq, { payload }) => {
perform: (ttq, { payload, settings }) => {
if (payload.email || payload.phone_number || payload.external_id) {
ttq.identify({
email: handleArrayInput(payload.email),
phone_number: formatPhone(handleArrayInput(payload.phone_number)),
external_id: handleArrayInput(payload.external_id),
first_name: formatString(payload.first_name),
last_name: formatString(payload.last_name),
city: formatAddress(payload.address?.city),
state: formatAddress(payload.address?.state),
country: formatAddress(payload.address?.country),
zip_code: formatString(payload.address?.zip_code)
})
ttq.instance(settings.pixelCode).identify(getUser(payload))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const VEHICLE_FIELDS = 'vehicle_fields'
export const TRAVEL_FIELDS = 'travel_fields'
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { InputField } from '@segment/actions-core'
import { VEHICLE_FIELDS, TRAVEL_FIELDS } from '../constants'

export const commonFields: Record<string, InputField> = {
event_spec_type: {
label: 'Additional Fields',
type: 'string',
description: 'Include fields for travel or vehicle events.',
choices: [
{ value: TRAVEL_FIELDS, label: 'Travel Fields' },
{ value: VEHICLE_FIELDS, label: 'Vehicle Fields' }
]
},
event: {
label: 'Event Name',
type: 'string',
Expand Down Expand Up @@ -195,6 +205,24 @@ export const commonFields: Record<string, InputField> = {
}
}
},
content_ids: {
label: 'Content IDs',
description:
"Product IDs associated with the event, such as SKUs. Do not populate this field if the 'Contents' field is populated. This field accepts a single string value or an array of string values.",
type: 'string',
multiple: true,
default: {
'@path': '$.properties.content_ids'
}
},
num_items: {
label: 'Number of Items',
type: 'number',
description: 'Number of items when checkout was initiated. Used with the InitiateCheckout event.',
default: {
'@path': '$.properties.num_items'
}
},
content_type: {
label: 'Content Type',
description:
Expand Down Expand Up @@ -238,5 +266,22 @@ export const commonFields: Record<string, InputField> = {
default: {
'@path': '$.properties.query'
}
},
search_string: {
label: 'Search String',
type: 'string',
description: 'The text string entered by the user for the search. Optionally used with the Search event.',
default: {
'@path': '$.properties.search_string'
},
depends_on: {
conditions: [
{
fieldKey: 'event',
operator: 'is',
value: 'Search'
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import { InputField } from '@segment/actions-core'
import { TRAVEL_FIELDS } from '../constants'

export const travel_fields: InputField = {
label: 'Travel Fields',
type: 'object',
description: 'Fields related to travel events.',
additionalProperties: false,
defaultObjectUI: 'keyvalue',
properties: {
city: {
label: 'Hotel City Location',
type: 'string',
description: 'Hotel city location.'
},
region: {
label: 'Hotel Region',
type: 'string',
description: 'Hotel region location.'
},
country: {
label: 'Hotel Country',
type: 'string',
description: 'Hotel country location.'
},
checkin_date: {
label: 'Hotel Check-in Date',
type: 'string',
description: 'Hotel check-in date.'
},
checkout_date: {
label: 'Hotel Check-out Date',
type: 'string',
description: 'Hotel check-out date.'
},
num_adults: {
label: 'Number of Adults',
type: 'number',
description: 'Number of adults.'
},
num_children: {
label: 'Number of Children',
type: 'number',
description: 'Number of children.'
},
num_infants: {
label: 'Number of Infants',
type: 'number',
description: 'Number of infants flying.'
},
suggested_hotels: {
label: 'Suggested Hotels',
description: 'Suggested hotels. This can be a single string value or an array of string values.',
type: 'string',
multiple: true
},
departing_departure_date: {
label: 'Departure Date',
type: 'string',
description:
'Date of flight departure. Accepted date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD'
},
returning_departure_date: {
label: 'Arrival Date',
type: 'string',
description:
'Date of return flight. Accepted date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD'
},
origin_airport: {
label: 'Origin Airport',
type: 'string',
description: 'Origin airport.'
},
destination_airport: {
label: 'Destination Airport',
type: 'string',
description: 'Destination airport.'
},
destination_ids: {
label: 'Destination IDs',
description:
'If a client has a destination catalog, the client can associate one or more destinations in the catalog with a specific flight event. For instance, link a particular route to a nearby museum and a nearby beach, both of which are destinations in the catalog. This field accepts a single string value or an array of string values.',
type: 'string',
multiple: true
},
departing_arrival_date: {
label: 'Departing Arrival Date',
type: 'string',
description:
'The date and time for arrival at the destination of the outbound journey. Accepted date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD'
},
returning_arrival_date: {
label: 'Returning Arrival Date',
type: 'string',
description:
'The date and time when the return journey is completed. Accepted date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD'
},
travel_class: {
label: 'Flight Ticket Class',
type: 'string',
description: 'Class of the flight ticket, must be: "eco", "prem", "bus", "first".',
choices: [
{ value: 'eco', label: 'Economy' },
{ value: 'prem', label: 'Premium' },
{ value: 'bus', label: 'Bus' },
{ value: 'first', label: 'First' }
]
},
user_score: {
label: 'User Score',
type: 'number',
description: 'Represents the relative value of this potential customer to advertiser.'
},
preferred_num_stops: {
label: 'Preferred Number of Stops',
type: 'integer',
description: 'The preferred number of stops the user is looking for. 0 for direct flight.'
},
travel_start: {
label: 'Start Date of the Trip',
type: 'string',
description:
"The start date of user's trip. Accept date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD."
},
travel_end: {
label: 'End Date of the Trip',
type: 'string',
description:
"The end date of user's trip. Accept date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD."
},
suggested_destinations: {
label: 'Suggested Destination IDs',
description:
'A list of IDs representing destination suggestions for this user. This parameter is not applicable for the Search event. This field accepts a single string value or an array of string values.',
type: 'string',
multiple: true
}
},
default: {
city: {
'@path': '$.properties.city'
},
region: {
'@path': '$.properties.region'
},
country: {
'@path': '$.properties.country'
},
checkin_date: {
'@path': '$.properties.checkin_date'
},
checkout_date: {
'@path': '$.properties.checkout_date'
},
num_adults: {
'@path': '$.properties.num_adults'
},
num_children: {
'@path': '$.properties.num_children'
},
num_infants: {
'@path': '$.properties.num_infants'
},
suggested_hotels: {
'@path': '$.properties.suggested_hotels' // Confirmed this can be a single string or an array of strings
},
departing_departure_date: {
'@path': '$.properties.departing_departure_date'
},
returning_departure_date: {
'@path': '$.properties.returning_departure_date'
},
origin_airport: {
'@path': '$.properties.origin_airport'
},
destination_airport: {
'@path': '$.properties.destination_airport'
},
destination_ids: {
'@path': '$.properties.destination_ids' // Confirmed this can be a single string or an array of strings
},
departing_arrival_date: {
'@path': '$.properties.departing_arrival_date'
},
returning_arrival_date: {
'@path': '$.properties.returning_arrival_date'
},
travel_class: {
'@path': '$.properties.travel_class'
},
user_score: {
'@path': '$.properties.user_score'
},
preferred_num_stops: {
'@path': '$.properties.preferred_num_stops'
},
travel_start: {
'@path': '$.properties.travel_start'
},
travel_end: {
'@path': '$.properties.travel_end'
},
suggested_destinations: {
'@path': '$.properties.suggested_destinations' // Confirmed this can be a single string or an array of strings
}
},
depends_on: {
conditions: [
{
fieldKey: 'event_spec_type',
operator: 'is',
value: TRAVEL_FIELDS
}
]
}
}
Loading
Loading