The AdinPlay library is a JavaScript library for displaying ads on your website. This document explains how to add the AdinPlay library to your site.
Adding the following code (known as the "JavaScript snippet") to your site's templates is the easiest way to get started using AdinPlay Ads. The code should be added near the top of the <head> tag and the string 'XXXXX' should be replaced with the property ID (also called the "AIP ID").
<!-- AdinPlay Ads -->
<script>
var aiptag = aiptag || {};
aiptag.cmd = aiptag.cmd || [];
aiptag.cmd.display = aiptag.cmd.display || [];
aiptag.cmd.player = aiptag.cmd.player || [];
//CMP tool settings
aiptag.cmp = {
show: true,
button: true,
buttonText: "Privacy settings",
buttonPosition: "bottom-left" //bottom-left, bottom-right, top-left, top-right
}
</script>
<script async src="//api.adinplay.com/libs/aiptag/pub/XXXXX/tag.min.js"></script>
The above code does two main things:
Custom implementations may require adding additional code to the last line of the JavaScript snippet. However, you should not change the order or the code that loads the AdinPlay Ads JavaScript library.
The string 'XXXXX_placement' should be replaced with the placement ID (also called the "AIP PLACEMENT ID").
<div id='XXXXX_placement'>
<script type='text/javascript'>
aiptag.cmd.display.push(function() { aipDisplayTag.display('XXXXX_placement'); });
</script>
</div>
aiptag.cmd.display.push(function() { aipDisplayTag.display('XXXXX_placement'); });
aiptag.cmd.display.push(function() { aipDisplayTag.destroy('XXXXX_placement'); });
aiptag.cmd.display.push(function() { aipDisplayTag.destroy(); });
Create a container to display the Video Ad
<div id="videoad"></div>
Initialize the Video player, this should be done only once per page load.
iptag.cmd.player.push(function() {
aiptag.adplayer = new aipPlayer({
AD_WIDTH: 960,
AD_HEIGHT: 540,
AD_DISPLAY: 'default', //default, fullscreen, center, modal-center, fill
LOADING_TEXT: 'loading advertisement',
PREROLL_ELEM: function(){return document.getElementById('videoad')},
AIP_COMPLETE: function (evt) {
/*******************
***** WARNING *****
*******************
Please do not remove the PREROLL_ELEM
from the page, it will be hidden automaticly.
*/
console.log("Video Ad Completed: " + evt);
}
});
});
Show the Video Ad
//check if the adslib is loaded correctly or blocked by adblockers etc.
if (typeof aiptag.adplayer !== 'undefined') {
aiptag.cmd.player.push(function() { aiptag.adplayer.startVideoAd(); });
} else {
//Adlib didnt load this could be due to an adblocker, timeout etc.
//Please add your script here that starts the content, this usually is the same script as added in AIP_COMPLETE.
console.log("Ad Could not be loaded, load your content here");
}
Add the following functions to the aipPlayer initialisation.
AIP_REWARDEDNOTGRANTED: function (state) {
//This event is fired when a rewarded ad is:
//timed out, empty, unsupported or closed by the user.
//don't grand the reward here
alert("Rewarded ad state: " + state); //state can be: timeout, empty, unsupported or closed.
},
AIP_REWARDEDGRANTED: function () {
alert("Reward Granted");
}
like this
aiptag.cmd.player.push(function() {
aiptag.adplayer = new aipPlayer({
AIP_REWARDEDNOTGRANTED: function (state) {
//This event is fired when a rewarded ad is:
//timed out, empty, unsupported or closed by the user.
//don't grand the reward here
alert("Rewarded ad state: " + state); //state can be: timeout, empty, unsupported or closed.
},
AIP_REWARDEDGRANTED: function () {
alert("Reward Granted");
},
AD_WIDTH: 960,
AD_HEIGHT: 540,
AD_DISPLAY: 'default', //default, fullscreen, center, modal-center, fill
LOADING_TEXT: 'loading advertisement',
PREROLL_ELEM: function(){return document.getElementById('videoad')},
AIP_COMPLETE: function () {
/*******************
***** WARNING *****
*******************
Please do not remove the PREROLL_ELEM
from the page, it will be hidden automaticly.
*/
console.log("Video Ad Completed: " + evt);
}
});
});
Show the Rewarded Ad
//check if the adslib is loaded correctly or blocked by adblockers etc.
if (typeof aiptag.adplayer !== 'undefined') {
aiptag.cmd.player.push(function() { aiptag.adplayer.startRewardedAd(); });
} else {
//Adlib didnt load this could be due to an adblocker, timeout etc.
//Please add your script here that starts the content, this usually is the same script as added in AIP_REWARDEDCOMPLETE.
console.log("Rewarded Ad Could not be loaded, load your content here");
}
The following event will be triggered when there is an interstitial ad available Please make sure this Event Listener is set before the JavaScript snippet: //api.adinplay.com/libs/aiptag/pub/XXXXX/tag.min.js is loaded
//Interstitial ad available event
document.addEventListener("aip_interstitialadavailable", function(e) {
console.log("An interstitial ad is available");
});
Add the following setting to the initialisation just after var aiptag = aiptag || {}; Please make sure this setting is set before the JavaScript snippet: //api.adinplay.com/libs/aiptag/pub/XXXXX/tag.min.js is loaded interstitial ads will need to be enabled, please contact our team to enable Interstitial Ads
/ disable interstitial ads
aiptag.disableInterstitialAd = true;
aiptag.cmp = {
show: true,
button: true,
buttonText: "Privacy settings",
buttonPosition: "bottom-left" //bottom-left, bottom-right, top-left, top-right
}
If you choose not to use the Consent tool button its important to implement aipAPItag.showCMPScreen(); as described below. To comply with the GDPR to show the Consent tool settings menu to revoke or change your consent settings.
<a href="javascript:void(0)" onclick="aipAPItag.showCMPScreen()">Privacy settings</a>
You can use the following functions to show or hide the settings button. (this can be useful when in game for example.)
aipAPItag.hideCMPButton();
aipAPItag.showCMPButton();
Examples
//CMP shows the consent screen
document.addEventListener("aip_consentscreen", function(e) {
console.log("CMP shows the consent screen");
});
//CMP removes the consent screen
document.addEventListener("aip_consentscreenoff", function(e) {
console.log("CMP removes the consent screen");
});
Some examples of how to use this to preview on your site (foo.com):
Test CPRA messaging -- http://foo.com/?fc=alwaysshow&fctype=ccpa
Test GDPR messaging -- http://foo.com/?fc=alwaysshow&fctype=gdpr
Note: If you expect to see a message but don't see it, or it's not behaving as expected, try clearing your cookies (or using Incognito mode) to reset any saved state and try again.