Skip to main content
Client-side callbacks let your app or website react to what happens inside a Gamezop game, such as a score change or a match result. This guide shows you how to receive those events on each platform. The setup is the same for Individual Games and Battles. Once it’s done, use the callback reference for your offering to see each event and what it contains.

Gamezop PostMessage examples

Complete, runnable examples for Web, Android, iOS, React Native, and Flutter, with a built-in event inspector.

Before you start

Client-side callbacks must be enabled for your Property ID before you load the game. Contact your Gamezop Account Manager to enable them. You only need to do this once, and it covers both Individual Games and Battles.
You also need the game URL that your app or website will load. Generate it by following the Individual Games integration or the Battles integration.

Set up your callback handler

The callback handler is the small piece of code in your app or website that receives events from the game. Register it before you load the game URL, so that no events are missed. In the snippets below, capture stands for your own function that handles each event: it parses the payload and passes it on to your UI or analytics code. See Parse and route callbacks for how to parse payloads safely. Each platform tab links to a complete example with the full app, parsing, and lifecycle code.
Pick the tab for whatever loads the game directly:
  • Your app’s WebView loads the game URL: use the tab for your platform (Android, iOS, React Native, or Flutter).
  • Your app opens your own website, and that website loads the game in an iframe: use the Web tab, even inside a mobile app.
The game runs in an iframe on your page and sends each event with window.parent.postMessage(payload, targetOrigin). Your page receives it in event.data, as either an object or a JSON string.Ask your Gamezop Account Manager to whitelist the domain that embeds the game, including any staging domains. This is a separate setting from enabling client-side callbacks, so make sure both are done. Host your page on HTTPS. A page on http://localhost is fine for checking the example’s layout, but may not receive live events.Add the iframe to your page, then register the listener before you set the iframe’s URL:
Keep both checks in onGameMessage. The source check makes sure the message came from your game iframe, and the origin check makes sure it came from the Gamezop game’s domain. Gamezop only sends events to your page’s domain, which is why that domain must be whitelisted. If the game URL redirects to a different domain, ask your Gamezop Account Manager for the final game URL and use its domain as expectedOrigin.Open the complete Web example and setup instructions.

Parse and route callbacks

Depending on the platform, each event arrives as either a JSON string or an object. In your capture function:
  • If the payload is a JSON string, parse it once. If it’s already an object, use it as is.
  • Catch errors from malformed JSON, and check that the result is an object before you read any fields.
  • Ignore fields and event names you don’t recognise, so that your handler keeps working when Gamezop adds new events.
Then use the right field to tell events apart: What you do with each event is up to you, for example updating your UI or recording analytics. When you need a trusted final result, such as before giving out rewards, use server-side webhooks for Individual Games, or the match outcome APIs for Battles, instead of client-side callbacks.

Verify your integration

  1. Run the GitHub example for your platform, and open a game using a Property ID that has client-side callbacks enabled.
  2. Play the game until it ends, making sure your score changes along the way. Open the example’s Logs view to see each event and its raw JSON.
  3. For Battles, open the game on more than one device or browser, using the same roomId and a different user.puid for each. Play through a match, and check that the events you receive match Client-side callbacks for Battles.

Troubleshooting

  • The game loads but no events arrive: Ask your Gamezop Account Manager to confirm that client-side callbacks, and the events you need, are enabled for your Property ID. Then check that your handler is registered before the game loads, and that its name matches exactly, including letter case: AndroidBridge on Android, observer on iOS, or FlutterWebView on Flutter.
  • Battles events are missing: Check your final game URL and its roomDetails, and make sure the same platform callback handler is registered. Battles uses the same callback setting as Individual Games.
  • The game won’t load in your web page: Ask your Gamezop Account Manager to whitelist your hosting domain. If the browser console shows errors about CSP or X-Frame-Options, the game is blocked from being embedded on that domain, and changing the iframe’s attributes won’t fix it.
  • The iframe loads but no events arrive on Web: Make sure your page uses HTTPS, the iframe keeps referrerpolicy="strict-origin-when-cross-origin" so the game can see your page’s domain, and expectedOrigin matches the game’s final domain after any redirects. Keep the source and origin checks in place.
  • Parsing fails: Look at the raw message in the example’s Logs view, and check whether your platform sends a string or an object before you parse it.

Next steps

Individual Games callbacks

Read the state field for gameplay events such as loaded, start, playing, over, and levelup.

Battles callbacks

Read the event field for matchmaking, match progress, results, and navigation events.