Kevel Decision API
Grab content and ad display decisions via Kevel's Decision API!
by Kevel
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/@adzerk/decision-sdk/dist/adzerk-decision-sdk.js"></script>
<h1>Kevel Native Ad Request</h1>
<p>Press the button to make an ad request, record the impression, and display both the internal JSON and HTML payload of the response. The response includes data like Impression URL, Click URL, Campaign ID, Metadata, and more. (Note: May not work if you're using an ad blocker).</p>
<button type="button" onclick="requestNativeAd()">Request Ad</button>
<hr />
<h4>Image:</h4>
<div id="div0">
<code>(Nothing yet; please click the button!)</code>
</div>
<h4>JSON Response:</h4>
<code id="response">(Nothing yet; please click the button!)</code>
<h4>Click URL:</h4>
<code id="clickUrl">(Nothing yet; please click the button!)</code>
CSS
body {
margin: 10px;
background-color: #004465;
color: white;
}
h1, h2, h3, h4, h5 {
font-family: Helvetica,Arial,sans-serif;
margin: 30px 0 10px 0;
}
hr {
margin: 30px 0 30px 0;
}
JavaScript
requestNativeAd = function() {
let client = new AdzerkDecisionSdk.Client({
networkId: 23,
siteId: 667480
});
let request = {
placements: [{
adTypes: [5]
}]
};
client.decisions.get(request).then(response => {
let decision = response.decisions.div0[0];
// Inject ad contents into page
$("#div0").replaceWith(decision.contents[0].body);
$("#response").text(JSON.stringify(response));
$("#clickUrl").text(decision.clickUrl);
// Record the impression
client.pixels.fire({
url: decision.impressionUrl
});
}).catch(error => {
console.log("ERROR!", error.toString());
});
};