How to Implement AdMob and Tappx on Unity.

How To Implement AdMob and Tappx on Unity

MONETIZATION PUZZLE

This tutorial describes how you can insert one ad from AdMob and one from Tappx and to repeat this sequence (Interstitials Format) on Unity Game.

STEP 1: IMPLEMENT ADMOB

admob_logo_2x

1.1 Download the latest version of the plugin of Admob for Unity, from their Github page. https://github.com/googleads/googleads-mobile-unity/releases

1.2 Import the package in Unity by going to Assets/Import/Custom Package and select the downloaded plugin. A window indicates the files you want to import (uncheck all IOS folders).

games03

1.3 Open the Manifest which is inside the folder  Plugins/Android/GoogleMobileAdsPlugin
Delete few lines of code to be sure to eliminate the activity that causes troubles with Google Play Services and the “InAppPurchase Activity”.

From line 22 which starts with “<!– Google Mobile Ads Activity –>” to line 28 which ends with.
android:theme=”@style/Theme.IAPTheme”/>

Well Done Admob is installed!

  • NB: If your game includes in app purchase, only delete the “Google Mobile Ads Activity”.
  • NB2: the part of coding will be done at the end.

STEP2: IMPLEMENT TAPPX

tappix-pencil - copia

2.1 Create an account on www.tappx.com, add your app by clicking on “Add App” and complete the form.
Download the SDK form their official page

add app2.2 Return to Assets/Import/Custom Package and carefully uncheck the AndroidManifest (Our project has already one.)

games04

NB: Your project has already installed the Google Play Services, so uncheck this folder and IOS’s one too (if you don’t use IOS).

Once imported we go to the TappxManagerUnity.prefab and enter your Android’s ID (and/or IOS’ID) Check if you are using Banners or Interstitials.

games05

 NB: Later we explain you where you can find your Tappx ID.

Finally, go to the Android Manifest which is inside the folder /Plugins/Android/GoogleMobileAdsPlugin and before the </application>, copy what Tappx will use for tracking the app:

<receiver android:name=”com.tappx.unity.InstallReferrerReceiver” android:exported= “true” >
<intent-filter>
<action android:name=”com.android.vending.INSTALL_REFERRER” />
</intent-filter>
<!– This is a example
<meta-data android:name=”forward.GoogleAnalytics” android:value=”com.google.android.apps.analytics.AnalyticsReceiver” />
–>
</receiver>

 

2.3 Compile in order to check if there are no errors.

Go to File/Build ,
– Check our platform to Android, if it wasn’t checked before. Select Android and press on “Switch Platforms”.
– Then they ask you where you want to save the file (APK): Select and press Build.
– Cautious: Before compiling, go to “Player Settings” and “Other Settings”.
Go to “Identification” and then to “Bundle Identifier”.
By default is “com.Company.ProductName” where you change the “Company” and “ProductName” for whatever you like: “com.testcompany.test

STEP3: CODING.PART1

IITAGH-Keep-Coding-300x226

You need a “General” Script which works for the general behaviour of the game.
If you don’t have it, you can create it or put this code where you think it suits with your game.

Before that, you need to understand how ads works:

AdRequest: The ad “asks” to its network for an ad to show
AdLoad: This part handles the request and prepares the ad to be shown
AdShow: Show the ad, this event closes when the user closes the ad

A simple Script could be:

using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using GoogleMobileAds;
using GoogleMobileAds.Api;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;

//variables that will be used forward
private InterstitialAd interstitial;
AndroidJavaObject interstitialControl;
int ad = 1;
//It is convenient to put the request on Start, so when the game starts the ads is loaded.

void Start() {
            RequestInterstitial(); //admob request
            interstitialControl = new AndroidJavaObject(“com.tappx.unity.interstitialTappx”, “TappxID”, “TappxManagerUnity”);  //tappx request
}
void Lose(){ //This part will be for where the player loses
            if (ad % 2 != 0) //Below I’ll explain this part of the code
            {
                        ShowInterstitial(); //admob interstitial
                        ad++;
            }
            else
            {
                        interstitialControl.Call(“showInterstitial”); //tappx interstitial
                        ad++;
            }
}

Putting Requests on the Start function, works for the game which restarts after a player loses.
(In the case of using another method, it should be reallocated to another function).

STEP 4: CODING PART 2

MONETIZATION PUZZLE

 

NB: Some data are deleted by purpose, so do not copy/paste.

Add your Admob and Tappx Id on the corresponding parts of the code. On “AddTestDevice” we use the default value of the Admob’s guide.

Obtain your Tappx ID by clicking on your App

private void RequestInterstitial() //request inter
{
            #if UNITY_EDITOR
                        string adUnitId = “unused”;
            #elif UNITY_ANDROID
                        string adUnitId= “Insert AdmobID”;
            #else
                        string adUnitId = “unexpected_platform”;
            #endif
            // Create an interstitial.
            interstitial = new InterstitialAd(adUnitId);
            // Load an interstitial ad.
            interstitial.LoadAd(createAdRequest());
}
// Returns an ad request with custom ad targeting.
private AdRequest createAdRequest()
{
            return new AdRequest.Builder()
                        .AddTestDevice(AdRequest.TestDeviceSimulator)
                        .AddTestDevice(“AC98C820A50B4AD8A2106EDE96FB87D4”)
                        .AddKeyword(“game”)
                        .SetGender(Gender.Male)
                        .SetBirthday(new DateTime(1990, 1, 1))
                        .TagForChildDirectedTreatment(false)
                        .AddExtra(“color_bg”, “9B30FF”)
                        .Build();
}
private void ShowInterstitial()
{
            if (interstitial.IsLoaded())
            {
                        interstitial.Show();
            }
            else
            {
                        print(“Interstitial is not ready yet.”);
            }
}
// Tappx
public void InterstitialLoaded() //check ad loaded
{
            UnityEngine.Debug.Log(“Interstitial Load”);
}
public void InterstitialFailedToLoad(string error)
{
            UnityEngine.Debug.Log(“Interstitial Error ” + error);
}

STEP5: INSERT ADMOB/TAPPX ADS: RULE OF THE GAME

Rule: When a player loses, we show an Admob’s ad, when he loses again, we show a Tappx’s ad.
You can adjust this to your preferences.

One example of configuration: By checking if a number is odd or even.
To do that, we use the variable “ad” with an initial value of 1, when a player loses, the function asks if “ad” is even (if the rest of dividing “ad” by 2 is 0), in that case, we show an Admob’s ad; and add 1 to “ad”, for the next time, “ad” will be 2, so when a player loses, the function will ask again and as 2 is even it will show a Tappx’s ad and add 1 to “ad” and so on.

Well Done !

You can start to show ads via Admob and earn Tappix promoting ads from others developers!

Invest your Tappix making other members promote your apps!

cross-pro-double-good_0000_Calque-0-copie

Original Tutorial by Lautaro Pinilla
http://diariodeunindiedev.blogspot.com.es/

Want to exchange ads with other developers?