Esempio n. 1
0
        public void ImpressionEventTestWithAttributes()
        {
            var projectConfig = Config;
            var experiment    = Config.GetExperimentFromKey("test_experiment");
            var variation     = Config.GetVariationFromId(experiment.Key, "77210100090");
            var userId        = TestUserId;

            var userAttributes = new UserAttributes {
                { "device_type", "iPhone" },
                { "company", "Optimizely" }
            };

            var impressionEvent = UserEventFactory.CreateImpressionEvent(projectConfig, experiment, variation, userId, userAttributes, "test_experiment", "experiment");

            Assert.AreEqual(Config.ProjectId, impressionEvent.Context.ProjectId);
            Assert.AreEqual(Config.Revision, impressionEvent.Context.Revision);
            Assert.AreEqual(Config.AccountId, impressionEvent.Context.AccountId);
            Assert.AreEqual(Config.AnonymizeIP, impressionEvent.Context.AnonymizeIP);
            Assert.AreEqual(Config.BotFiltering, impressionEvent.BotFiltering);
            Assert.AreEqual(experiment, impressionEvent.Experiment);
            Assert.AreEqual(variation, impressionEvent.Variation);
            Assert.AreEqual(userId, impressionEvent.UserId);
            Assert.AreEqual(Config.BotFiltering, impressionEvent.BotFiltering);

            var expectedVisitorAttributes = EventFactory.BuildAttributeList(userAttributes, projectConfig);

            TestData.CompareObjects(expectedVisitorAttributes, impressionEvent.VisitorAttributes);
        }
Esempio n. 2
0
        /// <summary>
        /// Sends impression event.
        /// </summary>
        /// <param name="experiment">The experiment</param>
        /// <param name="variation">The variation entity</param>
        /// <param name="userId">The user ID</param>
        /// <param name="userAttributes">The user's attributes</param>
        /// <param name="flagKey">It can either be experiment key in case if ruleType is experiment or it's feature key in case ruleType is feature-test or rollout</param>
        /// <param name="ruleType">It can either be experiment in case impression event is sent from activate or it's feature-test or rollout</param>
        private void SendImpressionEvent(Experiment experiment, Variation variation, string userId,
                                         UserAttributes userAttributes, ProjectConfig config,
                                         string flagKey, string ruleType, bool enabled)
        {
            if (experiment != null && !experiment.IsExperimentRunning)
            {
                Logger.Log(LogLevel.ERROR, @"Experiment has ""Launched"" status so not dispatching event during activation.");
            }

            var userEvent = UserEventFactory.CreateImpressionEvent(config, experiment, variation, userId, userAttributes, flagKey, ruleType, enabled);

            if (userEvent == null)
            {
                return;
            }
            EventProcessor.Process(userEvent);

            if (experiment != null)
            {
                Logger.Log(LogLevel.INFO, $"Activating user {userId} in experiment {experiment.Key}.");
            }
            // Kept For backwards compatibility.
            // This notification is deprecated and the new DecisionNotifications
            // are sent via their respective method calls.
            if (NotificationCenter.GetNotificationCount(NotificationCenter.NotificationType.Activate) > 0)
            {
                var impressionEvent = EventFactory.CreateLogEvent(userEvent, Logger);
                NotificationCenter.SendNotifications(NotificationCenter.NotificationType.Activate, experiment, userId,
                                                     userAttributes, variation, impressionEvent);
            }
        }
Esempio n. 3
0
        public void ImpressionEventTest()
        {
            var projectConfig = Config;
            var experiment    = Config.GetExperimentFromKey("test_experiment");
            var variation     = Config.GetVariationFromId(experiment.Key, "77210100090");
            var userId        = TestUserId;

            var impressionEvent = UserEventFactory.CreateImpressionEvent(projectConfig, experiment, variation, userId, null, "test_experiment", "experiment");

            Assert.AreEqual(Config.ProjectId, impressionEvent.Context.ProjectId);
            Assert.AreEqual(Config.Revision, impressionEvent.Context.Revision);
            Assert.AreEqual(Config.AccountId, impressionEvent.Context.AccountId);
            Assert.AreEqual(Config.AnonymizeIP, impressionEvent.Context.AnonymizeIP);
            Assert.AreEqual(Config.BotFiltering, impressionEvent.BotFiltering);
            Assert.AreEqual(experiment, impressionEvent.Experiment);
            Assert.AreEqual(variation, impressionEvent.Variation);
            Assert.AreEqual(userId, impressionEvent.UserId);
            Assert.AreEqual(Config.BotFiltering, impressionEvent.BotFiltering);
        }