reportSurveyAnswered method
Fired after a question (any block other than welcome) is answered.
stepId identifies the node. First-party Digia analytics only.
Implementation
void reportSurveyAnswered(String stepId, Map<String, dynamic> answer) {
final state = _surveyOrchestrator.state;
if (state == null) return;
final block = _blockForNode(state.config, stepId);
final values = (answer['values'] as List?)
?.map((value) => value.toString())
.toList(growable: false);
final hasValues = values != null && values.isNotEmpty;
final comment = answer['comment'] as String?;
final viewedKey = _questionKey(state.token, stepId);
final viewedAt = _questionViewedAt.remove(viewedKey);
final scale = block == null ? null : _scaleBounds(block);
final typeWire = block == null ? null : _blockTypeWire(block.type);
_events.toDigia(
SurveyQuestionAnswered(
questionId: stepId,
questionType: typeWire,
questionTitle: block == null ? null : _questionTitle(block),
answerValue: hasValues ? values.first : null,
answerText: comment ?? (hasValues ? values.join(', ') : null),
blockType: typeWire,
blockId: block?.id,
answerLabel:
block == null ? null : _answerLabel(block, values ?? const []),
answerOptions: (values != null && values.length > 1) ? values : null,
scaleMin: scale?.min,
scaleMax: scale?.max,
timeToAnswerMs: viewedAt == null
? null
: DateTime.now().millisecondsSinceEpoch - viewedAt,
answer: answer,
),
state.payload,
);
}