onCampaignTriggered method
Called when the CEP has evaluated a campaign and it is ready to render. Digia routes the payload to nudge or inline surfaces based on campaignKey.
Returns whether Digia accepted the campaign for rendering. true means an
experience was (or will be) shown and will emit a terminal lifecycle event
(ExperienceDismissed/ExperienceCompleted) when it ends. false means
the campaign was dropped — SDK not ready, unknown campaign key, unsupported
type, or another experience already on screen — and no terminal event will
fire. A CEP plugin holding a single in-app slot (e.g. CleverTap custom
templates) must release it immediately when this returns false.
Implementation
@override
bool onCampaignTriggered(CEPTriggerPayload payload) {
// State gating mirrors Android's DigiaInstance.onCampaignTriggered.
switch (_sdkState) {
case SDKState.notInitialized:
debugPrint(
'[Digia] campaign dropped — SDK not initialized: ${payload.campaignKey}',
);
return false;
case SDKState.initializing:
// Buffer campaigns that arrive while the engage fetch is in flight.
if (_pendingPayload != null) {
debugPrint(
'[Digia] WARNING: pending payload replaced by newer payload: ${payload.campaignKey}',
);
}
_pendingPayload = payload;
// Accepted: it will route once init resolves. The CEP keeps its in-app
// slot held until then; [_flushPendingPayloadIfAny] (or the init-failure
// path) releases it if routing ultimately drops the campaign.
return true;
case SDKState.failed:
debugPrint(
'[Digia] campaign dropped — SDK initialization failed: ${payload.campaignKey}',
);
return false;
case SDKState.ready:
return _routeCampaign(payload);
}
}