Clojure Decision SDK

The Java Software Development Kit for Kevel Decision & UserDB APIs can be used with Clojure!

Installation

Requires Java SE 8 or higher.

Add to your deps.edn file:

{:deps
  {com.adzerk/adzerk-decision-sdk {:mvn/version "1.0.0-beta.1"}}}

Examples

Fetching an Ad Decision

(ns readme-ad-request
  (:import (com.adzerk.sdk Client ClientOptions)
           (com.adzerk.sdk.generated.model DecisionRequest Placement User)))

(defn -main []
  ; Demo network, site, and ad type IDs; find your own via the Adzerk UI!
  (let [client (Client. (doto (ClientOptions. (int 23)) (.siteId (int 667480))))
        request (doto (DecisionRequest.)
                      (.placements [(doto (Placement.) (.adTypes [5]))])
                      (.keywords ["keyword1" "keyword2"])
                      (.user (doto (User.) (.key "abc"))))]
    (print (-> 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 (doto (PixelFireOptions.) (.url (.toString (.getImpressionUrl decision))))))

; Click pixel; fire when user clicks on the ad
; status: HTTP status code
; location: click target URL
(let [decision-url (.toString (.getClickUrl decision))
      pixel-results (-> client (.pixels) (.fire (doto (PixelFireOptions.) (.url decision-url))))]
  (println (str "Fired! status: " (.getStatusCode pixel-results)
                "; location: " (.getLocation pixel-results))))))

UserDB: Reading User Record

(ns readme-read-userdb
  (:use clojure.pprint)
  (:import (com.adzerk.sdk Client ClientOptions)))

(defn -main []
  ; Demo network ID; find your own via the Adzerk UI!
  (let [client (Client. (doto (ClientOptions. (int 23))))]
    (pprint (bean (-> client (.userDb) (.read "abc"))))))

UserDB: Setting Custom Properties

(ns readme-set-userdb
  (:import (com.adzerk.sdk Client ClientOptions)))

(defn -main []
  ; Demo network ID; find your own via the Adzerk UI!
  (let [client (Client. (doto (ClientOptions. (int 23))))
        props {"favoriteColor" "blue"
               "favoriteNumber" 42
               "favoriteFoods" ["strawberries", "chocolate"]}]
    (-> client (.userDb) (.setCustomProperties "abc" props))))

UserDB: Forgetting User Record

(ns readme-forget-userdb
  (:import (com.adzerk.sdk Client ClientOptions)))

(defn -main []
  ; Demo network ID and API key; find your own via the Adzerk UI!
  (let [client (Client. (doto (ClientOptions. (int 23)) (.apiKey "YOUR-API-KEY")))]
    (-> client (.userDb) (.forget "abc"))))