The Adjust Android SDK enables you to record attribution, events, and more in your Android app. Follow the steps in this guide to set up your app to work with the Adjust SDK.
1. Get the Adjust SDK
To use the Adjust SDK in your Android app, you need to add it to your project. You can download the latest version from the GitHub releases page.
If you’re using Maven, add the following to your build.gradle
file:
2. Add Google Play Services
Apps that target the Google Play Store must use the gps_adid (Google Advertising ID) to identify devices. You need to add the play-services-ads-identifier
AAR to your project to access the gps_adid
.
If you’re using Maven, add the following to your build.gradle
file:
Collect App Set Identifier
The App Set Identifier is a unique identifier that enables you to measure information from any of your apps that a user has installed on their device. All apps by the same developer share the same App Set ID, meaning you can gather meaningful insights from users across all your apps. To record a device’s App Set ID, you need to add the following permission to your build.gradle
file:
If this permission is enabled, the App Set ID is sent to Adjust’s servers as part of the device information payload.
3. Add permissions
To give the Adjust SDK access to device information, you need to declare which permissions your app requires. To do this, add permissions to your AndroidManifest.xml
file.
Add the following permissions to get access to online features:
If your app doesn’t target the Google Play Store, add the following permission to access the device’s network state:
The Adjust SDK includes the com.google.android.gms.AD_ID
permission by default. If you need to make your app COPPA (Children’s Online Privacy Protection Act) compliant or if your app doesn’t target the Google Play Store, you must remove this permission using a remove
directive.
4. Set up Proguard
If you’re using Proguard to optimize your app, you must add rules to prevent Proguard from removing classes.
If you’re not publishing your app in the Google Play Store, add the following rule:
5. Set up install referrer
An install referrer is a unique identifier used to attribute an install to a source. The Adjust SDK requires this information to perform attribution. Use one of the following methods to retrieve the install referrer information:
Google Play Referrer API
The Google Play Referrer API is available to apps that target the Google Play Store.
To support the Google Play Referrer API, add the following to your build.gradle
file:
If you’re using Proguard, remember to add a rule to prevent the dependency from being removed.
Huawei Referrer API
The Huawei Referrer API is available to apps that target Huawei devices. The Adjust SDK can record installs on Huawei devices using Huawei App Gallery v10.4 and later. You don’t need to make any changes to support this API.
Xiaomi referrer plugin
The Xiaomi referrer plugin enables you to record install referrer values for apps that target Xiaomi devices. See the plugin documentation for install information.
Samsung referrer plugin
The Samsung referrer plugin enables you to record install referrer values for apps that target the Samsung Galaxy store. See the plugin documentation for install information.
Meta referrer integration
The Adjust SDK supports the Meta Install Referrer in v4.36.0 and above. To enable this feature:
- Find your Meta app ID in your App Dashboard. See Meta’s App Dashboard documentation for more information.
- Pass your App ID as a
String
argument to theAdjustConfig.setFbAppId
method.
6. Integrate the Adjust SDK
The following information is required to initialize the Adjust SDK:
appToken
: Your Adjust app token.environment
: The environment your app is running in. Set this toAdjustConfig.ENVIRONMENT_SANDBOX
to test your app locally.
The recommended way to initialize the Adjust SDK is inside a global Android Application class. If you haven’t already set this up for your app, follow these steps:
- Create a class that extends the
Application
. - Open the
AndroidManifest.xml
file and locate the<application>
element. - Add the
android:name
attribute to the<application>
element and set it to the name of your application class. For example, if yourApplication
class is namedGlobalApplication
, you would set the following:
-
Find the
onCreate
method in yourApplication
class or add one if it doesn’t exist. Pass the following parameters to initialize the Adjust SDK:- Your
appToken
- The
environment
you want to run the app in - The
LogLevel
you want to record
- Your
Integrate the Adjust Web View SDK
If your app uses web views, you need to use the Adjust Web View SDK to record information. You need to obtain the reference to your WebView
object. Once you’ve done this, follow these steps:
- Call
webView.getSettings().setJavaScriptEnabled(true)
to enable Javascript in the web view. - Start the default
AdjustBridgeInstance
by callingAdjustBridge.registerAndGetInstance(getApplication(), webview)
. This registers the Adjust bridge as a Javascript interface in the web view. - Call
AdjustBridge.setWebView()
to set a newWebView
. - Call
AdjustBridge.unregister()
to unregister theAdjustBridgeInstance
and theWebView
. - Here’s an example of a full setup:
- Import the Adjust Javascript files in your HTML:
- You can now initialize the Adjust SDK in your web view by passing your
appToken
andenvironment
to theAdjustConfig
class:
7. Configure session recording
To record session information, you need to call methods at different stages of your app’s activity lifecycle. These stages are different depending on the API level your app targets.
API level 14 and above
To set up session recording for API level 14 and above:
- If you have
Adjust.onResume
andAdjust.onPause
calls in your activities, remove them. - Add a private class that implements the
ActivityLifecycleCallbacks
interface. - Edit the
onActivityResumed(Activity activity)
method and add a call toAdjust.onResume()
. - Edit the
onActivityPaused(Activity activity)
method and add a call toAdjust.onPause()
. - Add the
onCreate()
method to your Adjust SDK configuration step. - Call
registerActivityLifecycleCallbacks
with an instance of the createdActivityLifecycleCallbacks
class:
API level 9 to 13
To set up session recording in apps targeting API level 13 and below, follow these steps:
- Add a call to
Adjust.onResume()
in your activity’sonResume
method. - Add a call to
Adjust.onPause()
in your activity’sonPause
method. - Repeat these steps for each activity in your app. Depending on your coding style, you might want to add this in a common superclass of all your activities.
8. Build your app for production
Once you’ve finished your testing, you can build your app for production. To do this, you need to update your config object.
- Adjust your log level to return only what you need.
- Set your
environment
toAdjustConfig.ENVIRONMENT_PRODUCTION
.