SDK Integration

Connect your game.
Start earning in minutes.

Drop-in SDKs for Unity, Construct 2, Construct 3, and plain JavaScript. Midroll and rewarded ads - one integration, every popular game platform.

4
Platforms supported
2
Ad formats included
5min
Average integration time
Unity
Midroll & rewarded ads with the WGSDK Prefab. Drag, drop, configure - no glue code required.
Construct 2
Plugin install in seconds. Visual event-sheet integration for midroll and rewarded ads.
Construct 3
Add-on installs through the Addon Manager. Same API as C2, modern toolchain.
JavaScript / HTML5
No SDK for your platform? Use the universal tag and JS callbacks directly. Works anywhere.
01 — Unity

Unity integration · midroll ads

The WGSDK communicates between your Unity game and the browser. The package ships with ExampleScene.unity and MyGame.cs as references — drop them once you have your own integration working.

Prerequisite

Install the WGPlayer Universal Tag

Before anything else, make sure the WGPlayer Universal Tag is in your game's index.html inside the <head> section.

index.html — <head>
<!-- WG Universal Tag -->
<script type="text/javascript" async>
  !function(e,t){
    a=e.createElement("script"),
    m=e.getElementsByTagName("script")[0],
    a.async=1, a.src=t,
    m.parentNode.insertBefore(a,m)
  }(document,
    "https://universal.wgplayer.com/tag/?lh=" + location.hostname
    + "&wp=" + location.pathname
    + "&ws=" + location.search);
</script>

Download the SDK and add it to Unity. The package contains example scenes and scripts.

Heads up

To avoid ReferenceError: window is not defined, go to the Advanced section of project properties and set Use worker to No.

Step 1

Import the Unity package

The archive contains a Unity package file. Import its contents into your game project.

Step 1: import Unity package
Step 2

Drag the WGSDK Prefab into your scene

From the Project panel, drag the WGSDK Prefab to your Hierarchy panel.

Step 2: drag WGSDK Prefab
Step 3

Configure WGSDK defaults

Update the WGSDK default values to fit your needs. If you're unsure, the defaults are safe.

Step 3: configure WGSDK

In the image above, look at the Wee Goo Ad Manager (script) panel. Two options control behavior: Ad Interval and Show Ad Every N Events.

Ad Interval — when greater than 0, the Ads Manager automatically calls a midroll every N seconds. Useful for slower-paced games (e.g. chess) where setting this to 240 shows an ad every 4 minutes.

Show Ad Every N Events — postpones the ad display. Imagine a game with very short levels where the user restarts every 30 seconds: showing an ad every 30 seconds is awful UX, so this lets you show it once every N restarts (set to 2 to show every other call).

Step 4

Bind a button to the WGSDK Prefab

Create a button and bind its click event to the WGSDK Prefab. This lets you call the GetAd function from a button click.

Step 4: bind button to WGSDK
Step 5a

Show midroll using a button

Now you can use the WeeGooAdManager to display midroll ads from a button click.

Select the button in the Hierarchy panel and look at the Inspector panel — find the On Click area. Click the lower-right plus (+) sign to add a new action. Drag the WeeGooAdManager object from the Hierarchy panel into the On Click — None (object) field in the Inspector panel.

Step 5a: midroll via button

Click the No function dropdown, hover WeeGooAdManager, and click GetAd. In a real game, this could fire every Nth time a user clicks the next-level button.

Note

The ad will only display in a live environment with a valid WGPlayer AFG implementation. To confirm the component is integrated, check the developer console in your browser.

Step 5b

Show midroll from a script

If you need to call the ad from an existing script, update it as shown below.

Step 5b: midroll via script

If Get Ad Every N Event is set to its default (5), the function PlayerHasDied needs to be called 5 times before an ad displays.

Whether you trigger the ad from a button or a script, the component automatically pauses and resumes the game based on the ad state.

Final note

Newer Unity versions

In newer versions of Unity the JavaScript initialization sequence in index.html has changed. Make sure you assign unityInstance to gameInstance:

index.html — gameInstance assignment
// ...
  var gameInstance; // Define the gameInstance variable here
  script.onload = () => {
    createUnityInstance(canvas, config, (progress) => {
      spinner.style.display = "none";
      progressBarEmpty.style.display = "";
      progressBarFull.style.width = `${100 * progress}%`;
    }).then((unityInstance) => {
      gameInstance = unityInstance; // make sure to have this assignment
      loadingCover.style.display = "none";
      if (canFullscreen) {
        if (!hideFullScreenButton) {
          fullscreenButton.style.display = "";
        }
        fullscreenButton.onclick = () => {
          unityInstance.SetFullscreen(1);
        };
      }
    }).catch((message) => {
      alert(message);
    });
  };
