コード例 #1
0
 /// <summary>
 /// Activates a server-side A/B test for a specified user for a server-side running campaign.
 /// </summary>
 /// <param name="campaignTestKey">Campaign key to uniquely identify a server-side campaign.</param>
 /// <param name="userId">User ID which uniquely identifies each user.</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 campaignTestKey, string userId)
 {
     if (this._validator.Activate(campaignTestKey, userId))
     {
         var assignedVariation = this.AllocateVariation(campaignTestKey, userId, 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);
 }
コード例 #2
0
 /// <summary>
 /// Fetch SettingsFile for provided accountId and sdkKey.
 /// </summary>
 /// <param name="accountId">ID for VWO Account.</param>
 /// <param name="sdkKey">SdkKey for Server-Side application.</param>
 /// <returns>
 /// Fetch Settings for valid accountId and sdkKey.
 /// Null for invalid parameters, unable to connect to VWO, etc.
 /// </returns>
 public static Settings GetSettingsFile(long accountId, string sdkKey)
 {
     if (Validator.GetSettings(accountId, sdkKey))
     {
         ApiRequest apiRequest = ServerSideVerb.SettingsRequest(accountId, sdkKey);
         var        settings   = apiRequest.Execute <Settings>();
         if (settings == null)
         {
             LogErrorMessage.SettingsFileCorrupted(file);
         }
         return(settings);
     }
     return(default(Settings));
 }
コード例 #3
0
        /// <summary>
        /// Tracks a conversion event for a particular user for a running server-side campaign.
        /// </summary>
        /// <param name="campaignTestKey">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="revenueValue">The Revenue to be tracked for a revenue-type goal.</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 campaignTestKey, string userId, string goalIdentifier, string revenueValue = null)
        {
            if (this._validator.Track(campaignTestKey, userId, goalIdentifier, revenueValue))
            {
                var assignedVariation      = this.AllocateVariation(campaignTestKey, userId, 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)
                    {
                        bool sendImpression = true;
                        if (assignedVariation.Goal.IsRevenueType() && string.IsNullOrEmpty(revenueValue))
                        {
                            sendImpression = false;
                            LogErrorMessage.TrackApiRevenueNotPassedForRevenueGoal(file, goalIdentifier, campaignTestKey, 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, campaignTestKey, userId);
                    }
                }
            }
            return(false);
        }