https://github.com/wingify/vwo-ruby-sdk-ror-example
Provides a basic demo of ROR app how server-side works with VWO Ruby SDK
https://github.com/wingify/vwo-ruby-sdk-ror-example
Last synced: 3 months ago
JSON representation
Provides a basic demo of ROR app how server-side works with VWO Ruby SDK
- Host: GitHub
- URL: https://github.com/wingify/vwo-ruby-sdk-ror-example
- Owner: wingify
- License: apache-2.0
- Created: 2019-11-28T07:44:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-12T05:44:34.000Z (about 2 years ago)
- Last Synced: 2025-01-08T18:44:39.439Z (5 months ago)
- Language: Ruby
- Homepage: https://developers.vwo.com/reference#server-side-introduction
- Size: 73.2 KB
- Stars: 1
- Watchers: 18
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## VWO Ruby SDK Example (Ruby on Rails)
This repository provides a basic demo of how server-side works with VWO Ruby SDK in ruby on rails app.
### Documentation
Refer [VWO Official Server-side Documentation](https://developers.vwo.com/reference#fullstack-introduction)
### Setup
1. Install dependencies
```
# Assuming ruby is installed
gem install bundler (sudo if required)
bundle install
```2. Update your app with your settings present
Run `EDITOR=vi bin/rails credentials:edit`
Add following -
```yaml
account_id: REPLACE_THIS_WITH_CORRECT_VALUE
sdk_key: REPLACE_THIS_WITH_CORRECT_VALUE
```3. Run application
```
rails s
```## Basic usage
**Importing and Instantiation**
```ruby
require 'vwo'# Initialize client
vwo_client_instance = VWO.new(account_id, sdk_key)# Get Settings
vwo_client_instance.get_settings# Activate API
variation_name = vwo_client_instance.activate(campaign_key, user_id)# GetVariation API
variation_name = vwo_client_instance.get_variation(campaign_key, user_id)# Track API
vwo_client_instance.track(campaign_key, user_id, goal_identified, revenue_value)```
**API usage**
**User Define Logger**
Override Existing Logging
```
class VWO
class Logger
def initialize(logger_instance)
# Only log info logs and above, no debug
@@logger_instance = logger_instance || Logger.new(STDOUT, level: :info)
enddef log(level, message)
# Basic Modification
message = "#{Time.now} #{message}"
@@logger_instance.log(level, message)
end
end
end
```***Note*** - Make sure your custom logger instance has `log` method which takes `(level, message)` as arguments.
**User Storage**
To save a user you can override UserStorage methods. i.e -
```
class VWO
# Abstract class encapsulating user storage service functionality.
# Override with your own implementation for storing
# And retrieving the user.class UserStorage
# Abstract method, must be defined to fetch the
# User storage dict corresponding to the user_id.
#
# @param[String] :user_id ID for user that needs to be retrieved.
# @return[Hash] :user_storage_obj Object representing the user.
#
def get(user_id, campaign_key)
# example code to fetch it from DB column
JSON.parse(User.find_by(vwo_id: user_id).vwo_profile)
end# Abstract method, must be to defined to save
# The user dict sent to this method.
# @param[Hash] :user_storage_obj Object representing the user.
#
def set(user_obj)
# example code to save it in DB
User.update_attributes(vwo_id: user_obj.userId, vwo_profile: JSON.generate(user_obj))
end
end
end# Now use it to initiate VWO client instance
vwo_client_instance = VWO.new(account_id, sdk_key, custom_logger, UserStorage.new)
```### License
[Apache License, Version 2.0](https://github.com/wingify/vwo-ruby-sdk-ror-example/blob/master/LICENSE)
Copyright 2019 Wingify Software Pvt. Ltd.