Wiki

Clone wiki

AATKit Unity Plugin / Home

This documentation is deprecated

Please see here for up-to-date documentation.

Overview

The aatkit plugin offers easy integration of mobile ad networks. AddApptr gives you an access to all the networks with one single SDK.

Note: Plugin requires Unity 2019.4.0f1 and later. If you are using Unity 2019.4, please follow this instruction when setting up the project. If you use older versions, please contact support@addapptr.com.

Sign Up

To use the AddApptr SDK, please sign up for an account.

Changelog

DOWNLOAD THE LATEST VERSION

Showcase app

AATKitSettings asset

AATKitPlaceholderManager


Integration instructions

  1. Download and unpack AATKit_Unity.zip.
  2. Open your project in Unity editor.
  3. Remove old AATKit plugin version if previously used (see Updating plugin section).
  4. Import the AATKitUnity.unitypackage file to your project.
  5. Make sure your project uses custom mainTemplate.gradle file. To achieve this enable 'Custom Main Gradle Template' in Player Settings -> Settings for Android -> Publishing Settings.
  6. Make sure your project uses custom gradleTemplate.properties file. To achieve this enable 'Custom Gradle Properties Template' in Player Settings -> Settings for Android -> Publishing Settings.
  7. In the scene where you want to display ads, add the AATKit prefab object from the Assets/AATKit/Prefabs directory.
  8. If you don't want to include all networks to your application, please see how to disable some by AATKitSettings asset.

App Tracking Transparency & iOS 14.5

Starting with iOS 14.5 publishers have to use the App Tracking Transparency framework when accessing the IDFA. This is why you should present the app-tracking authorization request to the end user. Currently Unity doesn't officially support this functionality, however, there is a preview package allowing to use ATT framework. Please see this article to find out how to use it within your project. Also please see our recommendations here.

GDPR - General Data Protection Regulation

Using the CMP through AddApptr provided wrapper

With the introduction of IAB TCF2.0, AddApptr will no longer act as a CMP. Instead, we provide wrappers allowing for easily integrating third-party CMPs. Please note that the CMPs need a server-side configuration, please contact support@addapptr.com if you need support.

There are following methods for Managed Consent:

There are following events related to Managed Consent:

CMP Implementations

For now, we provide two CMP implementations:

CMP Google

Android requires appId to be added to Manifest, like

#!c#
<meta-data
          android:name="com.google.android.gms.ads.APPLICATION_ID"
          android:value="YOUR-APP-ID"/>

For iOS you can set appId by AATKitSettings asset. This way AATKit will automatically add the GADApplicationIdentifier value to the Info.plist file.

Code example:

#!c#
AATKitConfiguration aatkitConfiguration = new AATKitConfiguration
    {
        Consent = new AATKitConsent()
        {
            Type = AATKitConsent.ConsentTypes.ManagedCMPGoogle
        }
    };

CMP Ogury

Requires the Ogury library dependency (make sure this network is enabled by AATKitSettings asset). Also you need to pass Asset Key as configuration parameter when initializing AATKit.

Code example:

#!c#
AATKitConfiguration aatkitConfiguration = new AATKitConfiguration
{
    Consent = new AATKitConsent()
    {
        Type = AATKitConsent.ConsentTypes.ManagedCMPOgury,
        AssetKeyCMPOgury = "your-asset-key"
    }
};

Not using the AddApptr CMP wrapper

If for some reason you do not want to use AddApptr CMP wrappers, AATKit also provides another methods for GDPR compliance. The ConsentRequired configuration parameter allows you to inform AATKit if the user is subject to the GDPR laws:

#!c#
AATKitConfiguration aatkitConfiguration = new AATKitConfiguration
{
    ConsentRequired = true
};

For publishers not using the Managed Consent, we have introduced another type of Consent for GDPR-compliance, allowing to pass network-specific consent status. To use it, you need to initialize AATKit with consent type set as AATKitConsent.ConsentTypes.Vendor. Also you should pass the list of networks which should have consent set as obtained. AATKit will set consent as withheld for another networks.

#!c#
AATKitConfiguration aatkitConfiguration = new AATKitConfiguration
{
    ConsentRequired = true,
    Consent = new AATKitConsent()
    {
        Type = AATKitConsent.ConsentTypes.Vendor,
        ConsentForAddapptr = AATKitConsent.NonIABConsentType.Obtained,
        VendorConsentObtainedNetworks = new List<AATKitBinding.AdNetwork> {
            AATKitBinding.AdNetwork.ADCOLONY,
            AATKitBinding.AdNetwork.ADMOB,
            AATKitBinding.AdNetwork.DFP,
            AATKitBinding.AdNetwork.UNITYADS
        }
    }
};

