User Context
The user context serves as a unique identifier for individual users and plays a critical role in ensuring consistent feature rollouts across sessions and devices. Typically represented as a object, the user context includes an id key that uniquely identifies the user.
In addition to the user ID, the context can incorporate various attributes to support advanced targeting and segmentation strategies. These may include:
- custom-variables: User-specific data points for personalized experiences.
- user-agent: Information about the user's device, browser, or operating system.
- ip-address: Location-based data to enable geo-targeting.
By leveraging these attributes, organizations can deliver precisely targeted features, maintain personalization consistency, and conduct granular experimentation for improved user engagement and performance analysis.
📘 Important Note
The user context attributes differ from the attributes set using the setAttribute API.
- User Context Attributes: Primarily used for targeting purposes during feature rollouts and experimentation. These attributes help determine which users are eligible for specific features or variations.
- setAttribute API Attributes: Specifically designed for post-segmentation analysis, allowing you to segment and analyze experiment results based on defined user characteristics.
🚧 Current Limitation
Wingify does not support using user context attributes directly as post-segmentation filters in the reporting section of Wingify applications. For post-segmentation, it is recommended to rely on attributes set via the setAttribute API.
#Usage
context := map[string]interface{}{
"id": "unique_user_id", // Set a unique user identifier
// Create custom variables
"customVariables": map[string]interface{}{
"age": 25,
"location": "US",
},
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
"ipAddress": "1.1.1.1",
"bucketingSeed": "your-bucketing-seed",
}
// Check if a feature flag is enabled
getFlag, err := wingifyClient.GetFlag("feature_key", context)
if err != nil {
log.Printf("Error getting feature flag: %v", err)
} else {
isFeatureEnabled := getFlag.IsEnabled()
fmt.Println("Is feature enabled?", isFeatureEnabled)
// Get a variable value with a default fallback
variableValue := getFlag.GetVariable("feature_variable", "default_value")
fmt.Println("Variable value:", variableValue)
}
// Track a custom event
trackResponse, err := wingifyClient.TrackEvent("event_name", context, nil)
if err != nil {
log.Printf("Error tracking event: %v", err)
} else {
fmt.Println("Event tracked:", trackResponse)
}
// Set multiple custom attributes
attributeMap := map[string]interface{}{
"attribute-name": "attribute-value",
}
err = wingifyClient.SetAttribute(attributeMap, context)
if err != nil {
log.Printf("Error setting attributes: %v", err)
}
#User Context keys
| Paramter |
|---|
| **id** _Required_ |
📘 Note
You need to pass Gateway Service configuration while initializing the SDK for targeting (pre-segmentation using user-agent or IP-address-related segments).