2
0

🐛 (googleAnalytics) Fix output validation when using variable as event value

This commit is contained in:
Baptiste Arnaud
2023-05-03 18:09:25 -04:00
parent f2d31745ca
commit 65c6f66a5c
4 changed files with 27 additions and 24 deletions

View File

@@ -10,7 +10,9 @@ export const executeGoogleAnalyticsBlock = (
outgoingEdgeId: block.outgoingEdgeId,
clientSideActions: [
{
googleAnalytics: deepParseVariables(variables)(block.options),
googleAnalytics: deepParseVariables(variables, {
guessCorrectType: true,
})(block.options),
lastBubbleBlockId,
},
],

View File

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