/// <summary> /// If variation is assigned, allocate the goal using goalIdentifier. /// </summary> /// <param name="campaignTestKey"></param> /// <param name="userId"></param> /// <param name="goalIdentifier"></param> /// <returns> /// If Variation is allocated and goal with given identifier is found, return UserAssignedInfo with valid information, otherwise, Empty UserAssignedInfo object. /// </returns> private UserAllocationInfo AllocateVariation(string campaignTestKey, string userId, string goalIdentifier, string apiName) { var userAllocationInfo = this.AllocateVariation(campaignTestKey, userId, apiName); if (userAllocationInfo.Variation != null) { if (userAllocationInfo.Campaign.Goals.TryGetValue(goalIdentifier, out Goal goal)) { userAllocationInfo.Goal = goal; } else { LogErrorMessage.TrackApiGoalNotFound(file, goalIdentifier, campaignTestKey, userId); } } else { LogErrorMessage.TrackApiVariationNotFound(file, campaignTestKey, userId); } return(userAllocationInfo); }
/// <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); }