import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types' import type { Settings } from '../generated-types' import type { Payload } from './generated-types' const action: BrowserActionDefinition = { title: 'Sales Activity', description: 'Record monetary data for conversions, such as cost and the number of items sold.', defaultSubscription: 'type = "track"', platform: 'web', fields: { activityGroupTagString: { label: 'Activity Group Tag String', description: 'An identifier for the Floodlight activity group associated with this activity, which appears as a parameter in your tags. This value is case sensitive.', type: 'string', required: true }, activityTagString: { label: 'Activity Tag String', description: 'An identifier for your Floodlight activity, which appears as a parameter in your tags. This value is case sensitive.', type: 'string', required: true }, enableDynamicTags: { label: 'Enable Dynamic Tags', type: 'boolean', description: 'In Campaign Manager, go to Floodlight -> Configuration, under Tags, if **Dynamic** is selected, select **True**.' }, countingMethod: { label: 'Counting Method', type: 'string', description: 'Specifies how conversions will be counted for this Floodlight activity.', choices: [ { value: 'transactions', label: 'Transactions' }, { value: 'items_sold', label: 'Items Sold' } ], required: true }, transactionId: { label: 'Transaction ID', description: 'Use this field to insert a unique numerical identifier for each transaction. Can be alphanumeric.', type: 'string', required: true, default: { '@path': '$.properties.order_id' } }, value: { label: 'Value', description: 'Use this field to pass the revenue generated by a transaction. Typically the purchase price and value does not include taxes or shipping.', type: 'string', required: true, default: { '@path': '$.properties.total' } }, quantity: { label: 'Quantity', description: ` Use this field to pass the number of items sold during a transaction: - If you're counting each transaction as a single conversion, the value is 1. - If you're counting each item sold during a single transaction as a separate conversion, insert the number of items sold as part of each transaction as the value. - The value must be an integer greater than zero. `, type: 'integer', required: true }, uVariables: { label: 'U Variables', description: 'Custom Floodlight variables enable you to capture information beyond the basics (visits and revenue) that you can collect with standard parameters in your tags.', type: 'object', defaultObjectUI: 'keyvalue:only' }, dcCustomParams: { label: 'Custom Parameters', description: 'You can insert custom data into event snippets with the dc_custom_params field. This field accepts any values you want to pass to Google Marketing Platform.', type: 'object', defaultObjectUI: 'keyvalue:only' } }, perform: (gtag, { payload, settings }) => { const requestBody = { allow_custom_scripts: payload.enableDynamicTags, send_to: `${settings.advertiserId}/${payload.activityGroupTagString}/${payload.activityTagString}+${payload.countingMethod}`, value: payload.value, transaction_id: payload.transactionId, quantity: payload.quantity, ...payload.uVariables, ...(payload.dcCustomParams !== undefined && { dc_custom_params: { ...payload.dcCustomParams } }) } gtag('event', 'purchase', requestBody) } } export default action