Esempio n. 1
0
        /// <summary>
        /// Create Visitor Attributes list
        /// </summary>
        /// <param name="userAttributes">The user's attributes</param>
        /// <param name="config">ProjectConfig instance</param>
        /// <returns>VisitorAttribute array if config is valid, null otherwise</returns>
        public static VisitorAttribute[] BuildAttributeList(UserAttributes userAttributes, ProjectConfig config)
        {
            if (config == null)
            {
                return(null);
            }

            List <VisitorAttribute> attributesList = new List <VisitorAttribute>();

            if (userAttributes != null)
            {
                foreach (var validUserAttribute in userAttributes.Where(attribute => Validator.IsUserAttributeValid(attribute)))
                {
                    var attributeId = config.GetAttributeId(validUserAttribute.Key);
                    if (!string.IsNullOrEmpty(attributeId))
                    {
                        attributesList.Add(new VisitorAttribute(entityId: attributeId, key: validUserAttribute.Key,
                                                                type: CUSTOM_ATTRIBUTE_FEATURE_TYPE, value: validUserAttribute.Value));
                    }
                }
            }

            //checks if botFiltering value is not set in the project config file.
            if (config.BotFiltering.HasValue)
            {
                attributesList.Add(new VisitorAttribute(entityId: ControlAttributes.BOT_FILTERING_ATTRIBUTE,
                                                        key: ControlAttributes.BOT_FILTERING_ATTRIBUTE, type: CUSTOM_ATTRIBUTE_FEATURE_TYPE, value: config.BotFiltering));
            }

            return(attributesList.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// Helper function to set parameters common to impression and conversion event
        /// </summary>
        /// <param name="config">ProjectConfig Configuration for the project</param>
        /// <param name="userId">string ID of user</param>
        /// <param name="userAttributes">associative array of Attributes for the user</param>
        private Dictionary <string, object> GetCommonParams(ProjectConfig config, string userId, UserAttributes userAttributes)
        {
            var comonParams = new Dictionary <string, object>();

            var visitor = new Dictionary <string, object>
            {
                { "snapshots", new object[0] },
                { "visitor_id", userId },
                { "attributes", new object[0] }
            };

            comonParams[Params.VISITORS]       = new object[] { visitor };
            comonParams[Params.PROJECT_ID]     = config.ProjectId;
            comonParams[Params.ACCOUNT_ID]     = config.AccountId;
            comonParams[Params.CLIENT_ENGINE]  = Optimizely.SDK_TYPE;
            comonParams[Params.CLIENT_VERSION] = Optimizely.SDK_VERSION;
            comonParams[Params.REVISION]       = config.Revision;
            comonParams[Params.ANONYMIZE_IP]   = config.AnonymizeIP;

            var userFeatures = new List <Dictionary <string, object> >();

            foreach (var userAttribute in userAttributes.Where(a => !string.IsNullOrEmpty(a.Key)))
            {
                if (string.Equals(userAttribute.Key, DecisionService.RESERVED_ATTRIBUTE_KEY_BUCKETING_ID))
                {
                    var userFeature = new Dictionary <string, object>
                    {
                        { "entity_id", DecisionService.RESERVED_ATTRIBUTE_KEY_BUCKETING_ID },
                        { "key", RESERVED_ATTRIBUTE_KEY_BUCKETING_ID_EVENT_PARAM_KEY },
                        { "type", CUSTOM_ATTRIBUTE_FEATURE_TYPE },
                        { "value", userAttribute.Value }
                    };
                    userFeatures.Add(userFeature);
                }
                else
                {
                    var attributeEntity = config.GetAttribute(userAttribute.Key);
                    if (attributeEntity != null && attributeEntity.Key != null)
                    {
                        var userFeature = new Dictionary <string, object>
                        {
                            { "entity_id", attributeEntity.Id },
                            { "key", attributeEntity.Key },
                            { "type", CUSTOM_ATTRIBUTE_FEATURE_TYPE },
                            { "value", userAttribute.Value }
                        };
                        userFeatures.Add(userFeature);
                    }
                }
            }


            visitor["attributes"] = userFeatures;

            return(comonParams);
        }
Esempio n. 3
0
        /// <summary>
        /// Helper function to set parameters common to impression and conversion event
        /// </summary>
        /// <param name="config">ProjectConfig Configuration for the project</param>
        /// <param name="userId">string ID of user</param>
        /// <param name="userAttributes">associative array of Attributes for the user</param>
        private Dictionary <string, object> GetCommonParams(ProjectConfig config, string userId, UserAttributes userAttributes)
        {
            var comonParams = new Dictionary <string, object>();

            var visitor = new Dictionary <string, object>
            {
                { "snapshots", new object[0] },
                { "visitor_id", userId },
                { "attributes", new object[0] }
            };

            comonParams[Params.VISITORS]         = new object[] { visitor };
            comonParams[Params.PROJECT_ID]       = config.ProjectId;
            comonParams[Params.ACCOUNT_ID]       = config.AccountId;
            comonParams[Params.CLIENT_ENGINE]    = Optimizely.SDK_TYPE;
            comonParams[Params.CLIENT_VERSION]   = Optimizely.SDK_VERSION;
            comonParams[Params.REVISION]         = config.Revision;
            comonParams[Params.ANONYMIZE_IP]     = config.AnonymizeIP;
            comonParams[Params.ENRICH_DECISIONS] = true;

            var userFeatures = new List <Dictionary <string, object> >();

            //Omit attribute values that are not supported by the log endpoint.
            foreach (var validUserAttribute in userAttributes.Where(attribute => Validator.IsUserAttributeValid(attribute)))
            {
                var attributeId = config.GetAttributeId(validUserAttribute.Key);
                if (!string.IsNullOrEmpty(attributeId))
                {
                    userFeatures.Add(new Dictionary <string, object>
                    {
                        { "entity_id", attributeId },
                        { "key", validUserAttribute.Key },
                        { "type", CUSTOM_ATTRIBUTE_FEATURE_TYPE },
                        { "value", validUserAttribute.Value }
                    });
                }
            }

            if (config.BotFiltering.HasValue)
            {
                userFeatures.Add(new Dictionary <string, object>
                {
                    { "entity_id", ControlAttributes.BOT_FILTERING_ATTRIBUTE },
                    { "key", ControlAttributes.BOT_FILTERING_ATTRIBUTE },
                    { "type", CUSTOM_ATTRIBUTE_FEATURE_TYPE },
                    { "value", config.BotFiltering }
                });
            }

            visitor["attributes"] = userFeatures;

            return(comonParams);
        }