Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
 internal static void Configure(ILogWriter logger)
 {
     if (logger != null)
     {
         Logger = logger;
         LogDebugMessage.CustomLoggerUsed(file);
     }
     else
     {
         Logger = new DefaultLogWriter();
         LogErrorMessage.CustomLoggerMisconfigured(file);
     }
 }
Exemplo n.º 4
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));
 }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        /// <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);
        }