/adzerk-decision-sdk-ruby

Ruby SDK for Adzerk's Decision API

Primary LanguageRuby

Adzerk Ruby Decision SDK

Ruby Software Development Kit for Adzerk Decision & UserDB APIs

Installation

Requires Ruby 2.5 or higher.

RubyGem Package

gem install adzerk_decision_sdk --pre

Or add to your Gemfile:

gem 'adzerk_decision_sdk', '~> 1.0.0-pre.beta.2'

Examples

API Credentials & Required IDs

  • Network ID: Log into Adzerk UI & use the "circle-i" help menu in upper right corner to find Network ID. Required for all SDK operations.
  • Site ID: Go to Manage Sites page to find site IDs. Required when fetching an ad decision.
  • Ad Type ID: Go to Ad Sizes page to find Ad Type IDs. Required when fetching an ad decision.
  • API Key: Go to API Keys page find active API keys. Required when writing to UserDB.
  • User Key: UserDB IDs are specified or generated for each user.

Fetching an Ad Decision

require "adzerk_decision_sdk"

# Demo network, site, and ad type IDs; find your own via the Adzerk UI!
client = AdzerkDecisionSdk::Client.new(network_id: 23, site_id: 667480)

request = {
  placements: [{ adTypes: [5] }],
  user: { key: "abc" },
  keywords: ["keyword1", "keyword2"],
}

pp client.decisions.get(request)

Recording Impression & Clicks

Use with the fetch ad example above.

# Impression pixel; fire when user sees the ad
client.pixels.fire(decision.impression_url)

# Click pixel; fire when user clicks on the ad
# status: HTTP status code
# location: click target URL
status, location = client.pixels.fire(decision.click_url)

UserDB: Reading User Record

require "adzerk_decision_sdk"

# Demo network ID; find your own via the Adzerk UI!
client = AdzerkDecisionSdk::Client.new(network_id: 23)
pp client.user_db.read("abc")

UserDB: Setting Custom Properties

require "adzerk_decision_sdk"

# Demo network ID; find your own via the Adzerk UI!
client = AdzerkDecisionSdk::Client.new(network_id: 23)

props = {
  favoriteColor: "blue",
  favoriteNumber: 42,
  favoriteFoods: ["strawberries", "chocolate"],
}

client.user_db.set_custom_properties("abc", props)

UserDB: Forgetting User Record

require "adzerk_decision_sdk"

# Demo network ID and API key; find your own via the Adzerk UI!
client = AdzerkDecisionSdk::Client.new(network_id: 23, api_key: ENV["ADZERK_API_KEY"])
client.user_db.forget("abc")

Decision Explainer

The Decision Explainer returns information on a Decision API request explaining why each candidate ad was or was not chosen.

require "adzerk_decision_sdk"

# Demo network, site, and ad type IDs; find your own via the Adzerk UI!
client = AdzerkDecisionSdk::Client.new(network_id: 23, site_id: 667480)

request = {
  placements: [{ adTypes: [5] }],
  user: { key: "abc" },
  keywords: ["keyword1", "keyword2"],
}

options = {
  include_explanation: true,
  api_key: ENV["ADZERK_API_KEY"]
}

pp client.decisions.get(request, options)

The response returns a decision object with placement, buckets, rtb logs, and result information.

{
  "div0": {
    "placement": {},
    "buckets": [],
    "rtb_log": [],
    "results": []
  }
}

The "placement" object represents a decision in which an ad may be served. A Explainer Request can have multiple placements in the request. The "buckets" array contains channel and priority information. The "rtb_logs" array contains information about Real Time Bidding. The "results" array contains the list of candidate ads that did and did not serve, along with a brief explanation.

Logging

Our logging implementation is meant to be flexible enough to fit into any common Ruby logging framework.

You can use the logger utility to output messages.

The messages have associated levels: unknown, fatal, error, warn, info, and debug.

The easiest way to integrate is to write a function that handles translating the data from the Adzerk SDK Logger into whatever logging framework you're using in the rest of your application:

require "adzerk_decision_sdk"

logger.level("Message")

client = AdzerkDecisionSdk::Client.new(logger)

Documentation

Contributing

Reporting Issues

Building

To install dependencies and run the builds associated with this SDK, please use:

bundler install
rake spec
gem build adzerk_decision_sdk.gemspec