Skip to content

Commit

Permalink
🐛 (googleAnalytics) Fix sendTo initial value in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 2, 2023
1 parent e58016e commit e2836f3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextInput } from '@/components/inputs'
import { NumberInput, TextInput } from '@/components/inputs'
import {
Accordion,
AccordionButton,
Expand Down Expand Up @@ -31,10 +31,10 @@ export const GoogleAnalyticsSettings = ({

const updateLabel = (label: string) => onOptionsChange({ ...options, label })

const updateValue = (value?: string) =>
const updateValue = (value: number | `{{${string}}}` | undefined) =>
onOptionsChange({
...options,
value: value ? parseFloat(value) : undefined,
value,
})

const updateSendTo = (sendTo?: string) =>
Expand Down Expand Up @@ -80,16 +80,17 @@ export const GoogleAnalyticsSettings = ({
placeholder="Example: Campaign Z"
onChange={updateLabel}
/>
<TextInput
<NumberInput
direction="column"
label="Event value:"
defaultValue={options?.value?.toString() ?? ''}
defaultValue={options?.value}
placeholder="Example: 0"
onChange={updateValue}
onValueChange={updateValue}
/>
<TextInput
label="Send to:"
moreInfoTooltip="Useful to send a conversion event to Google Ads"
defaultValue={options?.value?.toString() ?? ''}
defaultValue={options?.sendTo?.toString() ?? ''}
placeholder="Example: AW-123456789"
onChange={updateSendTo}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/deprecated/bot-engine/src/lib/gtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const sendGaEvent = (options: GoogleAnalyticsOptions) => {
gtag('event', options.action, {
event_category: options.category,
event_label: options.label,
value: options.value,
value: options.value as number,
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/js/src/lib/gtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const sendGaEvent = (options: GoogleAnalyticsOptions) => {
gtag('event', options.action, {
event_category: options.category,
event_label: options.label,
value: options.value,
value: options.value as number,
send_to: options.sendTo,
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { z } from 'zod'
import { blockBaseSchema } from '../baseSchemas'
import { IntegrationBlockType } from './enums'
import { variableStringSchema } from '../../utils'

export const googleAnalyticsOptionsSchema = z.object({
trackingId: z.string().optional(),
category: z.string().optional(),
action: z.string().optional(),
label: z.string().optional(),
value: z.number().optional(),
value: z.number().or(variableStringSchema).optional(),
sendTo: z.string().optional(),
})

Expand Down

0 comments on commit e2836f3

Please sign in to comment.