https://github.com/wingify/vwo-go-sdk
[DEPRECATED] VWO Go SDK for server-side testing
https://github.com/wingify/vwo-go-sdk
go go-sdk server-side server-side-rendering vwo vwo-go-sdk
Last synced: 9 days ago
JSON representation
[DEPRECATED] VWO Go SDK for server-side testing
- Host: GitHub
- URL: https://github.com/wingify/vwo-go-sdk
- Owner: wingify
- License: apache-2.0
- Created: 2020-06-03T06:56:59.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-25T14:06:17.000Z (about 1 month ago)
- Last Synced: 2025-04-04T16:12:14.601Z (about 1 month ago)
- Topics: go, go-sdk, server-side, server-side-rendering, vwo, vwo-go-sdk
- Language: Go
- Homepage: https://developers.vwo.com/docs/fullstack-overview
- Size: 227 KB
- Stars: 2
- Watchers: 18
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ⚠️ [DEPRECATED] VWO GO SDK
**⚠️ This project is no longer actively developed. ⚠️**
**✅ We are only fixing critical bugs and security issues.**
**❌ No new features, enhancements, or non-critical updates will be added.**
#### Switch to *VWO Feature Management & Experimentation(FME)* – The Better Alternative! 🚀
VWO’s FME product empowers teams to seamlessly test, release, optimize, and roll back features across their entire tech stack while minimizing risk and maximizing business impact.
* Check out FME developer documentation [here](https://developers.vwo.com/v2/docs/fme-overview).
* Check [this](https://developers.vwo.com/v2/docs/sdks-release-info ) for the list of all FME-supported SDKs.**💡 Need Help?**
For migration assistance or any questions, contact us at [[email protected]]([email protected])------
[](https://github.com/wingify/vwo-go-sdk/actions?query=workflow%3ACI)

[](http://www.apache.org/licenses/LICENSE-2.0)
[](https://codecov.io/gh/wingify/vwo-go-sdk)This open source library allows you to A/B Test your Website at server-side.
## Requirements
- Works with Go 1.11.4+
## Installation
```go
go get "github.com/wingify/vwo-go-sdk"
```## Basic usage
**Importing and Instantiation**
```go
import vwo "github.com/wingify/vwo-go-sdk"
import "github.com/wingify/vwo-go-sdk/pkg/api"// Get SettingsFile
settingsFile := vwo.GetSettingsFile("accountID", "SDKKey")// Default instance of VwoInstance
vwoClientInstance, err := vwo.Launch(settingsFile)
if err != nil {
//handle err
}// Instance with custom options
vwoClientInstance, err := vwo.Launch(settingsFile, api.WithDevelopmentMode())
if err != nil {
//handle err
}// Activate API
// With Custom Variables
options := make(map[string]interface{})
options["customVariables"] = map[string]interface{}{"a": "x"}
options["variationTargetingVariables"] = map[string]interface{}{"a": "x"}
options["revenueValue"] = 12
variationName = vwoClientInstance.Activate(campaignKey, userID, options)// Without Custom Variables
variationName = vwoClientInstance.Activate(campaignKey, userID, nil)// GetVariation
// With Custom Variables
options := make(map[string]interface{})
options["customVariables"] = map[string]interface{}{"a": "x"}
variationName = vwoClientInstance.GetVariationName(campaignKey, userID, options)//Without Custom Variables
variationName = vwoClientInstance.GetVariationName(campaignKey, userID, nil)// Track API
// With Custom Variables
options := make(map[string]interface{})
options["customVariables"] = map[string]interface{}{"a": "x"}
isSuccessful = vwoClientInstance.Track(campaignKey, userID, goalIdentifier, options)// With Revenue Value
options := make(map[string]interface{})
options["revenueValue"] = 12
isSuccessful = vwoClientInstance.Track(campaignKey, userID, goalIdentifier, options)// With Custom Variables, Revenue Value, GoalTypeToTrack and ShouldTrackreturningUser
options := make(map[string]interface{})
options["customVariables"] = map[string]interface{}{"a": "x"}
options["revenueValue"] = 12
// Set specific goalType to Track
// Available GoalTypes - constants.GoalTypeRevenue, constants.GoalTypeCustom, constants.GoalTypeAll (Default)
options["goalTypeToTrack"] = constants.GoalTypeAll
// Set if a return user should be tracked, default false
options["ShouldTrackreturningUser"] = false
isSuccessful = vwoInstance.Track(campaignKey, userID, goalIdentifier, options)// For Goal Conversion in Multiple Campaign
// campaignKeys = []string{"campaignKey1", "campaignKey2", "campaignKey3"}
// For Goal Conversion in All Possible Campaigns
// campaignKeys = nil
isSuccessful = vwoInstance.Track(campaignKeys, userID, goalIdentifier, options)// FeatureEnabled API
// With Custom Varibles
options := make(map[string]interface{})
options["customVariables"] = map[string]interface{}{"a": "x"}
isSuccessful = vwoClientInstance.IsFeatureEnabled(campaignKey, userID, options)// Without Custom Variables
isSuccessful = vwoClientInstance.IsFeatureEnabled(campaignKey, userID, nil)// GetFeatureVariableValue API
// With Custom Variables
options := make(map[string]interface{})
options["customVariables"] = map[string]interface{}{"a": "x"}
variableValue = vwoClientInstance.GetFeatureVariableValue(campaignKey, variableKey, userID, options)// Without Custom Variables
variableValue = vwoClientInstance.GetFeatureVariableValue(campaignKey, variableKey, userID, nil)// Push API
isSuccessful = vwoClientInstance.Push(tagKey, tagValue, userID)
```**User Storage**
```go
import vwo "github.com/wingify/vwo-go-sdk/"
import "github.com/wingify/vwo-go-sdk/pkg/api"
import "github.com/wingify/vwo-go-sdk/pkg/schema"// declare UserStorage interface with the following Get & Set function signature
type UserStorage interface{
Get(userID, campaignKey string) UserData
Set(string, string, string, string)
}// declare a UserStorageData struct to implement UserStorage interface
type UserStorageData struct{}// Get method to fetch user variation from storage
func (us *UserStorageData) Get(userID, campaignKey string) schema.UserData {
//Example code showing how to get userData from DB
userData, ok := userDatas[campaignKey]
if ok {
for _, userdata := range userData {
if userdata.UserID == userID {
return userdata
}
}
}
/*
// UserData struct
type UserData struct {
UserID string
CampaignKey string
VariationName string
GoalIdentifier string
}
*/
return schema.UserData{}
}// Set method to save user variation to storage
func (us *UserStorageData) Set(userID, campaignKey, variationName, goalIdentifer string) {
//Example code showing how to store userData in DB
userdata := schema.UserData{
UserID: userID,
CampaignKey: campaignKey,
VariationName: variationName,
GoalIdentifier: goalIdentifier,
}flag := false
userData, ok := userDatas[userdata.CampaignKey]
if ok {
for _, user := range userData {
if user.UserID == userdata.UserID {
flag = true
}
}
if !flag {
userDatas[userdata.CampaignKey] = append(userDatas[userdata.CampaignKey], userdata)
} else {
for i, user := range userData {
if user.UserID == userdata.UserID && user.CampaignKey == userdata.CampaignKey {
userData[i].VariationName = userdata.VariationName
userData[i].GoalIdentifier = userdata.GoalIdentifier
}
}
}
} else {
userDatas[userdata.CampaignKey] = []schema.UserData{
userdata,
}
}func main() {
settingsFile := vwo.GetSettingsFile("accountID", "SDKKey")
// create UserStorageData object
storage := &UserStorageData{}vwoClientInstance, err := vwo.Launch(settingsFile, api.WithStorage(storage))
if err != nil {
//handle err
}
}```
**Custom Logger**
```go
import vwo "github.com/wingify/vwo-go-sdk"
import "github.com/wingify/vwo-go-sdk/pkg/api"// declare Log interface with the following CustomLog function signature
type Log interface {
CustomLog(level, errorMessage string)
}// declare a LogS struct to implement Log interface
type LogS struct{}// Get function to handle logs
func (c *LogS) CustomLog(level, errorMessage string) {}func main() {
settingsFile := vwo.GetSettingsFile("accountID", "SDKKey")
// create LogS object
logger := &LogS{}vwoClientInstance, err := vwo.Launch(settingsFile, api.WithLogger(logger))
if err != nil {
//handle err
}
}
```## Demo App
[Example](https://github.com/wingify/vwo-go-sdk-example)
## Documentation
Refer [Official VWO FullStack Documentation](https://developers.vwo.com/reference#fullstack-introduction)
## Local Setup
1. Install dependencies
```bash
go get .
```2. Configure the environment
```bash
bash start.sh
```## Running Unit Tests
```shell
./test.sh
```## Third-party Resources and Credits
Refer [third-party-attributions.txt](third-party-attribution.txt)
## Contributing
Please go through our [contributing guidelines](CONTRIBUTING.md)
## Code of Conduct
[Code of Conduct](CODE_OF_CONDUCT.md)
## License
[Apache License, Version 2.0](LICENSE)