tryStartUserX static method

Future<void> tryStartUserX()

Initialize UserX if it is allowed by RemoteConfig

Implementation

static Future<void> tryStartUserX() async {
  assert(DSConstants.isInitialized);
  assert(DSRemoteConfig.I.isInitialized);

  if (kDebugMode && !_debugModeSend) return;
  if (kIsWeb || !Platform.isAndroid && !Platform.isIOS) return;

  if (DSConstants.I.isInternalVersion) {
    await startUserX();
    return;
  }

  var val = DSRemoteConfig.I.getUserXPercent();
  if (val == 0) {
    await DSRemoteConfig.I.waitForFullInit(maxWait: const Duration(seconds: 20));
    val = DSRemoteConfig.I.getUserXPercent();
    if (val == 0) return;
  }
  final sessions = DSRemoteConfig.I.getUserXSessions();
  if (sessions != 0 && sessions < DSPrefs.I.getSessionId()) {
    return;
  }

  final yid = BigInt.tryParse(yandexId) ?? BigInt.from(yandexId.hashCode);
  if ((yid % BigInt.from(100)).toInt() < val) {
    await DSMetrica.startUserX();
  }
}