/// <summary> /// Allocate Campaign based on userStorageMap, trafficAllocation by computing userHash for userId and provided CampaignTKey. /// </summary> /// <param name="settings"></param> /// <param name="userStorageMap"></param> /// <param name="campaignKey"></param> /// <param name="userId"></param> /// <param name="apiName">Api name which called this implementation, Activate/GetVariation/Track. This is for logging purpose.</param> /// <returns></returns> public BucketedCampaign Allocate(AccountSettings settings, UserStorageMap userStorageMap, string campaignKey, string userId, string apiName = null) { BucketedCampaign allocatedCampaign = null; BucketedCampaign requestedCampaign = settings.Campaigns.Find((campaign) => campaign.Key.Equals(campaignKey)); if (requestedCampaign != null) { allocatedCampaign = AllocateCampaign(userId, campaignKey, userStorageMap, requestedCampaign); if (allocatedCampaign != null) { if (allocatedCampaign.Status.Equals(Constants.Campaign.STATUS_RUNNING, System.StringComparison.InvariantCultureIgnoreCase)) { LogInfoMessage.UserEligibilityForCampaign(file, userId, true); return(allocatedCampaign); } } } LogErrorMessage.CampaignNotRunning(file, campaignKey, apiName); LogInfoMessage.UserEligibilityForCampaign(file, userId, false); LogDebugMessage.UserNotPartOfCampaign(file, userId, campaignKey, nameof(Allocate)); return(null); }
/// <summary> /// Instantiate a VWOClient to call Activate, GetVariation and Track apis for given user and goal. /// </summary> /// <param name="settingFile">Settings as provided by GetSettings call.</param> /// <param name="isDevelopmentMode">When running in development or non-production mode. This ensures no operations are tracked on VWO account.</param> /// <param name="batchData">Event batching requestTimeInterval,eventsPerRequest,flushCallback value.</param> /// <param name="userStorageService">UserStorageService to Get and Save User-assigned variations.</param> /// <param name="goalTypeToTrack">Specify which goalType to track.</param> /// <param name="shouldTrackReturningUser">Should track returning user or not.</param> /// <param name="integrations">Integration Event Listener onEvent callback</param> /// <returns> /// IVWOClient instance to call Activate, GetVariation and Track apis for given user and goal. /// </returns> public static IVWOClient Launch(Settings settingFile, bool isDevelopmentMode = false, IUserStorageService userStorageService = null, BatchEventData batchData = null, string goalTypeToTrack = Constants.GoalTypes.ALL, bool shouldTrackReturningUser = false, HookManager integrations = null) { if (Validator.SettingsFile(settingFile)) { LogDebugMessage.ValidConfiguration(file); AccountSettings accountSettings = SettingsProcessor.ProcessAndBucket(settingFile); LogDebugMessage.SettingsFileProcessed(file); if (accountSettings == null) { return(null); } if (isDevelopmentMode) { LogDebugMessage.SetDevelopmentMode(file); } //integration var vwoClient = new VWO(accountSettings, Validator, userStorageService, CampaignAllocator, SegmentEvaluator, VariationAllocator, isDevelopmentMode, batchData, goalTypeToTrack, shouldTrackReturningUser, integrations); LogDebugMessage.SdkInitialized(file); return(vwoClient); } LogErrorMessage.ProjectConfigCorrupted(file); return(null); }
internal static void Configure(ILogWriter logger) { if (logger != null) { Logger = logger; LogDebugMessage.CustomLoggerUsed(file); } else { Logger = new DefaultLogWriter(); LogErrorMessage.CustomLoggerMisconfigured(file); } }
/// <summary> /// Allocate Campaign based on userStorageMap, of if userStorageMap is not present based on trafficAllocation. /// </summary> /// <param name="userId"></param> /// <param name="campaignKey"></param> /// <param name="userStorageMap"></param> /// <param name="requestedCampaign"></param> /// <returns></returns> private BucketedCampaign AllocateCampaign(string userId, string campaignKey, UserStorageMap userStorageMap, BucketedCampaign requestedCampaign) { BucketedCampaign allocatedCampaign = null; LogDebugMessage.CheckUserEligibilityForCampaign(file, campaignKey, requestedCampaign.PercentTraffic, userId); if (userStorageMap == null) { allocatedCampaign = AllocateByTrafficAllocation(userId, requestedCampaign); } else if (userStorageMap.CampaignKey.Equals(requestedCampaign.Key)) { allocatedCampaign = requestedCampaign; } return(allocatedCampaign); }
/// <summary> /// Allocate Variation by checking previously assigned variation if userProfileMap is provided, else by computing User Hash and matching it in bucket for eligible variation. /// </summary> /// <param name="userProfileMap"></param> /// <param name="campaign"></param> /// <param name="userId"></param> /// <returns></returns> public Variation Allocate(UserProfileMap userProfileMap, BucketedCampaign campaign, string userId) { if (campaign == null) { return(null); } if (userProfileMap == null) { double maxVal = Constants.Variation.MAX_TRAFFIC_VALUE; double multiplier = maxVal / campaign.PercentTraffic / 100; ///This is to evenly spread all user among variations. var bucketValue = this._userHasher.ComputeBucketValue(userId, maxVal, multiplier, out double hashValue); var selectedVariation = campaign.Variations.Find(bucketValue); LogDebugMessage.VariationHashBucketValue(file, userId, campaign.Key, campaign.PercentTraffic, hashValue, bucketValue); return(selectedVariation); } return(campaign.Variations.Find(userProfileMap.VariationName, GetVariationName)); }
/// <summary> /// Allocate variation by checking UserProfileService, Campaign Traffic Allocation and compute UserHash to check variation allocation by bucketing. /// </summary> /// <param name="campaignTestKey"></param> /// <param name="userId"></param> /// <returns> /// If Variation is allocated, returns UserAssignedInfo with valid details, else return Empty UserAssignedInfo. /// </returns> private UserAllocationInfo AllocateVariation(string campaignTestKey, string userId, string apiName = null) { UserProfileMap userProfileMap = this._userProfileService.GetUserMap(campaignTestKey, userId); BucketedCampaign selectedCampaign = this._campaignAllocator.Allocate(this._settings, userProfileMap, campaignTestKey, userId, apiName); if (selectedCampaign != null) { Variation variation = this._variationAllocator.Allocate(userProfileMap, selectedCampaign, userId); if (variation != null) { LogInfoMessage.VariationAllocated(file, userId, campaignTestKey, variation.Name); LogDebugMessage.GotVariationForUser(file, userId, campaignTestKey, variation.Name, nameof(AllocateVariation)); this._userProfileService.SaveUserMap(userId, selectedCampaign.Key, variation.Name); return(new UserAllocationInfo(variation, selectedCampaign)); } } LogInfoMessage.NoVariationAllocated(file, userId, campaignTestKey); return(new UserAllocationInfo()); }
/// <summary> /// Instantiate a VWOClient to call Activate, GetVariation and Track apis for given user and goal. /// </summary> /// <param name="settingFile">Settings as provided by GetSettings call.</param> /// <param name="isDevelopmentMode">When running in development or non-production mode. This ensures no operations are tracked on VWO account.</param> /// <param name="userProfileService">UserProfileService to Lookup and Save User-assigned variations.</param> /// <returns> /// IVWOClient instance to call Activate, GetVariation and Track apis for given user and goal. /// </returns> public static IVWOClient Instantiate(Settings settingFile, bool isDevelopmentMode = false, IUserProfileService userProfileService = null) { if (Validator.SettingsFile(settingFile)) { LogDebugMessage.ValidConfiguration(file); AccountSettings accountSettings = SettingsProcessor.ProcessAndBucket(settingFile); LogDebugMessage.SettingsFileProcessed(file); if (accountSettings == null) { return(null); } if (isDevelopmentMode) { LogDebugMessage.SetDevelopmentMode(file); } var vwoClient = new VWO(accountSettings, Validator, userProfileService, CampaignAllocator, VariationAllocator, isDevelopmentMode); LogDebugMessage.SdkInitialized(file); return(vwoClient); } LogErrorMessage.ProjectConfigCorrupted(file); return(null); }
internal static void Configure(LogLevel logLevel) { LogLevel = logLevel; LogDebugMessage.LogLevelSet(file, logLevel); }