SDK Integration

Connect your game with our Ad Monetization Solution
Available for most popular game platforms

Unity integration, midroll

WeeGoo Unity implementation guide for Midroll and Reward Ads.

In order to display the midroll / reward ads in Unity games you need to use a class which will facilitate the communication between the Unity game and the browser.

For this purpose we’ve developed such class to make it easier for you to achieve this. The ExampleScene.unity and MyGame.cs files from package are provided only as examples, to get you started and have a refference to a woking example. You should remove them from your project when they are no longer needed.

Before everything else, please make sure that the WGPlayer Universal Tag is present in the index.html file of your game, in the HEAD section.

//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="+window.location.hostname+"&wp="+window.location.pathname+"&ws="+window.location.search);</script>

Download the SDK and add it to Unity, in the package you will find example scenes and scripts.

To avoid the error "ReferenceError: window is not defined" please go to "Advanced" section of project properties and select "No" to "Use worker".

Step 1

In the archive you will find a Unity package file. Please import it’s content into your game project. Refer to the image below to get an overview idea:

Step 2

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

Step 3

Update the WGSDK default values with ones fitting your needs, if you are unsure you can safely leave them to defaults values.

In the image above, please see the “Wee Goo Ad Manager ( script )” panel

There are two options there that will configure the behaviour of the Ads Manager plugin: “Ad Interval” and “Show Ad Every N Events”

The Ad Interval is an option that when greater than 0 will enable the Ads Manager to automatically call the midroll ad every n seconds you completed the field. This would be helpful in a not so dynamic game, let’s say a chess game. You can set Ad Interval to let’s say 240 seconds and an ad will be displayed every 4 minutes.

The “Show Ad Every N Event” is an option that gives you the ability to postpone the ad display. Let’s imagine a game with very short levels where the user restarts the level every 30 seconds and you need to display the midroll when the user looses the level

It would create a very poor user experience to show the ad every 30 seconds, so, with this option, you can choose to actually show the ad just once for every 2 ad calls ( if you add 2 to this field ).

Moving on to the next step to see how you can call the ad from a button interaction, or from any script.

Step 4

Create a button and bind the click event to WGSDK Prefab, this will allow you to call the GetAd function within WGSDK by clicking the button.

Step 5 - show midroll using button

Now you can use the WeeGooAdManager to display Midroll ads as a result of button interaction or script call

Select (click) the button in the Hierarchy panel and take a peek in the Inspector panel. You will see the button details. Notice the “On Click” area. Click the lower right Plus (+) sign to add a new action. From the Hierarchy panel you need to drag the “WeeGooAdManager” object and drop it in the On Click - None ( object) button’s area from the Inspector panel.

Once your panel looks like in the image below, we can go on to the next step

Click on the “No function” drop down, hover the WeeGooAdManager option, follow the new submenu and click on GetAd option.

Take a look at the image below to get an idea, we’re going to use a button to exemplify the functionality of “Get Ad Every N Event” parameter usage and behaviour. In a real game scenario situation this could happen every N times a user clicks the next level button.

Please note that the ad will be displayed only in a live environment, within a valid WGPlayer AFG implementation. For confirmation about the component integration you can take a look in the web developer console tab of your web browser.

Step 5 - show midroll by script call, no button

Now, let’s imagine you need to call an ad from an existing script and you need to update it accordingly. Take a look to the next screen shot:

If the “Get Ad Every N Event” has still the default value ( 5 ) then the function “PlayerHasDied” needs to be called 5 times in order to display the ad.

Regardless you use this component to call an ad from a button or script, it will pause and resume the game according to the current state of the ad. Enjoy!

Final note

In the newer versions of Unity the JavaScript initialization sequence from index.html file has changed. Please make sure you assign the unityInstance to gameInstance variable like below:

//WG Universal Tag

...
	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);
		});
	};
...

Unity integration, rewarded ads

Reward ad is a concept where the user is reciving a prize in exchange of watching an ad. There are 3 events that a reward ad can dispatch: onReady, onComplete, onFail.

If you would like to display this type of ads to your users, please attach appropriate callbacks to those events like in following example.

Step 1

From the Project panel drag the RewardControl Prefab to your scene. Please keep in minf that the RewardControl Prefab is just for demo purposes, you can change it with your own game logic.

Step 2

Focus the WeeGooAdManager Prefab in your Hierarchy panel and subscribe to Reward ad events in the Inspector panel:

  • On Ready - signals that a reward is ready to be displayed, you can now show/activate the reward call to action element
  • On Success - the ad s finished and the user should now get the promised reward
  • On Fail - ad was prematurely closed and the user should no tget the reward

Also keep in mind that the Reward ad Call-To-Action element should only be visible/active only as a result of OnReady callback.

After each Succes or Fail you should hide/inactivate the Call-To-Action element and it will be displayed/activated again upon OnReady callback.

Please refer to MyGame.cs and ExampleScene from the provided package for more details

About rewarded ads

When testing and debugging Rewarded Ads, we use our test ad unit that has been specially configured to return test ads for every request.

Before publishing your game, make sure to contact us and provide your developer end point (site or name) in order for us to manually enable production Rewarded Ads.

Back to top

Construct 2

Before everything else, please make sure that the WGPlayer Universal Tag is present in the index.html file of your game, in the HEAD section.

//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="+window.location.hostname+"&wp="+window.location.pathname+"&ws="+window.location.search);</script>

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

Step 1

Right click on Object types and select Insert new object, then double click on WeeGoo SDK from Monetisation category as in the image below:

Step 2

Follow the information in the image below and make appropriate settings in your game logic:

Conditions

When the WGDSDK is loaded

