Visitor constructor

Visitor(
  1. FlagshipConfig config,
  2. String visitorId,
  3. bool _isAuthenticated,
  4. Map<String, Object> context, {
  5. bool hasConsented = true,
})

Create new instance for visitor

config: this object manage the mode of the sdk and other params visitorId : the user ID for the visitor context : Map that represent the conext for the visitor

Implementation

Visitor(this.config, this.visitorId, this._isAuthenticated,
    Map<String, Object> context,
    {bool hasConsented = true}) {
  if (_isAuthenticated == true) {
    this.anonymousId = FlagshipTools.generateFlagshipId();
  } else {
    anonymousId = null;
  }

  /// Init Tracking manager
  switch (config.trackingManagerConfig.batchStrategy) {
    case BatchCachingStrategy.BATCH_CONTINUOUS_CACHING:
      trackingManager = TrackingManageContinuousStrategy(
          Service(http.Client()),
          config.trackingManagerConfig,
          this.config.hitCacheImp ?? DefaultCacheHitImp());
      break;
    case BatchCachingStrategy.BATCH_PERIODIC_CACHING:
      trackingManager = TrackingManagerPeriodicStrategy(
          Service(http.Client()),
          config.trackingManagerConfig,
          this.config.hitCacheImp ?? DefaultCacheHitImp());
      break;
    default:
      trackingManager = TrackingManager(Service(http.Client()),
          config.trackingManagerConfig, DefaultCacheHitImp());
      break;
  }

  /// Load preset_Context
  this.updateContextWithMap(FlagshipContextManager.getPresetContextForApp());

  /// Update context
  this.updateContextWithMap(context);

  /// Set delegate
  _visitorDelegate = VisitorDelegate(this);

  /// Set the consent
  _hasConsented = hasConsented;

  /// Load the hits in cache if exist
  _visitorDelegate.lookupHits();

  /// Lookup for the cached visitor data
  _visitorDelegate.lookupVisitor(this.visitorId);

  /// Send the consent hit
  _visitorDelegate.sendHit(Consent(hasConsented: _hasConsented));

  DataUsageTracking.sharedInstance()
      .configureDataUsageWithVisitor(null, this);
}