Esempio n. 1
0
        /// <summary>
        /// Create ImpressionEvent instance from ProjectConfig
        /// </summary>
        /// <param name="projectConfig">The ProjectConfig entity</param>
        /// <param name="activatedExperiment">The Experiment entity</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">experiment key or feature key</param>
        /// <param name="ruleType">experiment or featureDecision source </param>
        /// <returns>ImpressionEvent instance</returns>
        public static ImpressionEvent CreateImpressionEvent(ProjectConfig projectConfig,
                                                            Experiment activatedExperiment,
                                                            Variation variation,
                                                            string userId,
                                                            UserAttributes userAttributes,
                                                            string flagKey,
                                                            string ruleType,
                                                            bool enabled = false)
        {
            if ((ruleType == FeatureDecision.DECISION_SOURCE_ROLLOUT || variation == null) && !projectConfig.SendFlagDecisions)
            {
                return(null);
            }

            var eventContext = new EventContext.Builder()
                               .WithProjectId(projectConfig.ProjectId)
                               .WithAccountId(projectConfig.AccountId)
                               .WithAnonymizeIP(projectConfig.AnonymizeIP)
                               .WithRevision(projectConfig.Revision)
                               .Build();

            var variationKey = "";
            var ruleKey      = "";

            if (variation != null)
            {
                variationKey = variation.Key;
                ruleKey      = activatedExperiment?.Key ?? string.Empty;
            }
            var metadata = new DecisionMetadata(flagKey, ruleKey, ruleType, variationKey, enabled);

            return(new ImpressionEvent.Builder()
                   .WithEventContext(eventContext)
                   .WithBotFilteringEnabled(projectConfig.BotFiltering)
                   .WithExperiment(activatedExperiment)
                   .WithMetadata(metadata)
                   .WithUserId(userId)
                   .WithVariation(variation)
                   .WithVisitorAttributes(EventFactory.BuildAttributeList(userAttributes, projectConfig))
                   .Build());
        }
Esempio n. 2
0
        /// <summary>
        /// Create ConversionEvent instance from ProjectConfig
        /// </summary>
        /// <param name="projectConfig">The ProjectConfig entity</param>
        /// <param name="eventKey">The event key</param>
        /// <param name="userId">The user Id</param>
        /// <param name="userAttributes">The user's attributes</param>
        /// <param name="eventTags">Array Hash representing metadata associated with the event.</param>
        /// <returns>ConversionEvent instance</returns>
        public static ConversionEvent CreateConversionEvent(ProjectConfig projectConfig,
                                                            string eventKey,
                                                            string userId,
                                                            UserAttributes userAttributes,
                                                            EventTags eventTags)
        {
            var eventContext = new EventContext.Builder()
                               .WithProjectId(projectConfig.ProjectId)
                               .WithAccountId(projectConfig.AccountId)
                               .WithAnonymizeIP(projectConfig.AnonymizeIP)
                               .WithRevision(projectConfig.Revision)
                               .Build();

            return(new ConversionEvent.Builder()
                   .WithBotFilteringEnabled(projectConfig.BotFiltering)
                   .WithEventContext(eventContext)
                   .WithEventTags(eventTags)
                   .WithEvent(projectConfig.GetEvent(eventKey))
                   .WithUserId(userId)
                   .WithVisitorAttributes(EventFactory.BuildAttributeList(userAttributes, projectConfig))
                   .Build());
        }
        /// <summary>
        /// Create ImpressionEvent instance from ProjectConfig
        /// </summary>
        /// <param name="projectConfig">The ProjectConfig entity</param>
        /// <param name="activatedExperiment">The Experiment entity</param>
        /// <param name="variation">The variation entity</param>
        /// <param name="userId">The user Id</param>
        /// <param name="userAttributes">The user's attributes</param>
        /// <returns>ImpressionEvent instance</returns>
        public static ImpressionEvent CreateImpressionEvent(ProjectConfig projectConfig,
                                                            Experiment activatedExperiment,
                                                            Variation variation,
                                                            string userId,
                                                            UserAttributes userAttributes)
        {
            var eventContext = new EventContext.Builder()
                               .WithProjectId(projectConfig.ProjectId)
                               .WithAccountId(projectConfig.AccountId)
                               .WithAnonymizeIP(projectConfig.AnonymizeIP)
                               .WithRevision(projectConfig.Revision)
                               .Build();

            return(new ImpressionEvent.Builder()
                   .WithEventContext(eventContext)
                   .WithBotFilteringEnabled(projectConfig.BotFiltering)
                   .WithExperiment(activatedExperiment)
                   .WithUserId(userId)
                   .WithVariation(variation)
                   .WithVisitorAttributes(EventFactory.BuildAttributeList(userAttributes, projectConfig))
                   .Build());
        }