screen method

  1. @override
Future<void> screen({
  1. required String screenName,
  2. Map<String, Object>? properties,
  3. Map<String, Object?>? options,
})

Implementation

@override
Future<void> screen({
  required String screenName,
  Map<String, Object>? properties,
  Map<String, Object?>? options,
}) async {
  // The screen name argument wins over a properties `$screen_name`.
  // beforeSend still runs after this and can change the name.
  final propsWithScreenName = _withWebContext({
    ...?properties,
    PostHogPropertyName.screenName: screenName,
  });

  final processedEvent = _runBeforeSend(
    PostHogEventName.screen,
    propsWithScreenName,
    options: options,
  );
  if (processedEvent == null) {
    printIfDebug('[PostHog] Screen event dropped by beforeSend: $screenName');
    return;
  }

  if (processedEvent.event != PostHogEventName.screen) {
    await _sendCapture(processedEvent);
    return;
  }

  final finalScreenName =
      processedEvent.properties?[PostHogPropertyName.screenName] as String? ??
          screenName;
  _currentScreen = finalScreenName;
  processedEvent.properties?.remove(PostHogPropertyName.screenName);
  final extracted = CaptureUtils.extractUserProperties(
    properties: processedEvent.properties,
    userProperties: processedEvent.userProperties,
    userPropertiesSetOnce: processedEvent.userPropertiesSetOnce,
  );
  final remaining = _withOptionProperties(
    extracted.properties,
    processedEvent.options,
    PostHogEventName.screen,
  );
  final userProperties = extracted.userProperties;
  final userPropertiesSetOnce = extracted.userPropertiesSetOnce;

  return handleWebMethodCall(
    MethodCall('screen', {
      'screenName': finalScreenName,
      'automaticPropertiesApplied': true,
      if (remaining != null && remaining.isNotEmpty) 'properties': remaining,
      if (userProperties != null)
        'userProperties': PropertyNormalizer.normalize(userProperties),
      if (userPropertiesSetOnce != null)
        'userPropertiesSetOnce':
            PropertyNormalizer.normalize(userPropertiesSetOnce),
    }),
  );
}