To define if the user has given or withheld consent for the collection and use of personal data (used for non-IAB partners) set configuration type parameter as AATKitConsent.ConsentTypes.Simple and use NonIABConsent parameter as:

  • AATKitConsent.NonIABConsentType.Obtained if the user has given the consent.
  • AATKitConsent.NonIABConsentType.Withheld if the user has declined.

If SimpleConsent is used, it will automatically read the IAB Consent String stored (by third-party CMP) in SharedPreferences (if available).

#!c#
AATKitConfiguration aatkitConfiguration = new AATKitConfiguration
{
    ConsentRequired = true,
    Consent = new AATKitConsent()
    {
        Type = AATKitConsent.ConsentTypes.Simple,
        NonIABConsent = AATKitConsent.NonIABConsentType.Obtained
    }
};

Android instructions

Once you imported the plugin into Unity, you should be ready to build your project. Click File -> Build Settings, select the Android platform, then Switch Platform. Select desired Build System and click Build.

Resolving building issues with Unity 2019.3.X or newer

If you have mainTemplate.gradle file in your project and use Unity 2019.3.X or newer there might be building errors like:

#!

java.lang.RuntimeException: Duplicate class android.support.customtabs.ICustomTabsCallback found in modules classes.jar (androidx.browser:browser:1.0.0) and classes.jar (com.android.support:customtabs:26.1.0)

UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:187)

To resolve it, please create settingsTemplate.gradle in project’s Assets/Plugins/Android directory. Add this code to the new file:

#!gradle

gradle.rootProject {
    it.afterEvaluate {
        it.allprojects {
            // Since Unity 2019.3 enabling Jetifier via mainTemplate.gradle is no longer working
            it.ext['android.useAndroidX'] = true
            it.ext['android.enableJetifier'] = true
        }
    }
}

include ':launcher', ':unityLibrary'
**INCLUDES**

Closing the application

Closing your application by Application.Quit function is not recommended. When calling this method, Unity will terminate the application hence AATKit will not be able to send all statistics to the server correctly. So if you want to have the most accurate statistics in AddApptr Dashboard, please avoid closing your app by the code. Please note the similar issue occurs when setting Input.backButtonLeavesApp to true.

Using OnebyAOL libraries

If you use OnebyAOL you should define provider in the AndroidManifest.xml file located int the Assets/Plugins/Android directory. Please see an example below and edit attributes for provider tags. Just replace YOUR_APPLICATION_ID by your actual application id (bundle identifier). Please note you should not define the provider if you are not going to use OnebyAOL network.

#!xml

        <!-- OnebyAOL PROVIDER -->
        <provider
            android:name="com.millennialmedia.internal.utils.MediaContentProvider"
            android:authorities="YOUR_APPLICATION_ID.MediaContentProvider"
            android:grantUriPermissions="true"
            android:exported="false" />

Using AppNexus prebid libraries

You cannot create a signed apk file with AppNexus prebid for both DFP and MoPub. This is why AppNexus prebid for MoPub is disabled by default:

Zrzut ekranu 2017-09-12 o 09.03.45.png

If you want to use AppNexus prebid for MoPub, please go to the AATKit/SDK/Plugins/Android location. Select the pricecheck-sdk-mopub-2.4.8 file and mark Android in the "Select platforms for plugin" section in the Inspector tab. Then select the pricecheck-sdk-dfp-2.4.8 file and unmark Android option. This way you will avoid conflicts when building your release apk.

iOS instructions

  1. To generate your project for iOS, click File -> Build Settings, select the iOS platform, then Switch Platform and click Build.
  2. All required files should be added automatically to you project. If project fails to build make sure that aatkit postprocess script always run after other scripts. Find AATKit/SDK/Editor/AATKitPostprocess.cs file and modify [PostProcessBuild(999)] to another high number to make it run last.

Unity Editor instructions

Since version 2.13.7 it's possible to show dummy banner ads when running Unity Editor's play mode. Please see the AATKitPlaceholderManager page for instructions.

Updating the plugin

Before updating the plugin make sure you have deleted the old plugin folder (Assets/AATKit) to avoid problems with duplicated libraries.

Facebook Audience Network Integration

