Example #1
0
        /// <summary>
        /// Mark this user as having converted for the specified tests.
        /// </summary>
        public void ScoreConversion(string testName)
        {
            ABUser user = IdentifyUser();

            if (!user.Tests.Contains(testName) || user.Conversions.Contains(testName))
            {
                // not part of the test or already scored.
                return;
            }

            SerializableDictionary <string, Experiment> tests = GetTests();

            if (tests.ContainsKey(testName))
            {
                Experiment t = tests[testName];

                ABAlternative choice = t.GetUserAlternative(user.ID);
                choice.ScoreConversion();

                user.Conversions.Add(testName);
                user.SaveToCookie();

                SaveTests(tests);
            }
        }
Example #2
0
        public static ABUser LoadFromCookie()
        {
            ABUser user = new ABUser();

            HttpCookie inCookie = HttpContext.Current.Request.Cookies["ab"];
            if (inCookie != null)
            {
                try
                {
                    user.LoadFromINI(inCookie.Value);
                }
                catch
                {
                    // user messed with his cookie.  No worries for us.
                }

                user.SaveToCookie();
            }

            return user;
        }
Example #3
0
        public static ABUser LoadFromCookie()
        {
            ABUser user = new ABUser();

            HttpCookie inCookie = HttpContext.Current.Request.Cookies["ab"];

            if (inCookie != null)
            {
                try
                {
                    user.LoadFromINI(inCookie.Value);
                }
                catch
                {
                    // user messed with his cookie.  No worries for us.
                }

                user.SaveToCookie();
            }

            return(user);
        }
Example #4
0
        /// <summary>
        /// For the specified test, pick an alternative to always show this user, and return that alternative.
        /// </summary>
        /// <param name="test"></param>
        /// <returns></returns>
        public ABAlternative GetUserAlternative(Experiment test)
        {
            //complete an experiment as soon as we reach our required sample size...
            if (test.IsComplete)
            {
                return(test.GetBestAlternative());
            }

            ABUser        user   = IdentifyUser();
            ABAlternative choice = test.GetUserAlternative(user.ID);

            if (!user.Tests.Contains(test.TestName) && !IsBotRequest()) //don't score the participation more than once for an identified user (don't score for bots either)
            {
                choice.ScoreParticipation();
                user.Tests.Add(test.TestName);
                user.SaveToCookie();

                //persist the new participant count to the file store...
                ScoreParticipation(test.TestName, choice);
            }

            return(choice);
        }
Example #5
0
        /// <summary>
        /// If we've seen this user before, pull his info from the cookie.  If not, start tracking him.
        /// </summary>
        /// <returns></returns>
        private static ABUser IdentifyUser()
        {
            ABUser user = ABUser.LoadFromCookie();

            return(user);
        }