Sample Integration

To configure UnifID for Android and iOS devices, follow this sample integration.

iOS Setup

Initialization

1. Import the InMobi SDK header and initialize it:

IMSdk.initWithAccountID("accountID", consentDictionary: [IM_GDPR_CONSENT_AVAILABLE: 
"true", IM_GDPR_CONSENT_IAB: "<<consent in IAB format>>" ]) { (error) in
            if let error = error {
                print(error.localizedDescription)
            } 
}

2. Create a user data model as follows:

let phoneNumber = IMUserDataTypes(md5: "2wse3e", sha1: "5tfg7yh", sha256: "6tghjk")
let emailId = IMUserDataTypes(md5: "ujhjk99", sha1: "9ujkhgtyf", sha256: "jhjyure4")

let userDataModel = IMUserDataModel(phoneNumber: phoneNumber, emailId: emailId, extra: nil)

 3. Pass this data model to fetch the API:

IMUnifiedIdService.push(data: userDataModel) 

4. Call this API to fetch the UnifIDs.

IMUnifiedIdService.fetchUnifiedIds(delegate: self)

Callbacks

Implement the following delegates to receive the callbacks.

class ViewController: IMUnifiedIdInterface {
    onFetchCompleted(response: Dictionary?, error: Error?) {
    }
}

Reset

Call this reset API to clear all the user-related data and IDs stored in the SDK:

IMUnifiedIdService.reset()

Publisher provided Unified Ids (Optional)

If you have an ID from a Vendor, you can use it in the following SDK. If there is an overlap, the system prioritizes the InMobi procured Unified IDs.

IMSdk.setPublisherProvidedUnifiedID(unifiedIds : Dictionary?);

JSONObject structure:

{
    "id5" : "json(blob)",
    "live Ramp": "json(blob)"
}

Android Setup

Initialization

1. Import the InMobi SDK header and initialize it.

InMobiSdk.init(this, "Insert InMobi Account ID here", consentObject, new SdkInitializationListener() {
    @Override
    public void onInitializationComplete(@Nullable Error error) {
        if (null != error) {
            Log.e(TAG, "InMobi Init failed -" + error.getMessage());
        } else {
            Log.d(TAG, "InMobi Init Successful");
        }
    }
});

2. Create a user data model as follows:

InMobiUserDataTypes phoneNumber = new
InMobiUserDataTypes.Builder().md5("2wse3e").sha1("5tfg7yh").sha256("6tghjk").build();

InMobiUserDataTypes emailId = new I
nMobiUserDataTypes.Builder().md5("ujhjk99").sha1("9ujkhgtyf").sha256("jhjyure4").build();

HashMap<String, String> extras = new HashMap<>();
extras.put("appSpecificUniqueId", "XXXXXXXX");

InMobiUserDataModel userDataModel = new
InMobiUserDataModel.Builder().phoneNumber(phoneNumber).emailId(emailId).extras(extras).build(); 

3. Pass this data model to fetch the API.

InMobiUnifiedIdService.push(userDataModel)

4. Use this API to fetch the UnifIDs.

InMobiUnifiedIdService.fetchUnifiedIDs(this)

Callbacks

Implement the following delegates to receive the callbacks.

class MyActivity implements InMobiUnifiedIDInterface {
   @Override
        public void onFetchCompleted(JSONObject response, Error error) {
        }
} 

Reset

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

InMobiUnifiedIdService.reset()

Publisher provided Unified Ids (Optional)

If you have an ID from a Vendor, you can use it in the following SDK. If there is an overlap, the system prioritizes the InMobi procured Unified IDs.

InMobiSdk.setPublisherProvidedUnifiedID(JSONObject unifiedIds);

JSONObject structure:

{ 
    "id5" : "json(blob)", 
    "live Ramp": "json(blob)" 
} 

Recommended Usage

