2023-12-13 10:22:02 +01:00
|
|
|
import { ExecuteIntegrationResponse } from '../../../../types'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { GoogleAnalyticsBlock, SessionState } from '@typebot.io/schemas'
|
2023-12-13 10:22:02 +01:00
|
|
|
import { deepParseVariables } from '@typebot.io/variables/deepParseVariables'
|
2022-11-29 10:02:40 +01:00
|
|
|
|
|
|
|
|
export const executeGoogleAnalyticsBlock = (
|
2023-08-24 07:48:30 +02:00
|
|
|
state: SessionState,
|
2023-05-26 09:20:22 +02:00
|
|
|
block: GoogleAnalyticsBlock
|
2023-05-05 11:32:58 -04:00
|
|
|
): ExecuteIntegrationResponse => {
|
2023-08-24 07:48:30 +02:00
|
|
|
const { typebot, resultId } = state.typebotsQueue[0]
|
2023-11-08 15:34:16 +01:00
|
|
|
if (!resultId || state.whatsApp || !block.options)
|
2023-08-29 10:01:28 +02:00
|
|
|
return { outgoingEdgeId: block.outgoingEdgeId }
|
2023-08-24 07:48:30 +02:00
|
|
|
const googleAnalytics = deepParseVariables(typebot.variables, {
|
2023-06-28 09:52:03 +02:00
|
|
|
guessCorrectTypes: true,
|
|
|
|
|
removeEmptyStrings: true,
|
|
|
|
|
})(block.options)
|
2023-05-05 11:32:58 -04:00
|
|
|
return {
|
|
|
|
|
outgoingEdgeId: block.outgoingEdgeId,
|
|
|
|
|
clientSideActions: [
|
|
|
|
|
{
|
2023-12-22 09:13:53 +01:00
|
|
|
type: 'googleAnalytics',
|
2023-06-28 09:52:03 +02:00
|
|
|
googleAnalytics,
|
2023-05-05 11:32:58 -04:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
}
|