@@ -6,8 +6,10 @@ import { executeScript } from '@/features/blocks/logic/script/executeScript'
|
||||
import { executeSetVariable } from '@/features/blocks/logic/setVariable/executeSetVariable'
|
||||
import { executeWait } from '@/features/blocks/logic/wait/utils/executeWait'
|
||||
import { executeWebhook } from '@/features/blocks/integrations/webhook/executeWebhook'
|
||||
import { executePixel } from '@/features/blocks/integrations/pixel/executePixel'
|
||||
import { ClientSideActionContext } from '@/types'
|
||||
import type { ChatReply, ReplyLog } from '@typebot.io/schemas'
|
||||
import { injectStartProps } from './injectStartProps'
|
||||
|
||||
export const executeClientSideAction = async (
|
||||
clientSideAction: NonNullable<ChatReply['clientSideActions']>[0],
|
||||
@@ -58,4 +60,10 @@ export const executeClientSideAction = async (
|
||||
const response = await executeWebhook(clientSideAction.webhookToExecute)
|
||||
return { replyToSend: response }
|
||||
}
|
||||
if ('startPropsToInject' in clientSideAction) {
|
||||
return injectStartProps(clientSideAction.startPropsToInject)
|
||||
}
|
||||
if ('pixel' in clientSideAction) {
|
||||
return executePixel(clientSideAction.pixel)
|
||||
}
|
||||
}
|
||||
|
||||
20
packages/embeds/js/src/utils/injectStartProps.ts
Normal file
20
packages/embeds/js/src/utils/injectStartProps.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/* eslint-disable solid/reactivity */
|
||||
import { initGoogleAnalytics } from '@/lib/gtag'
|
||||
import { gtmBodyElement } from '@/lib/gtm'
|
||||
import { initPixel } from '@/lib/pixel'
|
||||
import { injectCustomHeadCode, isNotEmpty } from '@typebot.io/lib/utils'
|
||||
import { StartPropsToInject } from '@typebot.io/schemas'
|
||||
|
||||
export const injectStartProps = async (
|
||||
startPropsToInject: StartPropsToInject
|
||||
) => {
|
||||
const customHeadCode = startPropsToInject.customHeadCode
|
||||
if (isNotEmpty(customHeadCode)) injectCustomHeadCode(customHeadCode)
|
||||
const gtmId = startPropsToInject.gtmId
|
||||
if (isNotEmpty(gtmId)) document.body.prepend(gtmBodyElement(gtmId))
|
||||
const googleAnalyticsId = startPropsToInject.googleAnalyticsId
|
||||
if (isNotEmpty(googleAnalyticsId))
|
||||
await initGoogleAnalytics(googleAnalyticsId)
|
||||
const pixelId = startPropsToInject.pixelId
|
||||
if (isNotEmpty(pixelId)) initPixel(pixelId)
|
||||
}
|
||||
Reference in New Issue
Block a user