// ...
01 — Unity

Unity integration · rewarded ads

Rewarded ads give the user a prize in exchange for watching. Three events fire: onReady, onComplete, onFail. Wire callbacks to each.

Step 1

Drag the RewardControl Prefab

From the Project panel, drag the RewardControl Prefab into your scene. The prefab is a demo — replace it with your own game logic when you're ready.

Step 1: rewarded prefab
Step 2

Subscribe to reward events

Focus the WeeGooAdManager Prefab and subscribe to reward events in the Inspector panel:

  • On Ready — a reward is ready. Show or activate the call-to-action element.
  • On Success — the ad finished; the user should receive the reward.
  • On Fail — the ad was closed early; the user should not get the reward.

The reward call-to-action element should only be visible after OnReady fires. Hide it after each Success or Fail — it'll re-appear when OnReady fires again.

Step 2: rewarded events

See MyGame.cs and ExampleScene in the package for full details.

About rewarded ads

Test mode vs production

While testing and debugging, we use a special test ad unit that returns test ads for every request.

Before publishing your game, contact us with your developer endpoint (site or name) so we can manually enable production rewarded ads.

Back to platforms
02 — Construct 2

Construct 2 integration

A drop-in plugin for the Construct 2 editor. Once installed, ads become event-sheet conditions and actions just like any other plugin.

Prerequisite

Install the WGPlayer Universal Tag

Make sure the WGPlayer Universal Tag is in your game's index.html inside the <head> section.

index.html — <head>
<!-- WG Universal Tag -->
<script type="text/javascript" async>
  !function(e,t){
    a=e.createElement("script"),
    m=e.getElementsByTagName("script")[0],
    a.async=1, a.src=t,
    m.parentNode.insertBefore(a,m)
  }(document,
    "https://universal.wgplayer.com/tag/?lh=" + location.hostname
    + "&wp=" + location.pathname
    + "&ws=" + location.search);
</script>

Download the SDK and extract the folder from the archive to C:\Program Files\Construct 2\exporters\html5\plugins.

Step 1

Add the WeeGoo SDK object

Right-click on Object types and select Insert new object, then double-click on WeeGoo SDK from the Monetisation category.

Step 1: insert object
Step 2

Configure your event sheet

Follow the information in the image below and apply appropriate settings to your game logic.

Step 2: event sheet config
API reference

Conditions

Construct 2 conditions

When the WGSDK is loaded

The WGSDK is loaded — you can safely init a reward or request a midroll. Use the Init rewarded ad action.

When ad starts

The ad is now visible. Pause/mute your game to avoid bad UX and stay compliant with ad policy.

When ad finishes

The ad finished — resume/unmute your game.

When reward ad is available

A reward ad is queued. Show the call-to-action whenever you decide.

When reward ad is granted

The user watched the entire ad and should receive the reward.

When reward ad is canceled

The user didn't watch enough — the reward should not be granted.

When reward was closed

The user closed the reward advertisement — resume/unmute the game.

API reference

Actions

Construct 2 actions

Display ad

Show a midroll ad.

Init rewarded ad

Request a reward ad and queue it for later. When ready, the When reward ad is available condition fires.

Display rewarded ad

Use this when the user clicks the reward ad call-to-action in your game.

About rewarded ads

Test mode vs production

While testing, we use a special test ad unit that returns test ads for every request.

Before publishing your game, contact us with your developer endpoint (site or name) so we can enable production rewarded ads.

Final note

Export settings

When exporting, make sure compression is not set to advanced — that breaks the build.

You can download a demo project to see how actions and conditions are wired up.

Back to platforms
03 — Construct 3

Construct 3 integration

A modern add-on for Construct 3. Install via the Addon Manager, then drop the WeeGooSDK object into your scene and wire up events.

Prerequisite

Install the WGPlayer Universal Tag

Make sure the WGPlayer Universal Tag is in your game's index.html inside the <head> section.

index.html — <head>
<!-- WG Universal Tag -->
<script type="text/javascript" async>
  !function(e,t){
    a=e.createElement("script"),
    m=e.getElementsByTagName("script")[0],
    a.async=1, a.src=t,
    m.parentNode.insertBefore(a,m)
  }(document,
    "https://universal.wgplayer.com/tag/?lh=" + location.hostname
    + "&wp=" + location.pathname
    + "&ws=" + location.search);
</script>

Download the SDK (SDKv7) or download the legacy SDK, then install it via Menu › View › Addon Manager.

Step 1

Add the WeeGooSDK object

Right-click on Object types, select Add new object type, then double-click on the gray area in your game's Events sheet and double-click WeeGooSDK.

Step 1: add object
Step 2

Configure your events

Follow the image below and apply appropriate settings to your game logic.

Step 2: events config
API reference

Conditions

