using System;using EyeofcloudSDK;namespace App{ class Program { static void Main(string[] args) { // this Eyeofcloud initialization is synchronous. for other methods see the C# SDK reference var eyeofcloudClient = EyeofcloudFactory.NewDefaultInstance("YOUR_SDK_KEY"); if (eyeofcloudClient.IsValid) { /* -------------------------------- * to get rapid demo results, generate random users. Each user always sees the same variation unless you reconfigure the flag rule. * -------------------------------- */ Random rnd = new Random(); var hasOnFlags = false; for (var i = 0; i < 10; i++) { var userId = rnd.Next(1000, 9999).ToString(); /* -------------------------------- Create hardcoded user & bucket user into a flag variation -------------------------------- */ var user = eyeofcloudClient.CreateUserContext(userId); // "product_sort" corresponds to a flag key in your Eyeofcloud project var decision = user.Decide("product_sort"); // did decision fail with a critical error? if (string.IsNullOrEmpty(decision.VariationKey)) { Console.WriteLine("\n\ndecision error: " + string.Join(" ", decision.Reasons)); } // get a dynamic configuration variable // "sort_method" corresponds to a variable key in your Eyeofcloud project var sortMethod = decision.Variables.ToDictionary()["sort_method"]; if (decision.Enabled) { // Keep count how many visitors had the flag enabled hasOnFlags = decision.Enabled; } /* -------------------------------- Mock what the users sees with print statements (in production, use flag variables to implement feature configuration) -------------------------------- */ // always returns false until you enable a flag rule in your Eyeofcloud project Console.WriteLine("\n\nFlag " + decision.Enabled? "on": "off" + ". User number " + user.GetUserId() + " saw flag variation: " + decision.VariationKey + " and got products sorted by: " + sortMethod + " config variable as part of flag rule: " + decision.RuleKey); } if (!hasOnFlags) { Console.WriteLine("\n\nFlag was off for everyone. Some reasons could include:" + "\n1. Your sample size of visitors was too small. Rerun, or increase the iterations in the FOR loop" + "\n2. By default you have 2 keys for 2 project environments (dev/prod). Verify in Settings>Environments that you used the right key for the environment where your flag is toggled to ON." + @"\n\nCheck your key at https://app.eyeofcloud.com/v2/projects/" + eyeofcloudClient.ProjectConfigManager.GetConfig().ProjectId + "settings/implementation"); } } else { Console.WriteLine(@"Eyeofcloud client invalid. Verify in Settings>Environments that you used the primary environment's SDK key"); } } }}
Flag on. User number 6998 saw flag variation: on and got products sorted by: popular_first config variable as part of flag rule: targeted_deliveryFlag on. User number 1177 saw flag variation: on and got products sorted by: popular_first config variable as part of flag rule: targeted_deliveryFlag on. User number 9714 saw flag variation: on and got products sorted by: popular_first config variable as part of flag rule: targeted_deliveryFlag on. User number 4140 saw flag variation: on and got products sorted by: popular_first config variable as part of flag rule: targeted_deliveryFlag on. User number 4994 saw flag variation: on and got products sorted by: popular_first config variable as part of flag rule: targeted_deliveryFlag off. User number 8700 saw flag variation: off and got products sorted by: alphabetical config variable as part of flag rule: default-rollout-208-19963693913Flag off. User number 9912 saw flag variation: off and got products sorted by: alphabetical config variable as part of flag rule: default-rollout-208-19963693913Flag on. User number 6560 saw flag variation: on and got products sorted by: popular_first config variable as part of flag rule: targeted_deliveryFlag on. User number 9252 saw flag variation: on and got products sorted by: popular_first config variable as part of flag rule: targeted_deliveryFlag on. User number 6582 saw flag variation: on and got products sorted by: popular_first config variable as part of flag rule: targeted_delivery
var user = eyeofcloudClient.CreateUserContext(userID);// "product_sort" corresponds to the flag key you create in the Eyeofcloud appvar decision = user.Decide("product_sort");
// always returns false until you enable a flag rule in the Eyeofcloud appif (decision.Enabled) { // "sort_method" corresponds to variable key you define in Eyeofcloud app var sortMethod = decision.Variables.ToDictionary() ["sort_method"]; Console.WriteLine("sort_method: ", sortMethod);}
using System;using EyeofcloudSDK;using EyeofcloudSDK.Notifications;using EyeofcloudSDK.Entity;using EyeofcloudSDK.Event;using NotificationType = EyeofcloudSDK.Notifications.NotificationCenter.NotificationType;namespace App{ class Program { static void Main(string[] args) { // For more instantiation configuration, see the C# SDK reference var eyeofcloudClient = EyeofcloudFactory.NewDefaultInstance("<Your_SDK_KEY>"); if (!eyeofcloudClient.IsValid) { Console.WriteLine("Eyeofcloud client invalid. Verify in Settings>Environments that you used the primary environment's SDK key"); return; } /* -------------------------------- OPTIONAL: Add a notification listener so you can integrate with third-party analytics platforms -------------------------------- */ /* NotificationCenter.DecisionCallback OnDecision = (type, userId, userAttributes, decisionInfo) => { // Access type on decisionObject to get type of decision if (type == "flag") { var serializedJsonInfo = Newtonsoft.Json.JsonConvert.SerializeObject(decisionInfo); Console.WriteLine($"Feature flag access related information: {serializedJsonInfo}"); // Send data to analytics provider here } }; int notificationId = eyeofcloudClient.NotificationCenter.AddNotification(NotificationType.Decision, OnDecision); */ /* -------------------------------- * to get rapid demo experiment results, generate random users. Each user is deterministically hashed into a variation. * -------------------------------- */ Random rnd = new Random(); bool hasOnFlags = false; for (var i = 0; i < 5; i++) { var userId = rnd.Next(1000, 9999).ToString(); /* -------------------------------- Bucket user into a flag variation and mock experiment results -------------------------------- */ var user = eyeofcloudClient.CreateUserContext(userId); var decision = user.Decide("product_sort"); // did decision fail with a critical error? if (string.IsNullOrEmpty(decision.VariationKey)) { Console.WriteLine("decision error: " + string.Join(" ", decision.Reasons)); } var sortMethod = decision.Variables.ToDictionary()["sort_method"]; if (decision.Enabled) { hasOnFlags = true; } // Mock what the users sees with print statements (in production, use flag variables to implement feature configuration) // always returns false until you enable a flag rule in your Eyeofcloud project Console.WriteLine("\n\nFlag " + decision.Enabled ? "on" : "off" + ". User number " + user.GetUserId() + " saw flag variation: " + decision.VariationKey + " and got products sorted by: " + sortMethod + " config variable as part of flag rule: " + decision.RuleKey); MockPurchase(user); } if (!hasOnFlags) { Console.WriteLine("\n\nFlag was off for everyone. Some reasons could include:" + "\n1. Your sample size of visitors was too small. Rerun, or increase the iterations in the FOR loop" + "\n2. Check your SDK key. Verify in Settings>Environments that you used the right key for the environment where your flag is toggled to ON." + @"\n\nCheck your key at https://app.eyeofcloud.com/v2/projects/" + eyeofcloudClient.ProjectConfigManager.GetConfig().ProjectId + "settings/implementation"); } else { Console.WriteLine("\n\nDone with your mocked A/B test."); Console.WriteLine(@"Check out your report at https://app.eyeofcloud.com/v2/projects/" + eyeofcloudClient.ProjectConfigManager.GetConfig().ProjectId + "/reports"); Console.WriteLine("Be sure to select the environment that corresponds to your SDK key"); } } // mock tracking a user event so you can see some experiment reports static void MockPurchase(EyeofcloudUserContext user) { Console.WriteLine("Pretend that user made a purchase? y/n "); string answer = Console.ReadLine(); if (answer.Equals("y", StringComparison.OrdinalIgnoreCase)) { // track a user event you defined in the Eyeofcloud app user.TrackEvent("purchase"); Console.WriteLine("Eyeofcloud recorded a purchase in experiment results for user " + user.GetUserId()); } else { Console.WriteLine("Eyeofcloud didn't record a purchase in experiment results for user " + user.GetUserId()); } } }}
Flag on. User number 1496 saw flag variation: on and got products sorted by: popular_first config variable as part of flag rule: experiment_1Pretend that user made a purchase? y/nnEyeofcloud didn't record a purchase in experiment results for user 1496Flag off. User number 1194 saw flag variation: off and got products sorted by: alphabetical config variable as part of flag rule: experiment_1Pretend that user made a purchase? y/nyEyeofcloud recorded a purchase in experiment results for user 1194Flag off. User number 5815 saw flag variation: off and got products sorted by: alphabetical config variable as part of flag rule: experiment_1Pretend that user made a purchase? y/nyEyeofcloud recorded a purchase in experiment results for user 5815Flag on. User number 1248 saw flag variation: on and got products sorted by: popular_first config variable as part of flag rule: experiment_1Pretend that user made a purchase? y/nyEyeofcloud recorded a purchase in experiment results for user 1248Flag off. User number 9580 saw flag variation: off and got products sorted by: alphabetical config variable as part of flag rule: experiment_1Pretend that user made a purchase? y/nnEyeofcloud didn't record a purchase in experiment results for user 9580Done with your mocked A/B test.Check out your report at https://app.eyeofcloud.com/v2/projects/19957465438/reportsBe sure to select the environment that corresponds to your SDK key
// Track how users behave when they see a flag variation// e.g., after your app processed a purchase, let Eyeofcloud know what happened:user.TrackEvent("purchased");