processBucketing method
Implementation
Campaigns processBucketing(String visitorId, Bucketing scriptBucket, Map<String, dynamic> context) {
Campaigns result = Campaigns(visitorId, false, []);
TargetingManager targetManager = TargetingManager(visitorId, context);
// Campaign
for (BucketCampaign itemCamp in scriptBucket.campaigns) {
// Variation group
for (VariationGroup itemVarGroup in itemCamp.variationGroups) {
// Check the targeting
if (targetManager.isTargetingGroupIsOkay(itemVarGroup.targeting) == true) {
Flagship.logger(Level.DEBUG, "The Targeting for " + itemVarGroup.idVariationGroup + "is OK 👍");
String? varId = selectIdVariationWithMurMurHash(visitorId, itemVarGroup);
if (varId != null) {
// Create variation group
Campaign camp = Campaign(itemCamp.idCampaign, itemVarGroup.idVariationGroup, itemCamp.type, itemCamp.slug);
Flagship.logger(Level.DEBUG, "#### The variation choosen is $varId ###########");
var matchedVariation = itemVarGroup.variations.firstWhereOrNull((v) => v.idVariation == varId);
if (matchedVariation != null) {
camp.variation = matchedVariation;
/// Add this camp to the result
result.campaigns.add(camp);
}
// for (Variation itemVar in itemVarGroup.variations) {
// if (itemVar.idVariation == varId) {
// camp.variation = itemVar;
// }
// }
}
} else {
Flagship.logger(Level.DEBUG, "The Targeting for " + itemVarGroup.idVariationGroup + "is NOT OK 👎 ");
}
}
}
return result;
}