Construct 3 conditions

When the WGSDK is loaded

The WGSDK is loaded — you can safely init a reward or request a midroll.

When ad starts, pause/mute the game

The ad is now visible. Pause/mute your game to comply with ad policy.

When ad finishes, resume/unmute the game

The ad finished — resume/unmute your game.

When reward ad is available

A reward ad is queued. Show the call-to-action when you're ready.

When reward ad was granted

The user watched the entire ad and should receive the reward.

When reward ad was canceled

The user didn't watch enough — the reward should not be granted.

When reward closed

The user closed the reward advertisement — resume/unmute the game.

API reference

Actions

Construct 3 actions

Display ad

Show a midroll ad.

Init rewarded ad

Request a reward ad and queue it for later. The When reward ad is available condition fires when ready.

Display rewarded ad

Use this when the user clicks the reward ad call-to-action.

About rewarded ads

Test mode vs production

While testing, we use a special test ad unit that returns test ads for every request.

Before publishing, contact us with your developer endpoint to enable production rewarded ads.

Final note

Export settings

Make sure Use worker is set to No, otherwise ads won't work. When exporting, also ensure compression is not set to advanced — that breaks the build.

You can download a demo project to see how actions and conditions are wired up.

Back to platforms
04 — JavaScript / HTML5

JavaScript / HTML5 · midroll

No SDK for your platform? You can still call midroll ads with the WeeGoo library directly using JavaScript.

Step 1

Add the universal tag

Add the following script to your HTML page:

index.html — universal tag
<script>!function(l){
  var b="https://universal.wgplayer.com/tag/?",
      p="&wp="+l.pathname+"&ws="+l.search;
  function load(h,fb){
    var s=document.createElement("script");
    s.async=1;
    s.fetchPriority="high";
    s.src=b+"lh="+h+p;
    s.onload=function(){
      if(fb&&!window.wgDomainOnboarded)
        load("wgplayer.com")
    };
    s.onerror=function(){
      if(fb) load("wgplayer.com")
    };
    document.head.appendChild(s)
  }
  load(l.hostname,1)
}(location)</script>
Step 2

Call refetchAd

Subscribe to the same callbacks using the following JavaScript call:

midroll.js
// Subscribe to midroll callbacks. The WG Universal Tag
// must be in your <head> section before this call.
<script type="text/javascript">
  window[window.preroll.config.loaderObjectName]
    .refetchAd(RESUME_GAME_CALLBACK);
</script>
Important

Make sure your game is paused/muted before calling refetchAd. This is mandatory to comply with ad policy.

RESUME_GAME_CALLBACK is a function from your game's environment, not a string. It will be called as soon as the ad finishes.

04 — JavaScript / HTML5

JavaScript / HTML5 · rewarded

Rewarded ads via the universal tag — no SDK required. Same three callbacks as the native SDKs.

Step 1

Add the universal tag

Same tag as the midroll integration — add it once to your <head> and you're set:

index.html — universal tag
<script>!function(l){
  var b="https://universal.wgplayer.com/tag/?",
      p="&wp="+l.pathname+"&ws="+l.search;
  function load(h,fb){
    var s=document.createElement("script");
    s.async=1;
    s.fetchPriority="high";
    s.src=b+"lh="+h+p;
    s.onload=function(){
      if(fb&&!window.wgDomainOnboarded)
        load("wgplayer.com")
    };
    s.onerror=function(){
      if(fb) load("wgplayer.com")
    };
    document.head.appendChild(s)
  }
  load(l.hostname,1)
}(location)</script>
Step 2

Register reward callbacks

Subscribe to the three lifecycle callbacks:

rewarded.js
// Subscribe to reward callbacks. The WG Universal Tag
// must be in your <head> section before this call.
<script type="text/javascript">
  window[window.preroll.config.loaderObjectName]
    .registerRewardCallbacks({
      onReady: OnReadyMethod,   // reward ad ready to display
      onSuccess: OnSuccessMethod, // ad finished, grant reward
      onFail: OnFailMethod        // ad canceled, no reward
    });
</script>
Step 3

Show the ad on demand

When onReady fires you know a reward ad is queued. Show it immediately or save it for later:

show-reward.js
// Display the rewarded ad any time after onReady has fired
<script type="text/javascript">
  window[window.preroll.config.loaderObjectName]
    .showRewardAd();
</script>
About rewarded ads

Test mode vs production

While testing and debugging, we use a special test ad unit that returns test ads for every request.

Before publishing your game, contact us with your developer endpoint (site or name) so we can enable production rewarded ads.

Back to platforms

Need a hand?
We're here.

Stuck on integration, ready to enable production rewarded ads, or just want a second pair of eyes on your setup? Drop us a line and a real person will get back to you.

Talk to a human