Unity Integration

Follow the instructions to integrate Unity.

  1. Open your project in the Unity editor.
  2. Select Assets Import Package Custom Package, and search for the InMobiAdsUnityPackage_1001.unitypackage file that you have downloaded.

    Note

    You must use the Unity version 2020.1.10f1 or above for InMobi Unity Plugin to ensure a smoother experience.

Initialization

Import the InMobi SDK header and initialize it.

public void InitializeInMobiAds() 
    { 
        UpdateLogs("initializeInMobiAds "); 
		InMobiPlugin inmobiPlugin = new InMobiPlugin(); 
	 inmobiPlugin.OnInitializationCompleted += this.HandleInitializationStatus; 
        Dictionary<string, object=""> consentObject = new Dictionary<string, object="">(); 
	     consentObject.Add(InMobiPlugin.IM_GDPR_CONSENT_AVAILABLE, true); 
        consentObject.Add(InMobiPlugin.IM_GDPR_CONSENT_IAB, "IAB_STRING"); 
        inmobiPlugin.Init("<inmobi account="" id="">", consentObject); 
        inmobiPlugin.SetLogLevel("Debug"); 
        inmobiPlugin.SetAge(23); 
    } 
public void HandleInitializationStatus (object sender, SdkInitializationStatusArgs args) { 
        UpdateLogs("SDK Initialization status code : " + args.status.Code + " and reason : " + args.status.Reason); 
    } </inmobi></string,></string,>

Unified push( )

Create a user data model as follows:

InMobiUserDataTypes emailIdData = new InMobiUserDataTypes(); 
emailIdData.Md5 = CreateMD5(emailID); 
emailIdData.Sha1 = CreateSHA1(emailID); 
emailIdData.Sha256 = CreateSHA256(emailID);  
InMobiUserDataTypes phoneNumberData = new InMobiUserDataTypes(); 
phoneNumberData.Md5 = CreateMD5(phoneNumber); 
phoneNumberData.Sha1 = CreateSHA1(phoneNumber); 
phoneNumberData.Sha256 = CreateSHA256(phoneNumber);  
InMobiUserDataModel userDataModel = new InMobiUserDataModel(); 
userDataModel.EmailID = emailIdData;  
userDataModel.PhoneNumber = phoneNumberData;
// Pass this data model to fetch the API. 
InMobiUnifiedIdService.Push(userDataModel);

Unified fetchUnifiedIds ( )

Use this API to fetch the UnifFI IDs.

InMobiUnifiedIdService.FetchUnifiedIds();  
Callback:  
public void onFetchCompleted(object sender, OnFetchCompletedEventArgs e) 
    { 
        UnityMainThreadHelper.GetInstance().PostTask(() => { 
            Logger.getInstance().log("onFetchCompleted" + e.unifiedIds + " " + e.error, logField); 
        }); 
    }

Sample Code

public InputField logField; 
    public void onFetchCompleted(object sender, OnFetchCompletedEventArgs e) 
    { 
        UnityMainThreadHelper.GetInstance().PostTask(() => { 
            Logger.getInstance().log("onFetchCompleted" + e.unifiedIds + " " + e.error, logField); 
        }); 
    } 
    private void Start() 
    { 
        InMobiUnifiedIdService.OnFetchCompleted += onFetchCompleted; 
    } 
    public void onFetch() 
    { 
        Logger.getInstance().log("Fetch Called", logField); 
        InMobiUnifiedIdService.FetchUnifiedIds(); 
    }

Unified reset( )

Call the following reset API to clear all the user-related data and Ids stored in the SDK.

InMobiUnifiedIdService.Reset();

Unified setPublisherProvidedUnifiedId ( )

Use the following function to pass the UIDs (Universal IDs) obtained by having direct partnerships with different ID partners (e.g., liveramp, id5, and so on.), upstream to demand partners, or to other ad exchanges.

InMobiSdk.setPublisherProvidedUnifiedID(Dictionary unifiedIds);

Sample Code

InMobiPlugin inMobiPlugin = new InMobiPlugin(); 
Dictionary<string, object=""> unifIds = new Dictionary<string, object="">(); 
unifIds.Add("key0", "value0"); 
unifIds.Add("nestedJson", level1); 
inMobiPlugin.SetPublisherProvidedUnifiedId(unifIds); </string,></string,>

On This Page

Last Updated on: 09 Mar, 2022