Welcome to the Fyber Android Developer Portal

Let's get started.

Docs

Integrating the SDK

Step 1: Adding the Fyber SDK to your Project

Add the Fyber Maven repository and Fyber SDK dependency to your build.gradle file.

repositories {
  maven {
    name "Fyber's maven repo"
    url "https://fyber.bintray.com/maven"
  }
}

dependencies {
  implementation 'com.fyber:fyber-sdk:8.22.1'
}

Integrating Google Play Services

We recommend you use the Google Play Services, as otherwise we aren't able to access your Google Advertising ID. This leads to limited ad inventory, as an increasing number of advertising campaigns require the identifier. This ID is also essential for tracking daily active users (DAU) on your app.

If you have not integrated Google Play Services yet, please follow the Google Play Services integration guide.

Please Note!

Fyber SDK only requires the com.google.android.gms:play-services-ads library. Your app may require additional APIs from Google Play Services.

You could simply include the entire library but doing so risks exceeding the DEX limit. It's optimal to only include the services you need.

To ensure we can access the Google Advertising ID, please include the following lines for Google Play Services:

# Google Advertising Id

-keep class com.google.android.gms.ads.identifier.** { *; }

Please Note!

If your project uses ProGuard, be sure to follow Google's instructions to prevent it from stripping away required classes.

Step 2: Adding User Consent

The General Data Protection Regulation requires you to scope your user's consent. A user is within the GDPR scope for your app when one or all of the following apply:

  • The user is currently located in the EU
  • The user has registered with the app as an EU resident
  • The app is specifically targeted to EU users

Once you have collected the user’s consent and/or consent string, you can pass them onto the SDK using the following API:

User.setGdprConsent(isGdprConsentGiven, context);

Map<String,String> consentData consentData = fetchConsentDataFromCmp();
User.setGdprConsentData(consentData, Context context);

isGdprConsentGiven is a boolean. It is true if you have the user’s consent. If you do not have the user's consent, it is false.

When passing an actual Consent String please use the "gdpr_consent_string" dictionary key only.
context is a valid Android Context.
If you don’t pass the user’s consent to the SDK, only contextual ads will be shown to that user.

In order to clear consent flag and consent data the following API can be used:

User.clearGdprConsentData(context)

We recommend that the first time you gather the user’s consent, you pass it onto the SDK before starting the SDK. The SDK will then take the user’s consent into consideration when initializing. In the following sessions, you will only need to call the API if the user updates his or her consent.

More information on GDPR can be found under the GDPR Resource Page and FAQs.

Step 3: Starting the SDK

You’ll need to start the Fyber SDK before being able to use any Fyber product.

Warning!

Starting up the Fyber SDK when the main thread is performing a heavy operation (loading assets, etc) can result in an unresponsive state (for example, an ANR). This may lead to the app being down ranked in the app store. This is especially true for slower devices. For these reasons, It is advised to initialize the Fyber SDK after all the heavy operations are completed.

To do this, determine a point in your application’s code that runs when the application starts. We recommend the onResume method of your main activity.

import com.fyber.Fyber;

[...]

@Override
protected void onResume() {
	Fyber.with(appId, activity)
    			.withUserId(userId)
     			.withSecurityToken(securityToken)
     			.start();
}

The securityToken and appId are required, and can be found in the Settings of your app in the Dashboard. The userId should uniquely identify the user of your app.

Common Error!

Fyber requires user ids to be unique within your app. You may not hardcode or share user ids. If necessary, the Fyber SDK can assign unique user ids for you (see below).

Automatically Generated user ids

The previous method is our preferred method of starting the SDK.

If you do not want to set a userId yourself and would rather the Fyber SDK create it for you, the Fyber SDK will do so when you omit the call to withUserId(...) in your code:

import com.fyber.Fyber;

[...]

@Override
protected void onResume() {
	Fyber.with(appId, activity)
     			.withSecurityToken(securityToken)
     			.start();
}

This generates the required unique userId on the first launch of the application and stores it for subsequent launches.

Subsequent usage of the Fyber SDK during your application's lifecycle will reuse the parameters passed to this call. If the user re-installs the app, a new userId will be generated.

You are now ready to start using Fyber's products!

Not sure which products you'd like to use? Please review the Introducing Our Products section for a discussion of the benefits of all Fyber products.