> 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/advertisers/campaigns/iframe-events.md).

# Iframe Events

Advertisers are able to track events in their Ads. These events are programmatically managed directly in the client browser with the help of JavaScript.

## Events

### creativeDisplayed

{% hint style="info" %}
This is only available for **Desktop Fullpage Interstitial** and **Mobile Fullpage Interstitial** (*DFPI/MFPI*) Ad Format campaigns with **iframe URL** variation.
{% endhint %}

When the ad is displayed to the user, a message is sent into the iframe called `creativeDisplayed`.

You can track this event inside your iframe by using the script below, which adds an event listener to catch the sent message once the ad is displayed to the user.

```html
<script>
        function readMessage(event) {
            console.log("readMessage event");
            console.log("origin: " + event.origin);
            console.log("data: " + event.data);
        }

        if (window.addEventListener) {
            // For standards-compliant web browsers
            window.addEventListener("message", readMessage, false);
        } else {
            window.attachEvent("onmessage", readMessage);
        }
</script>
```

## Example - Fullpage Interstitial

```html
<!DOCTYPE html>
<html>
<head>
    <!-- EVENT PART -->
    <script>
        function readMessage(event) {
            console.log("readMessage event");
            console.log("origin: " + event.origin);
            console.log("data: " + event.data);
            var message = "We got message: '" + event.data + "' from '" + event.origin + "' (we are on advertiser iframe now)";
            console.log(message);
            document.getElementById("received-message").innerHTML = message;
            // ie advertiser wants to update some element
        }
        if (window.addEventListener) {
            // For standards-compliant web browsers
            window.addEventListener("message", readMessage, false);
        } else {
            window.attachEvent("onmessage", readMessage);
        }
    </script>
    <!-- END OF EVENT PART -->
</head>
<body>
    <h1>My test iframe heading</h1>
    <p>My test iframe paragraph</p>
    <p id="received-message">Waiting for the message</p>
</body>
</html>
```

<figure><img src="/files/H77btDAF7jMa4p0v95He" alt=""><figcaption></figcaption></figure>


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.exoclick.com/advertisers/campaigns/iframe-events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
