> For the complete documentation index, see [llms.txt](https://arcplay-ai.gitbook.io/knowledge-portal/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://arcplay-ai.gitbook.io/knowledge-portal/for-h5-games/integration-steps/web-to-game-events-listner.md).

# Web to Game Events Listner

To listen to events from ArcPlay's web experience, you can use the `window.addEventListener`&#x20;

Here is an example implementation for it:

```javascript
window.addEventListener("message", (event) => {
  if (event.data) {
    switch (event.data.funcName) {
      case "game_pause":
        // Pause code here.
        break;
      case "game_unlock_item":
        const { itemId } = event.data.rewardParams; 
        // Unlock item code here.
        break;
    }
  }
});
```

The data will be in the format `{ funcName: “string”, …other data }` where `funcName` is the name of the event. It can be one of the following:

<table><thead><tr><th width="268">Event Name</th><th>Listening Logic</th></tr></thead><tbody><tr><td><code>game_replay</code></td><td>When the user clicks on “Replay” in ArcPlay's web experience. The game needs to restart so it can be played again</td></tr><tr><td><code>game_unlock_item</code></td><td><p>When the game gets this event, the game must unlock the reward item.</p><p> <br>This will contain the reward parameters with key name <code>rewardParams</code> as an additional parameter. The value of <code>rewardParams</code> will be the same as the value game had sent while calling the game to web event <code>game_reward_click</code></p></td></tr><tr><td><code>game_pause</code></td><td>When the user either leaves ArcPlay or hits the back button on the phone. The game will need to be paused.</td></tr><tr><td><code>game_resume</code></td><td>When the game needs to be resumed from the pause state</td></tr><tr><td><code>game_mute_allsound</code></td><td>When the user leaves ArcPlay or an ad is shown. The game will continue to run in the background, thus needs to be muted</td></tr><tr><td><code>game_restore_allsound</code></td><td>When the game is in the foreground again, the audio must be restored to the state it was in before <code>game_mute_allsound</code> was fired.</td></tr></tbody></table>


---

# 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:

```
GET https://arcplay-ai.gitbook.io/knowledge-portal/for-h5-games/integration-steps/web-to-game-events-listner.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
