πAdd Unique Link using in-app WebView
This document outlines how you can use Android WebViews to run our products inside your app.
This document has been written assuming you're integrating a Gamezop Unique Link or individual games. However, the steps to follow are the same even if you're integrating Quizzop / Astrozop or any of our other products in your app.
Integration guide
This guide applies to Android WebView integration only. Follow the steps given below closely to get a perfectly working WebView implementation in your app:
Step 1: Create the WebView via code (instead of XML)
We recommend creating the WebView in code for simplicity. To prevent memory leaks, make sure to call destroy() on the WebView in the Activityβs onDestroy().
You may have a particular Android Activity where you place the Gamezop icon / banner. When a user taps on that icon / banner, you want to open your game URL within a WebView. Within the onCreate method of this Activity, you will have to create the WebView as mentioned below:
private lateinit var myWebView: WebView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
myWebView = WebView(this)
setContentView(myWebView)
}// At the top of your Activity class:
private WebView myWebView;
// In onCreate():
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myWebView = new WebView(this);
setContentView(myWebView);
}Step 2: Make updates to AndroidManifest.xml
AndroidManifest.xmlThe primary objective of making these updates is to enable the following:
Internet access for the WebView
Screen orientation changes within the WebView (since games can be landscape as well)
Hardware acceleration for better game performance
Here are the updates to be made within your app's AndroidManifest.xml file:
Step 3: Setup a WebViewClient to intercept URLs
WebViewClient to intercept URLsCreate a CustomWebViewClient file within the same directory as where you have your MainActivity file. Java and Kotlin versions of this file are given below:
Step 4: Set this CustomWebViewClient as your WebView client
CustomWebViewClient as your WebView clientTo do so, add the following line in the Activity where you created your WebView:
Step 5: Configure WebView settings in the holder Activity
Add the following lines in the Activity where you created your WebView:
To prevent memory leaks, always destroy the WebView when the activity or fragment that hosts it is destroyed.
Add the following line inside your activityβs onDestroy() method:
Step 6: Open your Gamezop Unique Link
Once you are done with the 5 steps mentioned above, you are ready to open your Gamezop game URL within your WebView. Add this line at the end of the Activity where you created your WebView:
Step 7: Integrate the WebView API for Ads
The WebView Ads API shares app signals with Google ad tags used within Gamezop, helping optimise ad delivery and increase monetisation β which in turn boosts your revenue share.
Register the web view
Call registerWebView() on the main thread to establish a connection with the JavaScript handlers in the AdSense code or Google Publisher Tag within each WebView instance. This should be done as early as possible, such as in the onCreate() method of your MainActivity.
Cache and performance
WebView automatically caches Gamezopβs game assets and user cookies to make reloads much faster for returning users. To maintain this performance, avoid clearing the WebView cache or cookies unnecessarily.
β Best practice: Let WebView manage its own cache and cookie storage.
β Avoid:
webView.clearCache(true)CookieManager.getInstance().removeAllCookies(null)WebStorage.getInstance().deleteAllData()
Test ads performance
Use this URL to test if your WebView is properly optimised for ad monetisation:
The test URL has success criteria for a complete integration if the following are observed:
WebView settings
Third-party cookies work
First-party cookies work
JavaScript enabled
DOM storage enabled
Video ad
The video ad plays inline and does not open in the full screen built-in player
The video ad plays automatically without clicking the play button
The video ad is replayable
WebView API for Ads
If you followed Step 7 above, visit this link in your app's WebView to check if it successfully connected to the Google Mobile Ads SDK. The test URL should show green status bars for a successful integration.
Optimal click behaviour
Open this link in your app's WebView. Click each of the different link types to see how they behave in your app. Here are some things to check:
Each link opens the intended URL.
When returning to the app, the test page's counter doesn't reset to zero to validate the page state was preserved.
After testing is complete, substitute the test URLs from Google with your Gamezop Unique Link.
Useful resources
Ad monetisation best practises (Android): https://developers.google.com/ad-manager/mobile-ads-sdk/android/browser/webview
Ad monetisation best practises (iOS): https://developers.google.com/ad-manager/mobile-ads-sdk/ios/browser/webview
Last updated
Was this helpful?