onCampaignTriggered method

  1. @override
void onCampaignTriggered(
  1. InAppPayload payload
)
override

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 command.

Implementation

@override
void onCampaignTriggered(InAppPayload payload) {
  if (!_hostMounted) {
    debugPrint(
      '[Digia] WARNING: A campaign payload arrived but DigiaHost is not '
      'mounted. Wrap your app root with DigiaHost to display experiences.',
    );
  }

  final type = (payload.content['type'] as String?)?.trim().toLowerCase();
  final command =
      (payload.content['command'] as String?)?.trim().toUpperCase();

  if ((type == null || type.isEmpty) &&
      (command == null || command.isEmpty)) {
    debugPrint(
      '[Digia] WARNING: campaign dropped: neither type nor command is set: ${payload.id}',
    );
    return;
  }

  if (type == 'inline') {
    final placementKey = payload.content['placementKey'] as String?;
    if (placementKey == null || placementKey.isEmpty) {
      debugPrint(
        '[Digia] WARNING: inline payload dropped: placementKey is required when type is set: ${payload.id}',
      );
      return;
    }
    inlineController.setCampaign(placementKey, payload);
  } else {
    // Modal campaigns (SHOW_BOTTOM_SHEET / SHOW_DIALOG): route to DigiaHost.
    _controller.show(payload);
  }
}