getConfiguration method

JSObject getConfiguration(
  1. MethodCall call
)

Maps the configuration settings for the Amplitude SDK to a JavaScript object.

For more details on configuring the SDK, refer to the official documentation: https://amplitude.com/docs/sdks/analytics/browser/browser-sdk-2#configure-the-sdk

Returns a map containing the configuration settings.

Implementation

JSObject getConfiguration(MethodCall call) {
  var configuration = call.arguments as Map;
  if (configuration['autocapture'] is Map) {
    // formInteractions, fileDownloads, elementInteractions are not supported in flutter web
    configuration['autocapture']['formInteractions'] = false;
    configuration['autocapture']['fileDownloads'] = false;
    configuration['autocapture']['elementInteractions'] = false;
  }
  JSObject configurationJS = configuration.jsify() as JSObject;

  // defaultTracking is not supported in flutter web
  if (configuration.containsKey('defaultTracking')) {
    configurationJS.delete('defaultTracking'.toJS);
  }

  if (configuration.containsKey('logLevel')) {
    var logLevelString = configuration['logLevel'] as String;
    configurationJS['logLevel'] =
        LogLevel.values.byName(logLevelString).index.toJS;
  }

  if (configuration.containsKey('serverZone')) {
    var serverZoneString = configuration['serverZone'] as String;
    serverZoneString.toUpperCase();
    configurationJS['serverZone'] = serverZoneString.toUpperCase().toJS;
  }

  return configurationJS;
}