How to serve SFW ads with ExoClick
As countries begin to roll out age verification laws, publishers need to find a way to comply with these laws while also minimizing the impact these laws have on their revenue. That’s why ExoClick has introduced a couple of parameters that can be added to ad zones to help publishers not only block NSFW products but also track if these users actually succeed in verifying their age. In this tutorial, we will show you how to use these parameters.
data-ex_av
The data-ex_av parameter
determines whether the user has verified their age or not and it allows 3 values:
"0"
: No Age Verification (Undefined)"1"
: Age Verification - Verified"2"
: Age Verification - Not Verified (SFW)
Code example:
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script>
<ins class="eas6a97888e2" data-zoneid="5209020" data-ex_av="2"></ins>
<script>(AdProvider = window.AdProvider || []).push({"serve": {}});</script>
data-block-ad-types
The data-block-ad-types
parameter allows you to block specific ad type labels on the fly. For the purpose of blocking NSFW ads, we will only use the value "101"
in this parameter.
Code example:
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script>
<ins class="eas6a97888e2" data-zoneid="5209020" data-block-ad-types="101"></ins>
<script>(AdProvider = window.AdProvider || []).push({"serve": {}});</script>
Using the parameters
Considering what we have explained, if you want to serve an ad that is SFW and you want to identify that user as someone who hasn’t verified their age yet, you will integrate the parameters like this:
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script>
<ins class="eas6a97888e2" data-zoneid="5209020" data-ex_av="2" data-block-ad-types="101"></ins>
<script>(AdProvider = window.AdProvider || []).push({"serve": {}});</script>
Note: it’s important you use both parameters.
And if you want to serve NSFW ads to a verified user, you serve them like this:
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script>
<ins class="eas6a97888e2" data-zoneid="5209020" data-ex_av="1"></ins>
<script>(AdProvider = window.AdProvider || []).push({"serve": {}});</script>
The next section includes some examples of how you can add these parameters dynamically to your ad zones. Depending on the age verification you are using, users could be verified either through a cookie, a URL param or something else. Ultimately, it is your responsibility to detect your users’ verified status and implement the parameters accordingly.
Example 1: Change parameters based on cookie value
Let’s assume that you are assigning a first-party cookie called “verified_user” with value “yes” to users who have successfully verified their age. In this scenario, you can dynamically add the ex_av and data-block-ad-types parameters like this:
//banner ad zones
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script>
<div id=”adspot1”>
<ins class="eas6a97888e2" data-zoneid="5409832" data-block-ad-types="101" data-ex_av="2"></ins>
<div id=”adspot2”>
<ins class="eas6a97888e2" data-zoneid="5632512" data-block-ad-types="101" data-ex_av="2"></ins>
<div id=”adspot3”>
<ins class="eas6a97888e2" data-zoneid="57382911" data-block-ad-types="101" data-ex_av="2"></ins>
//fpi ad zones
<script async type="application/javascript" src="https://a.pemsrv.com/ad-provider.js"></script>
<ins class="eas6a97888e35" data-zoneid="5045990" data-block-ad-types="101" data-ex_av="2"></ins>
//dynamic function based on cookie
<script>
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
const verifiedUser = getCookie("verified_user");
if (verifiedUser === "verifiedUser") {
const adInsElements = document.querySelectorAll("ins");
adInsElements.forEach(ins => {
ins.setAttribute("data-ex_av", "1");
ins.setAttribute("data-block-ad-types", "0");
});
}
(AdProvider = window.AdProvider || []).push({"serve": {}});
</script>
This script will let you serve NSFW ads to those users who have the “user_verified” cookie. Note that you will have to refresh the page after the user has verified their age so that the script can properly detect the cookie.
Example 2: change parameters based on URL param
In this example, we assume that the URL gets a parameter called “user_verified=yes” when the user successfully verifies their age.
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script>
<div id="ad-container">
<ins class="eas6a97888e20" data-zoneid="5662140" data-block-ad-types="101" data-ex_av="2"></ins>
</div>
<script>
(AdProvider = window.AdProvider || []).push({ serve: {} });
</script>
<script>
const userVerified = new URLSearchParams(window.location.search).get(
"user_verified"
);
if (userVerified === "yes") {
let container = document.getElementById("ad-container");
container.innerHTML = "";
let newIns = document.createElement("ins");
newIns.className = "eas6a97888e20";
newIns.setAttribute("data-zoneid", "5662140");
newIns.setAttribute("data-block-ad-types", "");
newIns.setAttribute("data-ex_av","1");
container.appendChild(newIns);
(AdProvider = window.AdProvider || []).push({ serve: {} });
}
</script>
Remember: these code examples are mere suggestions. You should discuss with the Age Verification tool how users are verified and adapt your scripts accordingly.