From 121103f8a36b79789599385d648203caedbcd460 Mon Sep 17 00:00:00 2001 From: Rohitesh Dutta Date: Fri, 6 Oct 2023 14:04:41 +0530 Subject: [PATCH] feat(ua/ip): Added user_agent and user_ip_address support --- VWOSdk.DemoApp/Controllers/HomeController.cs | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/VWOSdk.DemoApp/Controllers/HomeController.cs b/VWOSdk.DemoApp/Controllers/HomeController.cs index f48e45e..4d0d66f 100644 --- a/VWOSdk.DemoApp/Controllers/HomeController.cs +++ b/VWOSdk.DemoApp/Controllers/HomeController.cs @@ -65,6 +65,15 @@ public IActionResult Ab([FromQuery] string user) string activateResponse = null, getVariationResponse = null; bool trackResponse = false; + // Get the user agent and IP address from the HTTP request + var httpRequest = HttpContext.Request; + string userAgent = httpRequest.Headers["User-Agent"]; // This is the user agent string of the client's browser. + string userIpAddress = httpRequest.HttpContext.Connection.RemoteIpAddress?.ToString(); // This is the IP address of the client's computer. + + // Add the user agent and IP address to the Options dictionary + options["userAgent"] = !string.IsNullOrEmpty(userAgent) ? userAgent : ""; // This key-value pair will be used to track the user's browser. + options["userIpAddress"] = !string.IsNullOrEmpty(userIpAddress) ? userIpAddress : ""; // This key-value pair can be used to track the user's IP address. + if (VWOClient != null) { @@ -92,6 +101,16 @@ public IActionResult FeatureRollout([FromQuery] string user) string CampaignKey = VWOConfig.FeatureRolloutData.CampaignKey; string campaignType = "Feature-rollout"; bool activateResponse = false; + + // Get the user agent and IP address from the HTTP request + var httpRequest = HttpContext.Request; + string userAgent = httpRequest.Headers["User-Agent"]; // This is the user agent string of the client's browser. + string userIpAddress = httpRequest.HttpContext.Connection.RemoteIpAddress?.ToString(); // This is the IP address of the client's computer. + + // Add the user agent and IP address to the Options dictionary + options["visitorUserAgent"] = !string.IsNullOrEmpty(userAgent) ? userAgent : ""; // This key-value pair will be used to track the user's browser. + options["visitorIp"] = !string.IsNullOrEmpty(userIpAddress) ? userIpAddress : ""; // This key-value pair can be used to track the user's IP address. + if (VWOClient != null) { activateResponse = VWOClient.IsFeatureEnabled(CampaignKey, userId, options); @@ -105,6 +124,16 @@ public IActionResult FeatureTest([FromQuery] string user) { var userId = string.IsNullOrEmpty(user) ? GetRandomName() : user; var options = VWOConfig.FeatureTestData.Options; + + // Get the user agent and IP address from the HTTP request + var httpRequest = HttpContext.Request; + string userAgent = httpRequest.Headers["User-Agent"]; // This is the user agent string of the client's browser. + string userIpAddress = httpRequest.HttpContext.Connection.RemoteIpAddress?.ToString(); // This is the IP address of the client's computer. + + // Add the user agent and IP address to the Options dictionary + options["visitorUserAgent"] = !string.IsNullOrEmpty(userAgent) ? userAgent : ""; // This key-value pair will be used to track the user's browser. + options["visitorIp"] = !string.IsNullOrEmpty(userIpAddress) ? userIpAddress : ""; // This key-value pair can be used to track the user's IP address. + string stringVariableKey = VWOConfig.FeatureTestData.StringVariableKey; string integerVariableKey = VWOConfig.FeatureTestData.IntegerVariableKey; string booleanVariableKey = VWOConfig.FeatureTestData.BooleanVariableKey;