2023-03-15 12:21:52 +01:00
|
|
|
import { ExecuteIntegrationResponse } from '@/features/chat/types'
|
|
|
|
|
import { deepParseVariables } from '@/features/variables/deepParseVariable'
|
2023-05-05 13:21:04 -04:00
|
|
|
import { isNotEmpty } from '@typebot.io/lib'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { GoogleAnalyticsBlock, SessionState } from '@typebot.io/schemas'
|
2022-11-29 10:02:40 +01:00
|
|
|
|
|
|
|
|
export const executeGoogleAnalyticsBlock = (
|
|
|
|
|
{ typebot: { variables } }: SessionState,
|
2023-05-26 09:20:22 +02:00
|
|
|
block: GoogleAnalyticsBlock
|
2023-05-05 11:32:58 -04:00
|
|
|
): ExecuteIntegrationResponse => {
|
|
|
|
|
const googleAnalytics = deepParseVariables(variables)(block.options)
|
|
|
|
|
return {
|
|
|
|
|
outgoingEdgeId: block.outgoingEdgeId,
|
|
|
|
|
clientSideActions: [
|
|
|
|
|
{
|
|
|
|
|
googleAnalytics: {
|
|
|
|
|
...googleAnalytics,
|
2023-05-05 13:21:04 -04:00
|
|
|
value: isNotEmpty(googleAnalytics.value as string)
|
|
|
|
|
? Number(googleAnalytics.value)
|
|
|
|
|
: undefined,
|
2023-05-05 11:32:58 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
}
|