2023-03-15 12:21:52 +01:00
|
|
|
import { ExecuteIntegrationResponse } from '@/features/chat/types'
|
|
|
|
|
import { deepParseVariables } from '@/features/variables/deepParseVariable'
|
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 = (
|
2023-06-28 09:52:03 +02:00
|
|
|
{ typebot: { variables }, result }: SessionState,
|
2023-05-26 09:20:22 +02:00
|
|
|
block: GoogleAnalyticsBlock
|
2023-05-05 11:32:58 -04:00
|
|
|
): ExecuteIntegrationResponse => {
|
2023-06-28 09:52:03 +02:00
|
|
|
if (!result) return { outgoingEdgeId: block.outgoingEdgeId }
|
|
|
|
|
const googleAnalytics = deepParseVariables(variables, {
|
|
|
|
|
guessCorrectTypes: true,
|
|
|
|
|
removeEmptyStrings: true,
|
|
|
|
|
})(block.options)
|
2023-05-05 11:32:58 -04:00
|
|
|
return {
|
|
|
|
|
outgoingEdgeId: block.outgoingEdgeId,
|
|
|
|
|
clientSideActions: [
|
|
|
|
|
{
|
2023-06-28 09:52:03 +02:00
|
|
|
googleAnalytics,
|
2023-05-05 11:32:58 -04:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
}
|