Skip to content

Commit

Permalink
feat(integration): ✨ Add Google Analytics integration
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jan 19, 2022
1 parent 44b4785 commit 3506d86
Show file tree
Hide file tree
Showing 21 changed files with 528 additions and 152 deletions.
100 changes: 100 additions & 0 deletions apps/builder/assets/logos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,103 @@ export const GoogleSheetsLogo = (props: IconProps) => (
</g>
</Icon>
)

export const GoogleAnalyticsLogo = (props: IconProps) => (
<Icon viewBox="0 0 353 353" {...props}>
<g clipPath="url(#clip0_1458_69)">
<path
d="M324.433 0H260.155C244.607 0 231.844 12.773 231.844 28.3329V111.474H138.792C123.709 111.474 111.41 123.782 111.41 139.11V232.237H27.6395C12.3241 232.237 0.0253906 244.545 0.0253906 259.873V324.899C0.0253906 340.227 12.3241 352.536 27.6395 353H324.665C340.212 353 352.975 340.227 352.975 324.667V28.3329C352.743 12.773 339.98 0 324.433 0Z"
fill="url(#paint0_linear_1458_69)"
/>
<path
d="M324.433 0H260.155C244.607 0 231.844 12.773 231.844 28.3329V111.474H138.792C123.709 111.474 111.41 123.782 111.41 139.11V232.237H27.6395C12.3241 232.237 0.0253906 244.545 0.0253906 259.873V324.899C0.0253906 340.227 12.3241 352.536 27.6395 353H324.665C340.212 353 352.975 340.227 352.975 324.667V28.3329C352.743 12.773 339.98 0 324.433 0Z"
fill="url(#paint1_linear_1458_69)"
/>
<path
d="M324.433 0H260.619C245.071 0 232.309 12.773 232.309 28.3329V353H324.433C339.98 353 352.743 340.227 352.743 324.667V28.3329C352.743 12.773 339.98 0 324.433 0Z"
fill="#F57C00"
/>
<path
d="M111.41 139.342V232.237H27.8715C12.5561 232.237 0.0253906 244.778 0.0253906 260.105V325.132C0.0253906 340.459 12.5561 353 27.8715 353H232.076V111.474H139.256C123.941 111.474 111.41 124.014 111.41 139.342Z"
fill="#FFC107"
/>
<path
d="M232.076 111.474V353H324.2C339.748 353 352.511 340.227 352.511 324.667V232.237L232.076 111.474Z"
fill="url(#paint2_linear_1458_69)"
/>
<path
opacity="0.2"
d="M139.256 113.796H232.077V111.474H139.256C123.941 111.474 111.41 124.014 111.41 139.342V141.664C111.41 126.337 123.941 113.796 139.256 113.796Z"
fill="white"
/>
<path
opacity="0.2"
d="M27.8715 234.56H111.41V232.237H27.8715C12.5561 232.237 0.0253906 244.778 0.0253906 260.106V262.428C0.0253906 247.1 12.5561 234.56 27.8715 234.56Z"
fill="white"
/>
<path
opacity="0.2"
d="M324.433 0H260.619C245.071 0 232.309 12.773 232.309 28.3329V30.6553C232.309 15.0954 245.071 2.32237 260.619 2.32237H324.433C339.98 2.32237 352.743 15.0954 352.743 30.6553V28.3329C352.743 12.773 339.98 0 324.433 0Z"
fill="white"
/>
<path
opacity="0.2"
d="M324.433 350.678H27.8715C12.5561 350.678 0.0253906 338.137 0.0253906 322.809V325.132C0.0253906 340.459 12.5561 353 27.8715 353H324.201C339.748 353 352.511 340.227 352.511 324.667V322.345C352.743 337.905 339.98 350.678 324.433 350.678V350.678Z"
fill="#BF360C"
/>
<path
d="M324.433 0H260.619C245.071 0 232.309 12.773 232.309 28.3329V111.474H139.488C124.173 111.474 111.642 124.014 111.642 139.342V232.237H27.8715C12.5561 232.237 0.0253906 244.778 0.0253906 260.105V325.132C0.0253906 340.459 12.5561 353 27.8715 353H324.433C339.98 353 352.743 340.227 352.743 324.667V28.3329C352.743 12.773 339.98 0 324.433 0Z"
fill="url(#paint3_linear_1458_69)"
/>
</g>
<defs>
<linearGradient
id="paint0_linear_1458_69"
x1="0.0253906"
y1="176.5"
x2="352.975"
y2="176.5"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="white" stopOpacity="0.1" />
<stop offset="1" stopColor="white" stopOpacity="0" />
</linearGradient>
<linearGradient
id="paint1_linear_1458_69"
x1="0.0253906"
y1="176.5"
x2="352.975"
y2="176.5"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="white" stopOpacity="0.1" />
<stop offset="1" stopColor="white" stopOpacity="0" />
</linearGradient>
<linearGradient
id="paint2_linear_1458_69"
x1="172.323"
y1="172.436"
x2="344.434"
y2="344.409"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#BF360C" stopOpacity="0.2" />
<stop offset="1" stopColor="#BF360C" stopOpacity="0.02" />
</linearGradient>
<linearGradient
id="paint3_linear_1458_69"
x1="118.3"
y1="118.513"
x2="346.649"
y2="346.679"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="white" stopOpacity="0.1" />
<stop offset="1" stopColor="white" stopOpacity="0" />
</linearGradient>
<clipPath id="clip0_1458_69">
<rect width="353" height="353" fill="white" />
</clipPath>
</defs>
</Icon>
)
4 changes: 3 additions & 1 deletion apps/builder/components/board/StepTypesList/StepIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
PhoneIcon,
TextIcon,
} from 'assets/icons'
import { GoogleSheetsLogo } from 'assets/logos'
import { GoogleAnalyticsLogo, GoogleSheetsLogo } from 'assets/logos'
import {
BubbleStepType,
InputStepType,
Expand Down Expand Up @@ -48,6 +48,8 @@ export const StepIcon = ({ type, ...props }: StepIconProps) => {
return <FilterIcon {...props} />
case IntegrationStepType.GOOGLE_SHEETS:
return <GoogleSheetsLogo {...props} />
case IntegrationStepType.GOOGLE_ANALYTICS:
return <GoogleAnalyticsLogo {...props} />
case 'start':
return <FlagIcon {...props} />
default:
Expand Down
15 changes: 13 additions & 2 deletions apps/builder/components/board/StepTypesList/StepTypeLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Text } from '@chakra-ui/react'
import { Text, Tooltip } from '@chakra-ui/react'
import {
BubbleStepType,
InputStepType,
Expand Down Expand Up @@ -41,7 +41,18 @@ export const StepTypeLabel = ({ type }: Props) => {
return <Text>Condition</Text>
}
case IntegrationStepType.GOOGLE_SHEETS: {
return <Text>Sheets</Text>
return (
<Tooltip label="Google Sheets">
<Text>Sheets</Text>
</Tooltip>
)
}
case IntegrationStepType.GOOGLE_ANALYTICS: {
return (
<Tooltip label="Google Analytics">
<Text>Analytics</Text>
</Tooltip>
)
}
default: {
return <></>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import {
PopoverBody,
useEventListener,
Portal,
Stack,
IconButton,
Flex,
} from '@chakra-ui/react'
import { ExpandIcon } from 'assets/icons'
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
Expand All @@ -28,6 +26,7 @@ import {
} from './bodies'
import { ChoiceInputSettingsBody } from './bodies/ChoiceInputSettingsBody'
import { ConditionSettingsBody } from './bodies/ConditionSettingsBody'
import { GoogleAnalyticsSettings } from './bodies/GoogleAnalyticsSettings'
import { GoogleSheetsSettingsBody } from './bodies/GoogleSheetsSettingsBody'
import { PhoneNumberSettingsBody } from './bodies/PhoneNumberSettingsBody'
import { SetVariableSettingsBody } from './bodies/SetVariableSettingsBody'
Expand All @@ -47,7 +46,7 @@ export const SettingsPopoverContent = ({ step, onExpandClick }: Props) => {
useEventListener('wheel', handleMouseWheel, ref.current)
return (
<Portal>
<PopoverContent onMouseDown={handleMouseDown}>
<PopoverContent onMouseDown={handleMouseDown} pos="relative">
<PopoverArrow />
<PopoverBody
px="6"
Expand All @@ -58,18 +57,17 @@ export const SettingsPopoverContent = ({ step, onExpandClick }: Props) => {
ref={ref}
shadow="lg"
>
<Stack>
<Flex justifyContent="flex-end">
<IconButton
aria-label="expand"
icon={<ExpandIcon />}
size="xs"
onClick={onExpandClick}
/>
</Flex>
<StepSettings step={step} />
</Stack>
<StepSettings step={step} />
</PopoverBody>
<IconButton
pos="absolute"
top="5px"
right="5px"
aria-label="expand"
icon={<ExpandIcon />}
size="xs"
onClick={onExpandClick}
/>
</PopoverContent>
</Portal>
)
Expand Down Expand Up @@ -162,6 +160,14 @@ export const StepSettings = ({ step }: { step: Step }) => {
/>
)
}
case IntegrationStepType.GOOGLE_ANALYTICS: {
return (
<GoogleAnalyticsSettings
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
default: {
return <></>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import {
Accordion,
AccordionButton,
AccordionIcon,
AccordionItem,
AccordionPanel,
Box,
FormLabel,
Stack,
Tag,
} from '@chakra-ui/react'
import { DebouncedInput } from 'components/shared/DebouncedInput'
import { InputWithVariableButton } from 'components/shared/InputWithVariableButton'
import { GoogleAnalyticsOptions } from 'models'
import React from 'react'

type Props = {
options?: GoogleAnalyticsOptions
onOptionsChange: (options: GoogleAnalyticsOptions) => void
}

export const GoogleAnalyticsSettings = ({
options,
onOptionsChange,
}: Props) => {
const handleTrackingIdChange = (trackingId: string) =>
onOptionsChange({ ...options, trackingId })

const handleCategoryChange = (category: string) =>
onOptionsChange({ ...options, category })

const handleActionChange = (action: string) =>
onOptionsChange({ ...options, action })

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

const handleValueChange = (value?: string) =>
onOptionsChange({
...options,
value: value ? parseFloat(value) : undefined,
})

return (
<Stack spacing={4}>
<Stack>
<FormLabel mb="0" htmlFor="tracking-id">
Tracking ID:
</FormLabel>
<DebouncedInput
id="tracking-id"
initialValue={options?.trackingId ?? ''}
placeholder="G-123456..."
delay={100}
onChange={handleTrackingIdChange}
/>
</Stack>
<Stack>
<FormLabel mb="0" htmlFor="category">
Event category:
</FormLabel>
<InputWithVariableButton
id="category"
initialValue={options?.category ?? ''}
placeholder="Example: Typebot"
delay={100}
onChange={handleCategoryChange}
/>
</Stack>
<Stack>
<FormLabel mb="0" htmlFor="action">
Event action:
</FormLabel>
<InputWithVariableButton
id="action"
initialValue={options?.action ?? ''}
placeholder="Example: Submit email"
delay={100}
onChange={handleActionChange}
/>
</Stack>
<Accordion allowToggle>
<AccordionItem>
<h2>
<AccordionButton>
<Box flex="1" textAlign="left">
Advanced
</Box>
<AccordionIcon />
</AccordionButton>
</h2>
<AccordionPanel pb={4} as={Stack} spacing="6">
<Stack>
<FormLabel mb="0" htmlFor="label">
Event label <Tag>Optional</Tag>:
</FormLabel>
<InputWithVariableButton
id="label"
initialValue={options?.label ?? ''}
placeholder="Example: Campaign Z"
delay={100}
onChange={handleLabelChange}
/>
</Stack>
<Stack>
<FormLabel mb="0" htmlFor="value">
Event value <Tag>Optional</Tag>:
</FormLabel>
<InputWithVariableButton
id="value"
initialValue={options?.value?.toString() ?? ''}
placeholder="Example: 0"
onChange={handleValueChange}
/>
</Stack>
</AccordionPanel>
</AccordionItem>
</Accordion>
</Stack>
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Fade, Flex, IconButton, Stack } from '@chakra-ui/react'
import { PlusIcon, TrashIcon } from 'assets/icons'
import { DropdownList } from 'components/shared/DropdownList'
import { InputWithVariable } from 'components/shared/InputWithVariable'
import { InputWithVariableButton } from 'components/shared/InputWithVariableButton'
import { Cell, Table } from 'models'
import React, { useEffect, useState } from 'react'
import { Sheet } from 'services/integrations'
Expand Down Expand Up @@ -131,9 +131,9 @@ export const CellWithValueStack = ({
items={columns}
placeholder="Select a column"
/>
<InputWithVariable
<InputWithVariableButton
initialValue={cell.value ?? ''}
onValueChange={handleValueChange}
onChange={handleValueChange}
placeholder="Type a value..."
/>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const SourceEndpoint = ({
align="center"
{...props}
>
<Box bgColor="gray.400" rounded="full" boxSize="7px" />
<Box bgColor="gray.400" rounded="full" boxSize="6px" />
</Flex>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export const StepNodeContent = ({ step }: Props) => {
if (!step.options) return <Text color={'gray.500'}>Configure...</Text>
return <Text>{step.options?.action}</Text>
}
case IntegrationStepType.GOOGLE_ANALYTICS: {
if (!step.options || !step.options.action)
return <Text color={'gray.500'}>Configure...</Text>
return <Text>Track "{step.options?.action}"</Text>
}
case 'start': {
return <Text>{step.label}</Text>
}
Expand Down
Loading

0 comments on commit 3506d86

Please sign in to comment.