grantEventsOf function
The chance events a grantChance answer's facts call for:
Digia Gamification Assignediff the answer carriesholdout;Digia Chance Granted(sourcetrigger) iff granted andisNew;Digia Chance Deniediff denied with adenyReasonandisNew.
None for a test invocation, or when the answer names no campaign. Never throws: a missing or mistyped fact is no event.
Implementation
List<ChanceAnalyticsEvent> grantEventsOf(
Map<String, dynamic> answer, {
required bool granted,
required String? chanceId,
required String userId,
required String triggerId,
required String? testInvocationId,
}) {
try {
if (testInvocationId != null) return const [];
final campaignId = _textOf(answer['campaignId']);
if (campaignId == null) return const [];
final isNew = answer['isNew'] == true;
final out = <ChanceAnalyticsEvent>[];
final holdout = answer['holdout'];
if (holdout is Map) {
final group = _textOf(holdout['group']);
final period = holdout['period'];
if (group != null && period is num) {
out.add(_event(
_assignedName,
'assigned:$campaignId:$userId:$triggerId',
campaignId,
{'group': group, 'period': period},
));
}
}
if (granted && isNew && chanceId != null) {
out.add(_event(
_grantedName,
'granted:$chanceId',
campaignId,
_withoutNulls({
'chance_id': chanceId,
'source': 'trigger',
'expires_at': _textOf(answer['expiresAt']),
}),
));
}
final denyReason = _textOf(answer['denyReason']);
if (!granted && isNew && denyReason != null) {
out.add(_event(
_deniedName,
'denied:$campaignId:$userId:$triggerId',
campaignId,
_withoutNulls({'reason': denyReason, 'cap': _textOf(answer['cap'])}),
));
}
return out;
} catch (_) {
return const [];
}
}