> 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/pt/campanhas/iframe-events.md).

# Eventos de iframe

Os anunciantes podem acompanhar eventos nos seus anúncios. Esses eventos são geridos programaticamente diretamente no navegador do cliente com a ajuda de JavaScript.

## Eventos

### creativeDisplayed

{% hint style="info" %}
Isto só está disponível para **Intersticial de página inteira para desktop** e **Intersticial de página inteira para dispositivos móveis** (*DFPI/MFPI*) campanhas de formato de anúncio com **URL do iframe** variação.
{% endhint %}

Quando o anúncio é apresentado ao utilizador, é enviada uma mensagem para o iframe chamada `creativeDisplayed`.

Pode acompanhar este evento dentro do seu iframe usando o script abaixo, que adiciona um listener de eventos para captar a mensagem enviada assim que o anúncio é apresentado ao utilizador.

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

        if (window.addEventListener) {
            // Para navegadores Web compatíveis com os padrões
            window.addEventListener("message", readMessage, false);
        } else {
            window.attachEvent("onmessage", readMessage);
        }
</script>
```

## Exemplo - Intersticial de página inteira

```html
<!DOCTYPE html>
<html>
<head>
    <!-- PARTE DO EVENTO -->
    <script>
        function readMessage(event) {
            console.log("evento readMessage");
            console.log("origem: " + event.origin);
            console.log("dados: " + event.data);
            var message = "Recebemos a mensagem: '" + event.data + "' de '" + event.origin + "' (estamos agora no iframe do anunciante)";
            console.log(message);
            document.getElementById("received-message").innerHTML = message;
            // ou seja, o anunciante quer atualizar algum elemento
        }
        if (window.addEventListener) {
            // Para navegadores Web compatíveis com os padrões
            window.addEventListener("message", readMessage, false);
        } else {
            window.attachEvent("onmessage", readMessage);
        }
    </script>
    <!-- FIM DA PARTE DO EVENTO -->
</head>
<body>
    <h1>Meu cabeçalho de iframe de teste</h1>
    <p>Meu parágrafo de iframe de teste</p>
    <p id="received-message">À espera da mensagem</p>
</body>
</html>
```

<figure><img src="/files/5285f1be2713f085939c73e0efc3dbccfdfbd379" 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/pt/campanhas/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.