At this point the WGDSDK is loaded and you can safely init the reward or request a midroll ad. To init a reward ad use the "Init rewarded ad" action from WGSDK.

When ad starts

The ad is now visible, you should pause/mute your game to avoid a bad user experience and respect the ad implementation policy

When ad finishes

The ad is now finished, at this point you can resume/unmute your game

When reward ad is available

This signals that a reward ad is available and you can, when you decide, show the call to action for reward ad

When reward ad is granted

At this moment, the user has watched the advertisement in its entirety and must benefit from the reward

When reward ad is canceled

The user did not view enough of the ad and the reward should not be granted

When reward was closed

The user has closed the reward advertisement, it is the right time to resume/unmute the game

Actions

Display ad

Use this action to display a midroll ad

Init rewarded ad

You can use this action to request, and make available for later use, a reward ad. When the reward ad is available the "When reward ad is available" condition will be met

Display rewarded ad

This action should be used when the user click on reward ad call to action element within your game

About rewarded ads

When testing and debugging Rewarded Ads, we use our test ad unit that has been specially configured to return test ads for every request.

Before publishing your game, make sure to contact us and provide your developer end point (site or name) in order for us to manually enable production Rewarded Ads.

Final note

When exporting, please make sure compression is not advanced, unfortunatelly this will break the build.

Demo project

You cand download this demo project and see how actions and condition are implemented

Back to top

Construct 3

Before everything else, please make sure that the WGPlayer Universal Tag is present in the index.html file of your game, in the HEAD section.

//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="+window.location.hostname+"&wp="+window.location.pathname+"&ws="+window.location.search);</script>

Download the SDK and use the Menu > View > Addon Manager to install the WeeGoo SDK

Step 1

Right click on "Object types" and select "Add new object type", then double click on gray area from your games's Events sheet and select double click on WeeGooSDK:

Step 2

Follow the information in the image below and make appropriate settings in your game logic:

Conditions

When the WGDSDK is loaded

At this point the WGDSDK is loaded and you can safely init the reward or request a midroll ad. To init a reward ad use the "Init rewarded ad" action from WGSDK.

When ad starts, pause/mute the game

The ad is now visible, you should pause/mute your game to avoid a bad user experience and respect the ad implementation policy

When ad finishes, resume/unmute the game

The ad is now finished, at this point you can resume/unmute your game

When reward ad is available

This signals that a reward ad is available and you can, when you decide, show the call to action for reward ad

When reward ad was granted

At this moment, the user has watched the advertisement in its entirety and must benefit from the reward

When reward as was canceled

The user did not view enough of the ad and the reward should not be granted

When reward closed

The user has closed the reward advertisement, it is the right time to resume/unmute the game

Actions

Display ad

Use this action to display a midroll ad

Init rewarded ad

You can use this action to request, and make available for later use, a reward ad. When the reward ad is available the "When reward ad is available" condition will be met

Display rewarded ad

This action should be used when the user click on reward ad call to action element within your game

About rewarded ads

When testing and debugging Rewarded Ads, we use our test ad unit that has been specially configured to return test ads for every request.

Before publishing your game, make sure to contact us and provide your developer end point (site or name) in order for us to manually enable production Rewarded Ads.

Final note

Pease make sure that "Use worker" option is set to "No", otherwise ads won't work.

Also, when exporting, please make sure compression is not advanced, unfortunatelly this will break the build.

Demo project

You cand download this demo project and see how actions and condition are implemented

Back to top

Javascript/html5 midroll ads integration

You can still use the midroll ads with WeeGoo library even if there is no WGSDK for your platform.

First of all you need to add the following script in your HTML page:

//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=play.wgplayground.com&wp=/game/testing-environment/&ws=");</script>
                    
                

Then, you simply need to subscribe to the same callbacks using the following JavaScript function call:

//Subscribe to reward callbacks, please be sure to have the WG Universal Tag in your HTML Head section prior to this call

<script type="text/javascript">
    window[window.preroll.config.loaderObjectName].refetchAd(RESUME_GAME_CALLBACK);
</script>

                        

* Please make sure your game is paused/muted before calling the window[window.preroll.config.loaderObjectName].refetchAd function. This is mandatory condition in order to be fully compliant with ads policy.

** Please pay attention to RESUME_GAME_CALLBACK as this is not a string but a function from your game's environment. This will be called as soon as the ad is finished.

Javascript/html5 rewarded ads integration

You can still use the rewarded ads with WeeGoo library even if there is no WGSDK for your platform.

First of all you need to add the following script in your HTML page:

//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=play.wgplayground.com&wp=/game/testing-environment/&ws=");</script>
                    
                

Step 1

Then, subscribe to the same callbacks using the following JavaScript function call:

//Subscribe to reward callbacks, please be sure to have the WG Universal Tag in your HTML Head section prior to this call

<script type="text/javascript">
    window[window.preroll.config.loaderObjectName].registerRewardCallbacks({
        onReady:OnReadyMethod,//called when a rewarded ad is ready to be displayed
        onSuccess:OnSuccessMethod,//the ad is finished, user should be rewarded with the prize
        onFail:OnFailMethod //the ad dispaly was canceled, user should not be rewarded with the prize
    });
</script>

                        

Step 2

When the onReady callback is called you know a reward ad is ready to be displayed. You can show it immediately or at a later time using the following function call:

//Display the rewarded ad at any time after onReady callback is called

<script type="text/javascript">
    window[window.preroll.config.loaderObjectName].showRewardAd();
</script>
			
		                        

About rewarded ads

When testing and debugging Rewarded Ads, we use our test ad unit that has been specially configured to return test ads for every request.

Before publishing your game, make sure to contact us and provide your developer end point (site or name) in order for us to manually enable production Rewarded Ads.

Back to top