Android

  1. Download and unpack Facebook SDK
  2. Go to your "unity_project_directory"/Assets/AATKit/SDK/Plugins/Android and copy to it FacebookAudienceNetwork library from FacebookSDK/AudienceNetwork/bin/AudienceNetwork.jar
  3. Export project from Unity.

iOS

This network is added to the build by Pods.

Usage guide

Initialize AATKit

#!c#
using UnityEngine;

public class AATKitDemo : MonoBehaviour
{
    void Start()
    {
        AATKitConfiguration aatkitConfiguration = new AATKitConfiguration(
        {
            //Set desired configuration
            TestModeAccountId = 136,
            Consent = new AATKitConsent()
            {
                Type = AATKitConsent.ConsentTypes.ManagedCMPGoogle
            }
        };)

        AATKitBinding.Init(aatkitConfiguration);
    }
}

Adding placements

Banner ads

Fullscreen ads

Rewarded ads

Example application

You can find the example application in the AATKit/Examples folder (please make sure you have already imported this directory).

Properties

bool ScriptLogEnabled

Methods

void Init(AATKitConfiguration configuration)

void ReconfigureUsingConfiguration(AATKitConfiguration configuration)

void SetDebugEnabled()

void SetDebugShakeEnabled(bool enabled)

string GetVersion()

void GetDebugInfo()

bool IsNetworkEnabled(int network)

void SetNetworkEnabled(int network, bool enabled)

void ShowConsentDialogIfNeeded()

void EditConsent()

void ReloadConsent()

void SetPublisherProvidedId(string providerID)

Placements

Vector2 CreatePlacement(string placementName, PlacementSize placementSize)

Vector2 CreatePlacement(string placementName, PlacementSize placementSize, IAATKitStatisticsListener statisticsListener)

Vector2 CreateAppOpenAdPlacement(string placementName)

void StartPlacementAutoReload(string placementName)

void StopPlacementAutoReload(string placementName)

bool ReloadPlacement(string placementName)

bool ReloadPlacementForced(string placementName, bool forced)

bool HasAdForPlacement(string placementName)

void SetImpressionAction(string placementName, Action<AATKitImpression> action)

Banner only

void AddPlacementToView(string placementName)

void RemovePlacementFromView(string placementName)

void StartPlacementAutoReloadWithSeconds(string placementName, int seconds)

void SetPlacementAlignment(string placementName, BannerAlignment bannerAlignment)

void SetPlacementAlignmentWithOffsetInPixels(string placementName, BannerAlignment bannerAlignment, int x, int y)

void SetPlacementAlignmentWithOffset(string placementName, BannerAlignment bannerAlignment, int x, int y)

void SetPlacementPositionInPixels(string placementName, int posX, int posY)

void SetPlacementPosition(string placementName, int posX, int posY)

void SetPlacementContentGravity(string placementName, PlacementContentGravity gravity)

Fullscreen only

bool ShowPlacement(string placementName)

bool IsFrequencyCapReachedForPlacement(string placementName)

bool MuteVideoAds(bool mute)

Multi size banner only

void SetMultiSizeAlignment(string placementName, BannerAlignment multiSizeAlignment)

void SetMultiSizeAlignmentWithOffset(string placementName, BannerAlignment multiSizeAlignment, int x, int y)

void SetMultiSizePosition(string placementName, int posX, int posY)

Target info

void AddAdNetworkForKeywordTargeting(AdNetwork network)

void RemoveAdNetworkForKeywordTargeting(AdNetwork network)

void SetTargetingInfo(String placementName, Dictionary<string, List\<string>> info)

void SetTargetingInfo(Dictionary<String, List\<string>> info)

void SetContentTargetingUrl(string url)

void SetContentTargetingUrl(string placementName, string url)

iOS only

float GetScale()

float GetNativeScale()

AATKit delegates

Action<string> OnHaveAdDelegate

Action<string> OnHaveAdOnMultiSizeBannerDelegate

Action<string> OnNoAdDelegate

Action<string> OnPauseForAdDelegate

Action<string> OnResumeAfterAdDelegate

Action<IncentiveData> OnUserEarnedIncentiveDelegate

Action<bool> OnObtainedAdRulesDelegate

Action<string> OnManagedConsentNeedsUserInterfaceDelegate

Action<ManagedConsentState> OnManagedConsentCMPFinishedDelegate

Action<string> OnManagedConsentCMPFailedToLoadDelegate

Action<string> OnManagedConsentCMPFailedToShowDelegate

Updated