2
0

🐛 (ga) Fix invalid variable parsing

This commit is contained in:
Baptiste Arnaud
2023-05-05 11:32:58 -04:00
parent ecc3b5fd87
commit d99af7e6c5
2 changed files with 17 additions and 18 deletions

View File

@@ -6,14 +6,18 @@ export const executeGoogleAnalyticsBlock = (
{ typebot: { variables } }: SessionState,
block: GoogleAnalyticsBlock,
lastBubbleBlockId?: string
): ExecuteIntegrationResponse => ({
outgoingEdgeId: block.outgoingEdgeId,
clientSideActions: [
{
googleAnalytics: deepParseVariables(variables, {
guessCorrectType: true,
})(block.options),
lastBubbleBlockId,
},
],
})
): ExecuteIntegrationResponse => {
const googleAnalytics = deepParseVariables(variables)(block.options)
return {
outgoingEdgeId: block.outgoingEdgeId,
clientSideActions: [
{
googleAnalytics: {
...googleAnalytics,
value: Number(googleAnalytics.value),
},
lastBubbleBlockId,
},
],
}
}

View File

@@ -4,14 +4,11 @@ import {
parseVariables,
ParseVariablesOptions,
} from './parseVariables'
import { parseGuessedValueType } from './parseGuessedValueType'
export const deepParseVariables =
(
variables: Variable[],
options: ParseVariablesOptions & {
guessCorrectType?: boolean
} = defaultParseVariablesOptions
options: ParseVariablesOptions = defaultParseVariablesOptions
) =>
<T extends Record<string, unknown>>(object: T): T =>
Object.keys(object).reduce<T>((newObj, key) => {
@@ -21,9 +18,7 @@ export const deepParseVariables =
const parsedVariable = parseVariables(variables, options)(currentValue)
return {
...newObj,
[key]: options.guessCorrectType
? parseGuessedValueType(parsedVariable)
: parsedVariable,
[key]: parsedVariable,
}
}