synchronizeModifications method
Implementation
@override
Future<Error?> synchronizeModifications() async {
Flagship.logger(Level.ALL, SYNCHRONIZE_MODIFICATIONS);
Status state = Flagship.getStatus();
DataUsageTracking.sharedInstance().processDataUsageTracking(visitor);
try {
var camp = await visitor.decisionManager.getCampaigns(
Flagship.sharedInstance().envId ?? "",
visitor.visitorId,
visitor.anonymousId,
visitor.getConsent(),
visitor.getContext());
// Clear the previous modifications
visitor.modifications.clear();
// Update panic value
visitor.decisionManager.updatePanicMode(camp.panic);
if (camp.panic) {
state = Status.PANIC_ON;
// Stop batching loop when the panic mode is ON
visitor.trackingManager?.stopBatchingLoop();
} else {
state = Status.READY;
var modif = visitor.decisionManager.getModifications(camp.campaigns);
visitor.modifications.addAll(modif);
// Start Batching loop
visitor.trackingManager?.startBatchingLoop();
Flagship.logger(
Level.INFO,
SYNCHRONIZE_MODIFICATIONS_RESULTS.replaceFirst(
"%s", "${visitor.modifications.keys}"));
}
// Update the state for Flagship
visitor.flagshipDelegate.onUpdateState(state);
// Save the response for the visitor database
cacheVisitor(visitor.visitorId,
jsonEncode(VisitorCache.fromVisitor(this.visitor).toJson()));
// Update the dataUsage tracking
visitor.dataUsageTracking
.updateTroubleshooting(camp.accountSettings?.troubleshooting);
// Notify the data report
DataUsageTracking.sharedInstance().processTSFetching(this.visitor);
return null;
} catch (error) {
// Report the error
Flagship.logger(Level.EXCEPTIONS,
EXCEPTION.replaceFirst("%s", "${error.toString()}"));
DataUsageTracking.sharedInstance()
.processTroubleShootingException(visitor, error);
return Error(); // Return Error
}
}