InMobi’s Unifi APIs expects hashed e-mail or telephone numbers to generate the identity envelope. To enhance matching, ensure to

  • Remove whitespace, blank spaces, tabs, and other characters from the plain language e-mail id.
  • Convert all the uppercase characters to lowercase.
  • Validate the email id against a regular expression.

Example: test@example.com, test@gmail.com.

Note

For email ids with @gmail.com:

  • Remove ‘.’ (ASCII code 46) from the username of the e-mail address. jane.doe@gmail.com normalizes to janedoe@gmail.com.
  • Remove ‘+’ (ASCII code 43) and all subsequent characters from the username of the e-mail address. janedoe+home@gmail.com normalizes to janedoe@gmail.com.

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,>

Testing Instructions

The request to the UnifID endpoint will not be made during the first session. From the next application start/session, the request is sent to the UnifID endpoint with the identity payload. Unifi ID endpoint:

Testing using Fetch( ) API

The quickest way to test the UnifID integration is to use InMobi Unifid Fetch API and implement its callback.

fetchUnifiedIds(delegate: UnifiedIdInterface):

The callback will have identities details in JSON Object/dictionary.

Sample Response

{ 
"ufids": [{ 
"src": "Liveramp", 
"envelope": "ApLA0JHjsUo3sCSO6NeT6i87P6eVAYuskookH7tFd-bknddGiOAeyXR9nUK8io0VaR5f32DDHMIEFYZfmo7KenUacv_hhZwxFA", 
"expiry": 1619170252591 
}, { 
"src": "ID5", 
"signature": "ID5_AUaTt3TDEeoZCyJsqeC1fIL9E-Jl675HrwbJ-0--n47mq_QPpFh6uK79MIGGbbejZGlOawA48-4A3o7fTBRpRNs", 
"envelope": "eyJjcmVhdGVkX2F0IjoiMjAyMS0wNC0yMlQwOTozMDo1Mi41MThaIiwiaWQ1X2NvbnNlbnQiOiJ0cnVlIiwic2lnbmF0dXJlIjoiSUQ1X0FVYVR0M1RERWVvWkN5SnNxZUMxZklMOUUtSmw2NzVIcndiSi0wLS1uNDdtcV9RUHBGaDZ1Szc5TUlHR2JiZWpaR2xPYXdBNDgtNEEzbzdmVEJScFJOcyIsIm9yaWdpbmFsX3VpZCI6IklENS1aSE1PajBUWUpaM0toX2xpLVcwTXVkS2hTXzFzVTlJeUtrVVJJV2tUN3chIiwidW5pdmVyc2FsX3VpZCI6IklENS1aSE1PajBUWUpaM0toX2xpLVcwTXVkS2hTXzFzVTlJeUtrVVJJV2tUN3chIiwibGlua190eXBlIjoiMCJ9", 
"expiry": 1619170252591 
}, { 
"src": "Britepool", 
"envelope": "eyJjb25maWRlbmNlIjowLjksInByaW1hcnlCUElEIjoiYmI5NjNjNmEtMDQ3Yy00NzZjLWFhZWYtMTNhNDUxYTI3YWMzIn0=", 
"expiry": 1619170252591 
}] 
}

Testing using Charles tool

Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. Follow Charles' instructions to install an SSL certificate on the Android emulator or mobile device.

Please refer to the below documentation on how to set up the Charles tool:

Configuring SSL Proxy on Mobile

Charles Official Website

Note

The logs below are gathered after the first session or launch of the application and must enable SSL proxy.

Launch your app and look for HTTP requests for unifiedID endpoint in the Charles log. Please refer to the below snapshot. If the integration is correct then, in the response body you’ll have the identity envelope with an expiry date.

Unified Endpoint: https://unif-id.ssp.inmobi.com/fetch

Make an ad request to InMobi and check for the URL: https://ads.inmobi.com. In the response body, check for the header ‘ufid’.  If integration is successful, you’ll see the same identity.

On This Page

Last Updated on: 10 Nov, 2021