Business FAQs

How do I integrate an ad SDK into a WebGL build?

0
(0)

A WebGL build cannot call an ad SDK’s JavaScript directly. Unity needs a .jslib plugin exposing extern C functions to JS; Godot 4 uses the JavaScriptBridge singleton. Both call the SDK’s show/reward methods and must handle an ’empty’ result by continuing the game.

At a glance

Fact Value Source
Unity WebGL calls JS via .jslib plugin docs.unity3d.com
Godot 4 web JS bridge JavaScriptBridge singleton docs.godotengine.org
Engines exporting to web Unity, Godot, Construct, GameMaker etc. developer.mozilla.org

A WebGL build runs inside the browser’s JS engine, but the game logic compiled from C#, GDScript or C++ can’t call browser JavaScript on its own – you need a bridge layer. In Unity that’s a .jslib plugin: you write a JS file with functions, mark the C# side with [DllImport("__Internal")] extern, and call it like any other C# method (see Unity’s browser scripting docs). In Godot 4 the equivalent is the JavaScriptBridge singleton, which lets GDScript call JS functions and get callbacks back.

For monetizing the finished build, Playgama Ad connects one SDK to 11 demand partners, including Google Ad Manager. Access to Playgama Ad is by application at playgama.com/adv.

Rather than writing this bridge for every ad network yourself, some plugins wrap the common ad SDK calls (show interstitial, show rewarded, banner on/off) behind one engine-side API so you only integrate once per engine.

What to code on each side

  • JS side: load the ad SDK script in your HTML shell, expose functions that call the SDK’s show/reward methods, and post results back to the engine via the bridge.
  • Engine side: call these exposed functions at natural pauses (level end, before a hint), not at game start and not right after another full-screen ad.
  • Handle an empty result by resuming the game immediately – there is no error event to catch, only an empty/no-fill outcome.

Test in an actual browser build, not the editor, since JS interop only runs in the exported WebGL/HTML5 build. Check console logs for the bridge calls firing and confirm the game continues cleanly when no ad is returned.

Sources

Does Unity’s WebGL build support ad SDKs natively?

No – Unity WebGL runs compiled C# in the browser but can’t call JavaScript directly. You need a .jslib plugin with extern C functions to bridge to the ad SDK.

What happens when an ad SDK returns no ad?

Treat it as an empty result and resume the game immediately; there is no separate error event to handle in this flow.

Which engines need a JS bridge for ads on the web?

Unity (via .jslib) and Godot (via JavaScriptBridge) both need one; frameworks like Phaser or PixiJS run in JS already so they call the SDK directly.

Last updated: 24 September 2026


How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Your email address will not be published. Required fields are marked *

Games categories