Please Note this page provides best practices only, the code in this page should be taken as a recommendation on how to fetch the native “Advertising ID” from your app code

According to Google and Apple guidelines regarding advertising ID (AdId), publishers who use Outbrain JS-Widget for their apps will need to pass the AdId .

The SDK automatically does it for you, however the JS widget will have to be addressed manually because the webview is 100% under the publisher control.

Android Guidelines

iOS Guidelines


Android

First update your app build.gradle to include Google Mobile Ads from Google Play Services: (read more)


dependencies {
    .
    .
    compile  'com.google.android.gms:play-services-ads:9.2.1'
    .
    .
}



In the main Activity of the app, add the following method and make sure you call it from the Activity onCreate() method:

private void fetchAdvertisingIDExample() {
        Log.v("OBSDK", "trying to get AdId from Google Play Services");
        final Activity activity = this;

        GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
        if (googleAPI.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
            new Thread(new Runnable() {
                public void run() {
                    AdvertisingIdClient.Info adInfo = null;

                    try {
                        adInfo = AdvertisingIdClient.getAdvertisingIdInfo(activity);
                    } catch (IOException e) {
                        Log.e("OBSDK", e.getMessage());
                    } catch (GooglePlayServicesNotAvailableException e) {
                        Log.e("OBSDK", e.getMessage());
                    } catch (GooglePlayServicesRepairableException e) {
                        Log.e("OBSDK", e.getMessage());
                    }
                    String AdId = adInfo.getId();
                    boolean userOptOutAdTracking = adInfo.isLimitAdTrackingEnabled();

                    // Respecting user’s “opt out of interest-based advertising” setting
                    // More details in: https://play.google.com/intl/ALL_us/about/developer-content-policy.html
                    if (userOptOutAdTracking) {
                        Log.v("OBSDK", "userOptOutAdTracking --> Removing AdId from Prefs");

                    }
                    else {
                        Log.v("OBSDK", "Saving AdId: " + AdId + " to Prefs");
                    }
                }
            }).start();
        }
        else {
            Log.e("OBSDK", "Error: Google Play Services are not available, error: " + GooglePlayServicesUtil.isGooglePlayServicesAvailable(this));
        }
    }

iOS

1) Add AdSupport.framework in Link Binary with Binaries section in the app target Settings.

adsupport-framework-xcode

2) Add the “import” below in file appDelegate.m:

@import AdSupport;



3) In appDelegate.m, add the following method and make sure you call it from application:didFinishLaunchingWithOptions:

- (void) fetchAdvertisingIDExample {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    if ([ASIdentifierManager sharedManager].advertisingTrackingEnabled) {
        [defaults setObject:[[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString] forKey:@"kAdvertiserID"];
    }
    else {
        // throw away any tracking info you may have saved before
        [defaults setObject:nil forKey:@"kAdvertiserID"];
    }
    NSLog(@"Advertiser ID: %@", [defaults valueForKey:@"kAdvertiserID"]);
}