2023-06-28 09:52:03 +02:00
|
|
|
/* eslint-disable solid/reactivity */
|
|
|
|
|
import { initGoogleAnalytics } from '@/lib/gtag'
|
|
|
|
|
import { gtmBodyElement } from '@/lib/gtm'
|
|
|
|
|
import { initPixel } from '@/lib/pixel'
|
2023-09-26 10:22:02 +02:00
|
|
|
import {
|
|
|
|
|
injectCustomHeadCode,
|
|
|
|
|
isDefined,
|
|
|
|
|
isNotEmpty,
|
|
|
|
|
} from '@typebot.io/lib/utils'
|
2023-06-28 09:52:03 +02:00
|
|
|
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)
|
2023-09-26 10:22:02 +02:00
|
|
|
const pixelIds = startPropsToInject.pixelId
|
|
|
|
|
? [startPropsToInject.pixelId]
|
|
|
|
|
: startPropsToInject.pixelIds
|
|
|
|
|
if (isDefined(pixelIds)) initPixel(pixelIds)
|
2023-06-28 09:52:03 +02:00
|
|
|
}
|