Back to top

Import and Initialize Unity Package

Last Updated on: 03 Aug, 2022

BEFORE YOU START

Meson supports Unity version 2018.4.18f1 and above.

The download and use of the SDK are subject to the Meson SDK Licensing Terms. If you do not agree to these terms, do not download, access, or use the SDK, or the underlying services.

Download the Meson Unity Package

You can download the Meson Unity Package here.

Import Meson Unity Package to the project

In Unity, Go to Assets, go to Import Package and select Custom Package. Navigate to the downloaded Meson Unity Package. Select the package. The package contents will show on Unity. Select All and Import.

Managing and Adding 3rd Party Ad Network dependency

To edit 3rd Party Ad Network support, edit MesonDependencies.xml

To access MesonDependencies.xml, Go to Assets > Meson > Scripts > Editor > MesonDependencies.xml

<dependencies>
    //Mandatory Dependencies
    <androidPackages>
        <androidPackage spec="ai.meson.sdk:meson:1.0.0-beta14"/>      
        <androidPackage spec="org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10"/>
        <androidPackage spec="org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"/>
        <androidPackage spec="org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"/>
    </androidPackages>

    //iOS Ad Networks
    <iosPods>
        <iosPod name="InMobiSDK" version="10.0.7"/>
        <iosPod name="MesonInMobiAdapter" version="10.0.7.0-beta6"/>

        <iosPod name="Google-Mobile-Ads-SDK" version="9.6.0"/>
        <iosPod name="MesonGAMAdapter" version="9.6.0.0-beta6"/>
        <iosPod name="MesonAdmobAdapter" version="9.6.0.0-beta6"/>

        <iosPod name="MesonSDK" version="1.0.0-beta6"/>

        <iosPod name="IronSourceSDK" version="7.2.2.0"/>
        <iosPod name="MesonIronSourceAdapter" version="7.2.2.0-beta6"/>

        <iosPod name="AppLovinSDK" version="11.4.2"/>
        <iosPod name="MesonApplovinAdapter" version="11.4.2.1-beta6"/>

        <iosPod name="UnityAds" version="4.2.1"/>
        <iosPod name="MesonUnityAdapter" version="4.2.1.0-beta6"/>

        <iosPod name="MintegralAdSDK" version="7.1.7"/>
        <iosPod name="MesonMintegralAdapter" version="7.1.7.0-beta6"/>

        <iosPod name="VungleSDK-iOS" version="6.11.0"/>
        <iosPod name="MesonVungleAdapter" version="6.11.0.0-beta6"/>

         <iosPod name="FBAudienceNetwork" version="6.9.0"/>
        <iosPod name="MesonFANAdapter" version="6.9.0.0-beta5"/>

    </iosPods>
    // Android Ad Networks
    <!-- InMobi -->
    <androidPackage spec="com.inmobi.monetization:inmobi-ads:10.0.7"/>
    <androidPackage spec="ai.meson.sdk.mediation:inmobi:10.0.7.0-beta1"/>

    <!-- Google AdMob -->
    <androidPackage spec="com.google.android.gms:play-services-ads:21.0.0"/>
    <androidPackage spec="ai.meson.sdk.mediation:admob:21.0.0.0-beta1"/>

    <!-- Google Ad Manager -->
    <androidPackage spec="com.google.android.gms:play-services-ads:21.0.0"/>
    <androidPackage spec="ai.meson.sdk.mediation:gam:21.0.0.0-beta1"/>

    <!-- Facebook Audience Network -->
    <androidPackage spec="com.facebook.android:audience-network-sdk:6.7.0"/>
    <androidPackage spec="ai.meson.sdk.mediation:facebook:6.7.0.0-beta3"/>

    <!-- Vungle -->
    <androidPackage spec="com.vungle:publisher-sdk-android:6.11.0"/>
    <androidPackage spec="ai.meson.sdk.mediation:vungle:6.11.0.0-beta1"/>

    <!-- Mintegral -->
    <androidPackage spec="com.mbridge.msdk.oversea:mbbid:16.1.41"/>
    <androidPackage spec="ai.meson.sdk.mediation:mintegral:16.1.41.0-beta1"/>
    <androidPackage spec="com.mbridge.msdk.oversea:reward:16.1.41"/>
    <androidPackage spec="com.mbridge.msdk.oversea:interstitialvideo:16.1.41"/>
    <androidPackage spec="com.mbridge.msdk.oversea:mbbanner:16.1.41"/>
    <androidPackage spec="com.mbridge.msdk.oversea:interstitial:16.1.41"/>

    <!-- Unity -->
    <androidPackage spec="com.unity3d.ads:unity-ads:4.2.1"/>
    <androidPackage spec="ai.meson.sdk.mediation:unity:4.2.1.0-beta2"/>

    <!-- App Lovin -->
    <androidPackage spec="com.applovin:applovin-sdk:11.4.3"/>
    <androidPackage spec="ai.meson.sdk.mediation:applovin:11.4.3.0-beta1"/>

