THIS CONTENT DOWNLOAD SHORTLY

Objectives

The main objective of this blog post is to explain how to implement Ads in Unity. This blog post is very useful to developers who don’t know anything about Ad or Ad Implementation in Unity. Here we go through the idea of how to implement Ad in unity using AppLovin SDK.

 

This SDK basically provides interstitial ads, banner ads and video ads. Advertisers can implement any of them according to their requirement.

Following are the steps through which you can get a brief idea about how to integrate AppLovin SDK in Android as well as in iOS.

 

Step 1 Find or Create your app ID

You can find your app ID from the mentiond link. But if you are new user than you can create your app ID from the given link.

create-your-app-id

You can put Interstitial as well as video ads in your games using AppLovin. It also provides Banner Ads.

 

Step 2 Configuration

To access the AppLovin SDK, Sign-in or Sign-up with your Email id and follow the steps.

  • First of all, download the latest available version of SDK.
  • Now, import this SDK as a custom package.

AppLovinUnity SDK can be integrated using c# code. Here you have to keep one thing in mind that, you have to test it only on devices, as Ads will not show in Unity editor/ xCode simulator.  

custom-pacakage

Add AdManager and AppLovinAdEventListener script to a game object in hierarchy.

 

Step 3 Integrate in iOS

You have to include the following two libraries:

  1. AdSupport
  2. StoreKit

You can get more ideas by referring to the following image. 

storekit-framework

 

Step 4 Integrate in Android

Here, you have to do some changes to your AndroidManifest.xml file by using the following line of code.

  • Paste your AppLovin SDK key on YOUR_SDK_KEY.
  • Replace all YOUR_PACKAGE_NAME with the actual package name (Bundle Identifier) of your application.

Note: There is no need to create your app. It will create your app automatically after you have run it successfully for the first time.

 

Step 5 Integration

>> Set SDK Key

AppLovin.SetSdkKey("");// Paste Your SDK Key

>> Initialize

AppLovin.InitializeSdk();

>> Set Unity Ad Listener to a Specific Object

AppLovin.SetUnityAdListener(gameObject.name);

>> You can Create Ad (Cache Ads in memory) using the following Line of Code.

  • Create Interstitial (Cache in Memory)
AppLovin.PreloadInterstitial();

>> You Can Show Ad (Display on Screen) using the following line of code.

  • Display Interstitial
AppLovin.ShowInterstitial();
  • Show Banner
AppLovin.ShowAd ();

>> You Can Hide Banner Ad Using the Following Line of Code

AppLovin.HideAd();

>> You Can Set Banner Ad Position Using the Following Line of Code.

AppLovin.SetPosition(AppLovin.AD_POSITION_CENTER, AppLovin.AD_POSITION_TOP);
AppLovin.SetAdPosition(100, 100);

>> You Can Set Ad Width Using the Following Line of Code.

AppLovin.SetAdWidth(400);
 

Step 6 Listeners

Listeners (which are also called Delegates/Callbacks) help you to follow Ad workflow. Whenever, the state of Ad changes, AppLovin SDK calls events respectively. It calls specific methods as per the callbacks.

For Eg:

  • If Ad is loaded successfully or not, you can identify it whenever user clicks on Ad etc. The following line of code gives a brief idea about it.

>> Delegates:

void onAppLovinEventReceived(string ev)
    {
Debug.Log(ev);
 
if (ev.Contains("REWARDAPPROVEDINFO"))
        {
// Split the string into its three components.
char[] delimiter = { '|' };
string[] split = ev.Split(delimiter);
 
// Pull out and parse the amount of virtual currency.
double amount = double.Parse(split[1]);
 
// Pull out the name of the virtual currency
string currencyName = split[2];
 
// Do something with this info - for example, grant coins to the user
//myFunctionToUpdateBalance(currencyName, amount);
        }
 
if (string.Equals(ev, "DISPLAYEDINTER") || string.Equals(ev, "VIDEOBEGAN"))
        {
Time.timeScale = 0.0f;
AudioListener.pause = true;
        }
 
if (string.Equals(ev, "HIDDENINTER") || string.Equals(ev, "VIDEOSTOPPED"))
        {
Time.timeScale = 1.0f;
AudioListener.pause = false;
        }
 
if (string.Equals(ev, "LOADEDINTER"))
        {
// The last ad load was successful.
// Probably do AppLovin.ShowInterstitial();
        }
if (string.Equals(ev, "LOADFAILED"))
        {
// The last ad load failed.
        }
    }
 

Step 7 Other Settings

After you finish the first run, you will be able to see your app on AppLovin.

  • Here are some of the settings for your app.
    test-mode
  • Set test mode on/off as per your requirement.
    turning-on-off-ads
  • Turn on/off different types of ads.
    ad-filtering
  • Filter your app ads.
  • Set targets according to need.
    banner-ad-refresh
  • Set banner ad refresh rate as per the requirement.
    rewarded-video
  • Set rewarded video settings as per requirement.

I hope you find this blog is very helpful while Ads Implementation In Unity Using AppLovin. Let me know in comment if you have any question regarding Ads Implementation. I will reply you ASAP

Got an Idea of Game Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Game Development Company in India.

I am 2D Game developer and iOS Developer with an aspiration of learning new technology and creating a bright future in Information Technology.