Skip to content

Commit

Permalink
feat(ua/ip): Added user_agent and user_ip_address support
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitesh-wingify committed Oct 6, 2023
1 parent d57274f commit 121103f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions VWOSdk.DemoApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 121103f

Please sign in to comment.