/// <summary> /// Activates a server-side A/B test for a specified user for a server-side running campaign. /// </summary> /// <param name="campaignKey">Campaign key to uniquely identify a server-side campaign.</param> /// <param name="userId">User ID which uniquely identifies each user.</param> /// <param name="options">Dictionary for passing extra parameters to activate</param> /// <returns> /// The name of the variation in which the user is bucketed, or null if the user doesn't qualify to become a part of the campaign. /// </returns> public string Activate(string campaignKey, string userId, Dictionary <string, dynamic> options = null) { if (options == null) { options = new Dictionary <string, dynamic>(); } Dictionary <string, dynamic> customVariables = options.ContainsKey("customVariables") ? options["customVariables"] : null; Dictionary <string, dynamic> variationTargetingVariables = options.ContainsKey("variationTargetingVariables") ? options["variationTargetingVariables"] : null; if (this._validator.Activate(campaignKey, userId, options)) { var campaign = this._campaignAllocator.GetCampaign(this._settings, campaignKey); if (campaign == null || campaign.Status != Constants.CampaignStatus.RUNNING) { LogErrorMessage.CampaignNotRunning(typeof(IVWOClient).FullName, campaignKey, nameof(Activate)); return(null); } if (campaign.Type != Constants.CampaignTypes.VISUAL_AB) { LogErrorMessage.InvalidApi(typeof(IVWOClient).FullName, userId, campaignKey, campaign.Type, nameof(Activate)); return(null); } var assignedVariation = this.AllocateVariation(campaignKey, userId, campaign, customVariables, variationTargetingVariables, apiName: nameof(Activate)); if (assignedVariation.Variation != null) { var trackUserRequest = ServerSideVerb.TrackUser(this._settings.AccountId, assignedVariation.Campaign.Id, assignedVariation.Variation.Id, userId, this._isDevelopmentMode); trackUserRequest.ExecuteAsync(); return(assignedVariation.Variation.Name); } } return(null); }
/// <summary> /// Gets the variation name assigned for the user for the campaign /// </summary> /// <param name="campaignKey">Campaign key to uniquely identify a server-side campaign.</param> /// <param name="userId">User ID which uniquely identifies each user.</param> /// <param name="options">Dictionary for passing extra parameters to activate</param> /// <returns> /// If variation is assigned then variation name, or Null in case of user not becoming part /// </returns> public string GetVariation(string campaignKey, string userId, Dictionary <string, dynamic> options = null) { if (options == null) { options = new Dictionary <string, dynamic>(); } Dictionary <string, dynamic> customVariables = options.ContainsKey("customVariables") ? options["customVariables"] : null; Dictionary <string, dynamic> variationTargetingVariables = options.ContainsKey("variationTargetingVariables") ? options["variationTargetingVariables"] : null; if (this._validator.GetVariation(campaignKey, userId, options)) { var campaign = this._campaignAllocator.GetCampaign(this._settings, campaignKey); if (campaign == null || campaign.Status != Constants.CampaignStatus.RUNNING) { LogErrorMessage.CampaignNotRunning(typeof(IVWOClient).FullName, campaignKey, nameof(GetVariation)); return(null); } if (campaign.Type == Constants.CampaignTypes.FEATURE_ROLLOUT) { LogErrorMessage.InvalidApi(typeof(IVWOClient).FullName, userId, campaignKey, campaign.Type, nameof(GetVariation)); return(null); } var assignedVariation = this.AllocateVariation(campaignKey, userId, campaign, customVariables, variationTargetingVariables, apiName: nameof(GetVariation)); if (assignedVariation.Variation != null) { return(assignedVariation.Variation.Name); } return(assignedVariation.Variation?.Name); } return(null); }
/// <summary> /// Returns the feature variable corresponding to the variableKey passed. It typecasts the value to the corresponding value type found in settings_file /// </summary> /// <param name="campaignKey">Campaign key to uniquely identify a server-side campaign.</param> /// <param name="variableKey">Campaign key to uniquely identify a server-side campaign.</param> /// <param name="userId">User ID which uniquely identifies each user.</param> /// <param name="options">Dictionary for passing extra parameters to activate</param> /// <returns> /// The name of the variation in which the user is bucketed, or null if the user doesn't qualify to become a part of the campaign. /// </returns> public dynamic GetFeatureVariableValue(string campaignKey, string variableKey, string userId, Dictionary <string, dynamic> options = null) { if (options == null) { options = new Dictionary <string, dynamic>(); } Dictionary <string, dynamic> customVariables = options.ContainsKey("customVariables") ? options["customVariables"] : null; Dictionary <string, dynamic> variationTargetingVariables = options.ContainsKey("variationTargetingVariables") ? options["variationTargetingVariables"] : null; var variables = new List <Dictionary <string, dynamic> >(); var variable = new Dictionary <string, dynamic>(); if (this._validator.GetFeatureVariableValue(campaignKey, variableKey, userId, options)) { var campaign = this._campaignAllocator.GetCampaign(this._settings, campaignKey); if (campaign == null || campaign.Status != Constants.CampaignStatus.RUNNING) { LogErrorMessage.CampaignNotRunning(typeof(IVWOClient).FullName, campaignKey, nameof(GetFeatureVariableValue)); return(null); } if (campaign.Type == Constants.CampaignTypes.VISUAL_AB) { LogErrorMessage.InvalidApi(typeof(IVWOClient).FullName, userId, campaignKey, campaign.Type, nameof(GetFeatureVariableValue)); return(null); } var assignedVariation = this.AllocateVariation(campaignKey, userId, campaign, customVariables, variationTargetingVariables, apiName: nameof(GetFeatureVariableValue)); if (campaign.Type == Constants.CampaignTypes.FEATURE_ROLLOUT) { variables = campaign.Variables; } else if (campaign.Type == Constants.CampaignTypes.FEATURE_TEST) { if (!assignedVariation.Variation.IsFeatureEnabled) { LogInfoMessage.FeatureNotEnabledForUser(typeof(IVWOClient).FullName, campaignKey, userId, nameof(GetFeatureVariableValue)); assignedVariation = this.GetControlVariation(campaign, campaign.Variations.Find(1, (new VariationAllocator()).GetVariationId)); } else { LogInfoMessage.FeatureEnabledForUser(typeof(IVWOClient).FullName, campaignKey, userId, nameof(GetFeatureVariableValue)); } variables = assignedVariation.Variation.Variables; } variable = this.GetVariable(variables, variableKey); if (variable == null || variable.Count == 0) { LogErrorMessage.VariableNotFound(typeof(IVWOClient).FullName, variableKey, campaignKey, campaign.Type, userId, nameof(GetFeatureVariableValue)); return(null); } else { LogInfoMessage.VariableFound(typeof(IVWOClient).FullName, variableKey, campaignKey, campaign.Type, variable["value"].ToString(), userId, nameof(GetFeatureVariableValue)); } return(this._segmentEvaluator.getTypeCastedFeatureValue(variable["value"], variable["type"])); } return(null); }
/// <summary> /// Identifies whether the user becomes a part of feature rollout/test or not. /// </summary> /// <param name="campaignKey">Campaign key to uniquely identify a server-side campaign.</param> /// <param name="userId">User ID which uniquely identifies each user.</param> /// <param name="options">Dictionary for passing extra parameters to activate</param> /// <returns> /// /// A boolean value based on whether the impression was made to the VWO server. /// True, if an impression event is successfully being made to the VWO server for report generation. /// False, If userId provided is not part of campaign or when unexpected error comes and no impression call is made to the VWO server. /// </returns> public bool IsFeatureEnabled(string campaignKey, string userId, Dictionary <string, dynamic> options = null) { if (options == null) { options = new Dictionary <string, dynamic>(); } Dictionary <string, dynamic> customVariables = options.ContainsKey("customVariables") ? options["customVariables"] : null; Dictionary <string, dynamic> variationTargetingVariables = options.ContainsKey("variationTargetingVariables") ? options["variationTargetingVariables"] : null; if (this._validator.IsFeatureEnabled(campaignKey, userId, options)) { var campaign = this._campaignAllocator.GetCampaign(this._settings, campaignKey); if (campaign == null || campaign.Status != Constants.CampaignStatus.RUNNING) { LogErrorMessage.CampaignNotRunning(typeof(IVWOClient).FullName, campaignKey, nameof(IsFeatureEnabled)); return(false); } if (campaign.Type == Constants.CampaignTypes.VISUAL_AB) { LogErrorMessage.InvalidApi(typeof(IVWOClient).FullName, userId, campaignKey, campaign.Type, nameof(IsFeatureEnabled)); return(false); } var assignedVariation = this.AllocateVariation(campaignKey, userId, campaign, customVariables, variationTargetingVariables, apiName: nameof(IsFeatureEnabled)); if (campaign.Type == Constants.CampaignTypes.FEATURE_TEST) { if (assignedVariation.Variation != null) { var trackUserRequest = ServerSideVerb.TrackUser(this._settings.AccountId, assignedVariation.Campaign.Id, assignedVariation.Variation.Id, userId, this._isDevelopmentMode); trackUserRequest.ExecuteAsync(); var result = assignedVariation.Variation.IsFeatureEnabled; if (result) { LogInfoMessage.FeatureEnabledForUser(typeof(IVWOClient).FullName, campaignKey, userId, nameof(IsFeatureEnabled)); } else { LogInfoMessage.FeatureNotEnabledForUser(typeof(IVWOClient).FullName, campaignKey, userId, nameof(IsFeatureEnabled)); } return(result); } return(false); } return(true); } else { return(false); } }
/// <summary> /// Tracks a conversion event for a particular user for a running server-side campaign. /// </summary> /// <param name="campaignKey">Campaign key to uniquely identify a server-side campaign.</param> /// <param name="userId">User ID which uniquely identifies each user.</param> /// <param name="goalIdentifier">The Goal key to uniquely identify a goal of a server-side campaign.</param> /// <param name="options">Dictionary for passing extra parameters to activate</param> /// <returns> /// A boolean value based on whether the impression was made to the VWO server. /// True, if an impression event is successfully being made to the VWO server for report generation. /// False, If userId provided is not part of campaign or when unexpected error comes and no impression call is made to the VWO server. /// </returns> public bool Track(string campaignKey, string userId, string goalIdentifier, Dictionary <string, dynamic> options = null) { if (options == null) { options = new Dictionary <string, dynamic>(); } string revenueValue = options.ContainsKey("revenueValue") ? options["revenueValue"].ToString() : null; Dictionary <string, dynamic> customVariables = options.ContainsKey("customVariables") ? options["customVariables"] : null; Dictionary <string, dynamic> variationTargetingVariables = options.ContainsKey("variationTargetingVariables") ? options["variationTargetingVariables"] : null; string goalTypeToTrack = options.ContainsKey("goalTypeToTrack") ? options["goalTypeToTrack"] : null; bool shouldTrackReturningUser = options.ContainsKey("shouldTrackReturningUser") ? options["shouldTrackReturningUser"] : this._shouldTrackReturningUser; if (this._validator.Track(campaignKey, userId, goalIdentifier, revenueValue, options)) { goalTypeToTrack = !string.IsNullOrEmpty(goalTypeToTrack) ? goalTypeToTrack : this._goalTypeToTrack != null ? this._goalTypeToTrack : Constants.GoalTypes.ALL; var campaign = this._campaignAllocator.GetCampaign(this._settings, campaignKey); if (campaign == null || campaign.Status != Constants.CampaignStatus.RUNNING) { LogErrorMessage.CampaignNotRunning(typeof(IVWOClient).FullName, campaignKey, nameof(Track)); return(false); } if (campaign.Type == Constants.CampaignTypes.FEATURE_ROLLOUT) { LogErrorMessage.InvalidApi(typeof(IVWOClient).FullName, userId, campaignKey, campaign.Type, nameof(Track)); return(false); } var assignedVariation = this.AllocateVariation(campaignKey, userId, campaign, customVariables, variationTargetingVariables, goalIdentifier: goalIdentifier, apiName: nameof(Track)); var variationName = assignedVariation.Variation?.Name; var selectedGoalIdentifier = assignedVariation.Goal?.Identifier; if (string.IsNullOrEmpty(variationName) == false) { if (string.IsNullOrEmpty(selectedGoalIdentifier) == false) { if (goalTypeToTrack != assignedVariation.Goal.Type && goalTypeToTrack != Constants.GoalTypes.ALL) { return(false); } if (!this.isGoalTriggerRequired(campaignKey, userId, goalIdentifier, variationName, shouldTrackReturningUser)) { return(false); } bool sendImpression = true; if (assignedVariation.Goal.IsRevenueType() && string.IsNullOrEmpty(revenueValue)) { sendImpression = false; LogErrorMessage.TrackApiRevenueNotPassedForRevenueGoal(file, goalIdentifier, campaignKey, userId); } else if (assignedVariation.Goal.IsRevenueType() == false) { revenueValue = null; } if (sendImpression) { var trackGoalRequest = ServerSideVerb.TrackGoal(this._settings.AccountId, assignedVariation.Campaign.Id, assignedVariation.Variation.Id, userId, assignedVariation.Goal.Id, revenueValue, this._isDevelopmentMode); trackGoalRequest.ExecuteAsync(); return(true); } } else { LogErrorMessage.TrackApiGoalNotFound(file, goalIdentifier, campaignKey, userId); } } } return(false); }