AdLad
AdLad allows you to easily integrate ads for your games without the need for different implementations from every
publisher. Instead, you can configure which plugins you would like to use, and whenever you want to show an ad, AdLad
will forward your request to the plugin that is currently active.
Usage
To quickly get started, you can use jsdelivr.com to import AdLad:
<script type="module">
import {AdLad} from "https://cdn.jsdelivr.net/npm/@adlad/adlad/mod.min.js";
import {crazyGamesPlugin} from "https://cdn.jsdelivr.net/npm/@adlad/plugin-crazygames/mod.min.js";
const adLad = new AdLad({
plugins: [
crazyGamesPlugin(),
]
});
</script>
You can immediately start making calls, but ads won't show until the plugin has initialized.
await adLad.showFullScreenAd();
Both showFullScreenAd()
and showRewardedAd()
return an object that allows you to determine if an ad was shown.
const result = await adLad.showRewardedAd();
console.log(result);
Some portals require you to report loading and gameplay state, which can be done with the methods below. You can call
these as often as you like, if you call gameplayStart()
twice in a row for example, AdLad will make sure it is passed
to the plugin only once.
adLad.gameplayStart();
adLad.gameplayStop();
adLad.loadStart();
adLad.loadStop();
It's important that you mute audio and pause gameplay during ads. This can be done by observing the following values:
adLad.needsPause;
adLad.needsMute;
Usually these both become true
once you make a call for showing ads, but plugins can manually override this value.
That way your game always behaves according to the policies of the platform it's embedded on.
You can also listen for changes to these values:
adLad.onNeedsPauseChange((needsPause) => {
console.log(needsPause);
});
adLad.onNeedsMuteChange((needsMute) => {
console.log(needsMute);
});
You can use adLad.removeOnNeedsPauseChange
and adLad.removeOnNeedsMuteChange
To remove your callbacks.
Once you have experimented enough, you can bundle AdLad using a build tool of choice. AdLad is available as
an npm package and on deno.land/x.
For the full API reference, see
this page.
Plugins
By default the first available plugin from your plugins
option is used. You can get the id of the active plugin using
adLad.activePlugin
.
To override which plugin is active, you can pass the plugin id via the plugin
option like so:
const adLad = new AdLad({
plugins: [notSoCoolPlugin(), myCoolPlugin()],
plugin: "my-cool-plugin",
});
Alternatively, you can use the ?adlad=my-cool-plugin
query string. This is useful when you want to host your own page,
while still allowing gaming portals to use a specific plugin. You can simply provide each gaming portal with a different
url.
List of supported plugins