> For the complete documentation index, see [llms.txt](https://docs.exoclick.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.exoclick.com/tutorials/tutorials/publishers-tutorials/popunder-redirect-examples.md).

# Popunder Redirect Examples

The following page lists a series of use 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:

{% stepper %}
{% step %}
Create a `.js` file called `ads.js` containing the following code:

```js
isAdblockActive = false;
```

{% endstep %}

{% step %}
Create another file called `domains.js` containing the following code:

```js
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);
  });
```

{% endstep %}

{% step %}
Place both files on your website’s server. Then, on your site’s HTML, add the following:

```html
<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.
{% endstep %}
{% endstepper %}

## 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**](/tutorials/tutorials/publishers-tutorials/serve-sfw-ads.md) 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.

```html
<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**](/tutorials/tutorials/publishers-tutorials/dynamically-block-ads-using-data-block-ad-types.md) 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**:

```html
<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>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.exoclick.com/tutorials/tutorials/publishers-tutorials/popunder-redirect-examples.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