</dependencies>

Initialize the Unity plugin using Meson Manager (Recommended)

  1. Drag and drop the MesonManager prefab from Assets/Meson/Prefabs onto your scene.

  2. Enter the required settings as per your need.
    Option Description
    Auto Initialise on Start Check this option to automatically initialize the Meson SDK in Start (). The SDK must be initialized before you can request ads. Leaving it unchecked means you must manually initialize the SDK.
    iOS App ID Unique Identifier for an iOS app generated on Meson UI while creating a new app
    Android App ID Unique Identifier for an Android app generated on Meson UI while creating a new app
    Log level Specify log verbosity (‘none’, ‘error’, or ‘debug’) for the Meson SDK.
    GDPR Consent GDPR consent can be passed either as an IAB v1 or v2 string, boolean value.
    Callback Subscribe to initialization callback to listen to for initialization event completion lifecycle.
  3. iOS and Android App IDs must be set for successful integration.

Initialize the plugin manually

  1. In the app Start() method, instantiate a Meson.SdkConfiguration object with i. iOS App ID - Unique Identifier for an iOS app generated on Meson UI while creating a new app ii. Android App ID - Unique Identifier for an Android app generated on Meson UI while creating a new app iii. Log level - Specify log verbosity (‘none’, ‘error’ or ‘debug’) for the Meson SDK. iv. Consent (optional) - GDPR consent can be passed either as an IAB v1 or v2 string, boolean value.
  2. Call Meson.InitializeSDK() and pass the Meson.SdkConfiguration Object.
Dictionary<string, string> consentDictionary = new Dictionary<string, string>();
            
            consentDictionary.Add(Meson.MESON_GDPR_CONSENT_AVAILABLE, "true");
            
            consentDictionary.Add(Meson.MESON_GDPR_CONSENT_GDPR_APPLIES, "0");
            
            consentDictionary.Add(Meson.MESON_GDPR_CONSENT_IAB, "IAB String v1 or v2");


Meson.InitializeSdk(new Meson.SdkConfiguration

{
                AndroidAppId = "12345",

                IOSAppId = "1234",

                LogLevel = Meson.LogLevel.Debug,

                ConsentDict = consentDictionary

  });
  1. Register for onSDKInitializedEvent a callback event.
// register for initialized callback event in the app

 MesonManager.SdkInitializedEvent += OnSdkInitializedEvent;
// create your handler

  private void OnSdkInitializedEvent(string adUnitId)
{

// The SDK is initialized here. Ready to make ad requests.

}

Add User Data

NOTE

  • To use cohorts in Meson UI, this is where you will need to set PPID unique to a user.
  • To use segments or experiments in Meson UI, this is where you will need to send the segments or experiments.

This is optional. In case you want to send us any information about the user, please do as follows:

Dictionary<string, dynamic> extrasDictionary = new Dictionary<string, dynamic>();
extrasDictionary.Add("gender", 1);
extrasDictionary.Add("age", 18);
string[] segments = { "s1", "s2", "s3" };
extrasDictionary.Add("segments", segments);

Meson.SetExtras(extrasDictionary);

Add ProGuard Rules

NOTE

  • If you are using ProGuard and do not do this step, you could have issues with initialization.
  • Please check proguard rules with networks you are using as these will also need to be added within.

If you are using ProGuard, you must add the following code to your ProGuard file:

-keep class ai.meson.** {*;}
-keep interface ai.meson.** {*;}
-keepclassmembers class ai.meson.** { public *; }