Skip to main content

Popunder Redirect Examples

The following page lists a series of uses cases where you can use the Redirect Popunder URL format of the popunder to trigger the ad under certain conditions.

Serve popunders under Adblock

Assuming that you don't want to use the Inline + Remote Script version of the popunder, you can follow these steps:

  1. Create a .js file called ads.js containing the following code:
isAdblockActive = false;
  1. Create another file called domains.js containing the following code:
let storedDomain = null;
fetch("https://ads.exoclick.com/adblock-domains.php")
.then(r => {
if (!r.ok) {
throw new Error("Network response was not ok (" + r.status + ")");
}
return r.json();
})
.then(data => {
if (data.success && data.domain) {
storedDomain = data.domain;
} else {
logError("API returned error: " + (data.message || "Unknown error"));
}
})
.catch(err => {
logError("Fetch failed: " + err.message);
});

3.Place both files on your website’s server. Then, on your site’s HTML, add the following:

<script type="text/javascript">var isAdBlockActive=true;</script>
<script type="text/javascript" src="domains.js"></script>
<script type="text/javascript" src="ads.js" ></script>
<a id="rd" href="#" target="_blank">Redirect Domain</a>
<script>
var link = document.getElementById('rd');
link.addEventListener("click", function (){
if (isAdBlockActive) {
window.location.replace("https://" + storedDomain + "/v1/link.php?cat=&idzone=XXXXX&type=8&block=1");
} else {
window.location.replace("https://s.pemsrv.com/v1/link.php?cat=&idzone=XXXXX&type=8");
}
});
</script>

The Redirect Popunder will trigger when the user clicks on the link with id rd. Then, if Adblock is enabled on the browser, isAdBlockActive will be set to true because ads.js will be blocked, allowing the redirect popunder to use the dynamic adblock domain retrieved from domains.js. The &block=1 parameter allows the popunder to register the traffic as Adblock.

Serve SFW ads

The ex_av and block_ad_types parameters can be added to the Redirect Domain Popunder to register the user as someone who has or hasn’t passed Age Verification and to block NSFW ads.

The following code is based on How to serve SFW ads with ExoClick and loads the Redirect Domain Popunder depending on whether the user has the userVerified cookie, which is set once the user has passed Age Verfication.

<a id="rd" href="#" target="_blank">Redirect Domain</a>
<script>
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
const link = document.getElementById('rd');
const verifiedUser = getCookie("verified_user");
link.addEventListener("click", function (){
if (verifiedUser === "yes") {
window.location.replace("https://s.pemsrv.com/v1/link.php?cat=&idzone=XXXXX&type=8&ex_av=1");
}
else {
window.location.replace("https://s.pemsrv.com/v1/link.php?cat=&idzone=XXXXX&type=8&ex_av=2&blocked_ad_types=101");)
}
});
</script>

Block campaigns with specific labels when the website has a specific parameter on its URL

The following code is based on How To Dynamically Block Ad Types Using data-block-ad-types and reads the value from a specific parameter of the URL where the popunder will be loaded. This can be useful for publishers who identify their sources of traffic by using a specific parameter.

In this example, we are looking for a parameter called utm_source and the label we are going to block is Verified False Positives:

<a id="rd" href="#" target="_blank">Redirect Domain</a>
<script>
const link = document.getElementById('rd');
const pb = new URLSearchParams(window.location.search).get("utm_source");
link.addEventListener("click", function (){
if (pb === YYYYYYYYYYY) { // YYYYY corresponds to whatever value publisher uses to identify the source of traffic where we want to enforce this block
window.location.replace("https://s.pemsrv.com/v1/link.php?cat=&idzone=XXXXX&type=8&blocked_ad_types=98");
}
else {
window.location.replace("https://s.pemsrv.com/v1/link.php?cat=&idzone=XXXXX&type=8");)
}
});
</script>