2
0

(ga) Add send_to option

This commit is contained in:
Baptiste Arnaud
2023-04-27 13:23:10 +02:00
parent d448e64dc9
commit 9e8acd97aa
5 changed files with 30 additions and 27 deletions

View File

@ -6,9 +6,7 @@ import {
AccordionItem, AccordionItem,
AccordionPanel, AccordionPanel,
Box, Box,
FormLabel,
Stack, Stack,
Tag,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { GoogleAnalyticsOptions } from '@typebot.io/schemas' import { GoogleAnalyticsOptions } from '@typebot.io/schemas'
import React from 'react' import React from 'react'
@ -22,43 +20,48 @@ export const GoogleAnalyticsSettings = ({
options, options,
onOptionsChange, onOptionsChange,
}: Props) => { }: Props) => {
const handleTrackingIdChange = (trackingId: string) => const updateTrackingId = (trackingId: string) =>
onOptionsChange({ ...options, trackingId }) onOptionsChange({ ...options, trackingId })
const handleCategoryChange = (category: string) => const updateCategory = (category: string) =>
onOptionsChange({ ...options, category }) onOptionsChange({ ...options, category })
const handleActionChange = (action: string) => const updateAction = (action: string) =>
onOptionsChange({ ...options, action }) onOptionsChange({ ...options, action })
const handleLabelChange = (label: string) => const updateLabel = (label: string) => onOptionsChange({ ...options, label })
onOptionsChange({ ...options, label })
const handleValueChange = (value?: string) => const updateValue = (value?: string) =>
onOptionsChange({ onOptionsChange({
...options, ...options,
value: value ? parseFloat(value) : undefined, value: value ? parseFloat(value) : undefined,
}) })
const updateSendTo = (sendTo?: string) =>
onOptionsChange({
...options,
sendTo,
})
return ( return (
<Stack spacing={4}> <Stack spacing={4}>
<TextInput <TextInput
label="Tracking ID:" label="Tracking ID:"
defaultValue={options?.trackingId ?? ''} defaultValue={options?.trackingId ?? ''}
placeholder="G-123456..." placeholder="G-123456..."
onChange={handleTrackingIdChange} onChange={updateTrackingId}
/> />
<TextInput <TextInput
label="Event category:" label="Event category:"
defaultValue={options?.category ?? ''} defaultValue={options?.category ?? ''}
placeholder="Example: Typebot" placeholder="Example: Typebot"
onChange={handleCategoryChange} onChange={updateCategory}
/> />
<TextInput <TextInput
label="Event action:" label="Event action:"
defaultValue={options?.action ?? ''} defaultValue={options?.action ?? ''}
placeholder="Example: Submit email" placeholder="Example: Submit email"
onChange={handleActionChange} onChange={updateAction}
/> />
<Accordion allowToggle> <Accordion allowToggle>
<AccordionItem> <AccordionItem>
@ -72,26 +75,23 @@ export const GoogleAnalyticsSettings = ({
</h2> </h2>
<AccordionPanel pb={4} as={Stack} spacing="6"> <AccordionPanel pb={4} as={Stack} spacing="6">
<TextInput <TextInput
label={ label="Event label:"
<>
Event label <Tag>Optional</Tag>:
</>
}
defaultValue={options?.label ?? ''} defaultValue={options?.label ?? ''}
placeholder="Example: Campaign Z" placeholder="Example: Campaign Z"
onChange={handleLabelChange} onChange={updateLabel}
/> />
<TextInput <TextInput
label={ label="Event value:"
<>
<FormLabel mb="0" htmlFor="value">
Event value <Tag>Optional</Tag>:
</FormLabel>
</>
}
defaultValue={options?.value?.toString() ?? ''} defaultValue={options?.value?.toString() ?? ''}
placeholder="Example: 0" placeholder="Example: 0"
onChange={handleValueChange} onChange={updateValue}
/>
<TextInput
label="Send to:"
moreInfoTooltip="Useful to send a conversion event to Google Ads"
defaultValue={options?.value?.toString() ?? ''}
placeholder="Example: AW-123456789"
onChange={updateSendTo}
/> />
</AccordionPanel> </AccordionPanel>
</AccordionItem> </AccordionItem>

View File

@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/js", "name": "@typebot.io/js",
"version": "0.0.42", "version": "0.0.43",
"description": "Javascript library to display typebots on your website", "description": "Javascript library to display typebots on your website",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -7,6 +7,7 @@ declare const gtag: (
event_category: string | undefined event_category: string | undefined
event_label: string | undefined event_label: string | undefined
value: number | undefined value: number | undefined
send_to: string | undefined
} }
) => void ) => void
@ -39,6 +40,7 @@ export const sendGaEvent = (options: GoogleAnalyticsOptions) => {
event_category: options.category, event_category: options.category,
event_label: options.label, event_label: options.label,
value: options.value, value: options.value,
send_to: options.sendTo,
}) })
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/react", "name": "@typebot.io/react",
"version": "0.0.42", "version": "0.0.43",
"description": "React library to display typebots on your website", "description": "React library to display typebots on your website",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@ -8,6 +8,7 @@ export const googleAnalyticsOptionsSchema = z.object({
action: z.string().optional(), action: z.string().optional(),
label: z.string().optional(), label: z.string().optional(),
value: z.number().optional(), value: z.number().optional(),
sendTo: z.string().optional(),
}) })
export const googleAnalyticsBlockSchema = blockBaseSchema.merge( export const googleAnalyticsBlockSchema = blockBaseSchema.merge(