The ayeT-Studios Rewarded Video SDK for HTML5 allows web publishers to request and run rewarded video ads within their page.
<script src="https://cdn.ayet.io/offerwall/js/ayetvideosdk.min.js"></script> var placementId=3; // This is the numeric id of your web placement
var externalIdentifier="{your user identifier}";
var optionalParameter=null; // or a string(32)
AyetVideoSdk.init(placementId, externalIdentifier, optionalParameter).then(function() {
console.log("finished initialization!");
});/* An error occured when trying to play a video ad. After this callback, no video is being rendered and a new ad has to be requested first: */
AyetVideoSdk.callbackError = function(e) {console.log("callbackError: "+JSON.stringify(e));};
/* After this callback, a video will start playing: */
AyetVideoSdk.callbackPlaying = function() {console.log("callbackPlaying");};
/* After this callback, playing the video is finished and the player is closed: */
AyetVideoSdk.callbackComplete = function() {console.log("callbackComplete");};
/* This callback is sent once a second while a video is being played: */
AyetVideoSdk.callbackProgress = function(remainingSeconds) {console.log("callbackProgress: "+Math.round(remainingSeconds)+"s remaining");};
/* This callback is sent if a video has been completed and the impression has gone through fraud checks (see "Rewarding Users" for more details): */
AyetVideoSdk.callbackRewarded = function(details) {appendLog("callbackRewarded: "+JSON.stringify(details));};AyetVideoSdk.requestAd(
'{your_rewarded_video_adslot_name}',
function() { // success callback function
console.log("requestAd successful");
},
function(msg) { // error callback function
appendLog("requestAd failed: "+msg);
}
); /* Play the ad in a pre-defined div (consult your account manager to determine if size & location is appropriate for all demand partners): */
AyetVideoSdk.playInPageAd('video_div');
/* Play the ad full size (100% of your page viewport): */
AyetVideoSdk.playFullsizeAd();
/* Play the ad fullscreen (this temporarily switches the browser to fullscreen mode): */
AyetVideoSdk.playFullscreenAd();/* This example assumes an ad was requested a longer time ago and we're unsure if the bid expired already */
if (AyetVideoSdk.isAdAvailable()) {
AyetVideoSdk.playInPageAd('{your_html_video_div_id}');
} else {
/* Either abort and notify the user or request and play a fresh ad: */
AyetVideoSdk.requestAd(
'{your_rewarded_video_adslot_name}',
function() { // success callback function
AyetVideoSdk.playInPageAd('{your_html_video_div_id}');
},
function(msg) { // error callback function
appendLog("requestAd failed: "+msg);
}
);
}/* Interrupt a playing ad and destroy the player (to play another ad later, a new call to AyetVideoSdk.requestAd is required) */
AyetVideoSdk.destroy();/* This callback is sent if a video has been completed and the impression has gone through fraud checks: */
AyetVideoSdk.callbackRewarded = function(details) {appendLog("callbackRewarded: "+JSON.stringify(details));};
/* Example output:
callbackRewarded: {"status":"success","rewarded":true,"externalIdentifier":"your user identifier","currency":10,"conversionId":"aef8cd370cfe-video-u94-adbcec159f76","signature":"f98c35ae4facef42dce5b31f6a5f9f0e8819b8ec"}
*/
/* Example output if custom parameters were set:
callbackRewarded: {"status":"success","rewarded":true,"externalIdentifier":"your user identifier","currency":10,"conversionId":"aef8cd370cfe-video-u94-adbcec159f76","custom_1":"bar", "custom_3":"foo","signature":"e35d78be4facef42dce5b31f6a5f9f0e8821c3de"}
*/$signature = hash_hmac('sha1',
$response['externalIdentifier'] .
$response['currency'] .
$response['conversionId'] .
(isset($response['custom_1']) ? isset($response['custom_1'] : '') .
(isset($response['custom_2']) ? isset($response['custom_2'] : '') .
(isset($response['custom_3']) ? isset($response['custom_3'] : '') .
(isset($response['custom_4']) ? isset($response['custom_4'] : '') .
(isset($response['custom_5']) ? isset($response['custom_5'] : '')
, $user->publisher->user->api_key);/* Example of setting custom parameters: */
AyetVideoSdk.setCustomParameter("custom_1", "bar");
AyetVideoSdk.setCustomParameter("custom_3", "foo");
/* Example of unsetting custom parameter: */
AyetVideoSdk.setCustomParameter("custom_1", null);