Important Note:
- This article has been moved to our Developer Center, and will no longer be updated on this site. Here is the newest version of our Android SDK Settings Guide.
This article will guide you through using Amplitude's Android SDK to track users and events. The variables and values in red are what you will need to replace with your own. Please see our Android SDK reference for a description of all available SDK methods and classes. For best practices on instrumenting Amplitude, see our Getting Started Guide for developers and sign up for one of our instrumentation training seminars here. For more developer specific content, please feel free to visit our Developer Centre here.
The SDK automatically pulls useful data from a user's device, including app version, phone model, operating system version, and carrier information. They are displayed as user properties in Amplitude, and you can read more about them here. The source code for Amplitude's Android SDK can be found on GitHub here. The size of Amplitude's most recent version of the Android SDK (v2.23.2) is 84.8KB without dependencies like okhttp3. With dependencies it is about 567KB.
Starting with Version 2.24.1, the SDK now also supports control for COPPA - Children's Online Privacy Protection Act.
Table of Contents
- Installation
- Tracking Events
- Tracking Sessions
- Setting Custom User IDs
- Setting Event Properties
- Setting User Properties
- Setting Group Properties
- Tracking Revenue
- Opting User Out of Logging
- Disable Automatic Tracking of User Properties
- Advanced
Installation
1. Create an Amplitude account. If you have not already, go to https://amplitude.com and register for an account. Then, create an organization and a project. You will immediately receive an API Key for the project you have just created.
2. Install the SDK. There are a few options to install the Android SDK.
- Download the JAR here and copy it into the "libs" folder in your Android project in Android Studio. Alternatively, if you are using Maven in your project, the JAR is available on Maven Central using the following configuration in your pom.xml:
<dependency> <groupId>com.amplitude</groupId> <artifactId>android-sdk</artifactId> <version>2.23.2</version> </dependency>
- Or, if you are using gradle in your project, include the following line in your build.gradle file:
compile 'com.amplitude:android-sdk:2.23.2'
3. Add permissions. If you have not already, add the INTERNET permission to your manifest file:
<uses-permission android:name="android.permission.INTERNET" />
4. Import. In every file that uses analytics, import Amplitude at the top:
import com.amplitude.api.Amplitude;
5. Initialize the SDK with your API Key. In the onCreate()
of your main activity, initialize the SDK:
Amplitude.getInstance().initialize(this, "API_KEY").enableForegroundTracking(getApplication());
Replace API_KEY
with the API Key given to you. You can find your project's API Key in your project's Settings page. Note: If your app has multiple entry points/exit points, you should make a Amplitude.getInstance().initialize()
at every onCreate()
entry point.
6. Start tracking events. Data is sent to Amplitude via events. As a result, you will have to explicitly log events in order to see any data in your project. To track an event anywhere in the app, call:
Amplitude.getInstance().logEvent("EVENT_TYPE");
where EVENT_TYPE
is the name you are giving to the event you want to track.
7. Attribution integration. If you want to use Google Advertising IDs, make sure to add Google Play Services to your project.
IMPORTANT NOTE: Google play integration is required for third party attribution matching when tracking events with our Android SDK.
8. Event uploads. Events are saved locally. Uploads are batched to occur every 30 events, every 30 seconds, and on app close. After calling logEvent()
in your app, you will immediately see data appear in Amplitude. Note: By default, unsent events are uploaded when your app is minimized or closed via the Activity Lifecycle onPause
callback. If you wish to disable this behavior, you can call Amplitude.getInstance().setFlushEventsOnClose(false);
. When a user is offline, we store their most recent 1000 events by default and then upload them once the user is online again. When the user returns online, their events are processed by first-in, first-out.
Tracking Events
It is important to consider what types of events you care about as a developer. You should aim to track between 20 and 200 types of events on your site. Common event types are actions the user initiates (such as pressing a button) and events you want the user to complete (such as filling out a form, completing a level, or making a payment).
Here are some resources to help you with your taxonomy or instrumentation planning:
Having a large number of distinct event types, event properties, and user properties can make data exploration and visualization very confusing. By default, we only show the first:
- 2000 distinct event types
- 2000 distinct event properties
- 1000 distinct user properties
Anything past the above thresholds will not be visualized. Note: The raw data is not impacted by this in any way, meaning that you will still see the values in the raw data but they will not be visualized in the platform. A single call to logEvent
should not have more than 1000 event properties. Likewise, a single call to setUserProperties
should not have more than 1000 user properties. If the 1000 property limit is exceeded then the properties will be dropped and a warning will be printed in the console. We have put in very conservative estimates for the event type and property caps that we do not expect to be exceeded in any practical use case. If you feel that your use case will go above those limits, please reach out to us here.
To track an event anywhere in the app, call:
Amplitude.getInstance().logEvent("EVENT_TYPE");
where EVENT_TYPE
is the name you are giving to the event you want to track.
Logging Events to Multiple Projects
The Amplitude Android SDK supports logging events to multiple Amplitude projects (multiple API keys). If you want to log events to multiple Amplitude projects, you will need to use separate instances for each Amplitude project. Each new instance created will have its own apiKey
, userId
, deviceId
, and settings. You will need to assign a name to each Amplitude project/instance and use that name consistently when fetching that instance to call functions.
IMPORTANT NOTE: Once you have chosen a name for that instance you cannot change it.
Choose your instance names carefully because every instance's data and settings are tied to its name, and you will need to continue using that instance name for all future versions of your app to maintain data continuity. Note that these names do not need to correspond to the names of your projects in Amplitude, but they will need to remain consistent throughout your code. You also need to be sure that each instance is initialized with the correct apiKey
.
Instance names must be non-null and nonempty strings, and the names are case insensitive. You can fetch each instance by name by calling:
Amplitude.getInstance("INSTANCE_NAME");
As mentioned before, each new instance created will have its own apiKey
, userId
, deviceId
, and settings. IMPORTANT NOTE: You will have to reconfigure all the settings for each instance. For example, if you want to enable foreground tracking you will have to call enableForegroundTracking
on each instance. This gives you the freedom to have different settings for each instance.
Here is an example on how to set up and log events to two separate projects:
Amplitude.getInstance().initialize(this, "12345"); // existing project, existing settings, and existing API key
Amplitude.getInstance("new_project").initialize(this, "67890"); // new project, new API key
Amplitude.getInstance("new_project").setUserId("joe@gmail.com"); // need to reconfigure new project
Amplitude.getInstance("new_project").logEvent("Clicked");
Identify identify = new Identify().add("karma", 1);
Amplitude.getInstance().identify(identify);
Amplitude.getInstance().logEvent("Viewed Home Page");
Synchronizing Device IDs Between Apps
As mentioned before, each new instance will have its own deviceId
. If you want your apps to share the same deviceId
, you can do so after initialization via the getDeviceId
and setDeviceId
methods. Here is an example of how to copy the existing deviceId
to the new_project
instance:
String deviceId = Amplitude.getInstance().getDeviceId(); // existing deviceId
Amplitude.getInstance("new_project").setDeviceId(deviceId); // transferring existing deviceId to new project
Backwards Compatibility
If you were tracking users with a single app before version 2.14.0 (released July 2017), you might be wondering what will happen to existing data, existing settings, and returning users (users who already have a deviceId
and/or userId
). All of the historical data and settings are maintained on the default
instance, which is fetched without an instance name: Amplitude.getInstance()
. This is the way you are used to interacting with the Amplitude SDK, which means all of your existing tracking code should work as before.
Tracking Sessions
A session is a period of time that a user has the app in the foreground. Events that are logged within the same session will have the same session_id
. Sessions are handled automatically so you do not have to manually call startSession()
or endSession()
.
For Android API level 14 and above, a new session is created when the app comes back into the foreground after being in the background for five or more minutes or when the last event was logged (whichever occurred last). Otherwise, the background event logged will be part of the current session. Note that you can define your own session expiration time by calling setMinTimeBetweenSessionsMillis(timeout)
, where the timeout input is in milliseconds.
For Android API level 13 and below, foreground tracking is not available so a new session is automatically started when an event is logged 5 minutes or more after the last logged event. If another event is logged within 5 minutes, it will extend the current session. Note that you can define your own session expiration time here as well by calling setSessionTimeoutMillis(timeout)
, where the timeout input is in milliseconds. Also note that enableForegroundTracking(getApplication)
is still safe to call for Android API level 13 and below even though it is not available.
By default, '[Amplitude] Start Session' and '[Amplitude] End Session' events are no longer sent. Even though these events are not sent, sessions are still tracked by using session_id
. To re-enable those session events, add this line before initializing the SDK:
Amplitude.getInstance().trackSessionEvents(true);
You can also log events as out-of-session. Out-of-session events have a session_id
of -1
and are not considered part of the current session, meaning they do not extend the current session. This might be useful if you are logging events triggered by push notifications, for example. You can log events as out-of-session by setting the input parameter outOfSession
to true
when calling logEvent()
:
Amplitude.getInstance().logEvent("EVENT_TYPE", null, true);
You can also log identify
events as out-of-session, which is useful if you are updating user properties in the background and do not want to start a new session. You can do this by setting the input parameter outOfSession
to true when calling identify()
:
Identify identify = new Identify().set("key", "value"); Amplitude.getInstance().identify(identify, true);
Getting the Session ID
You can use the helper method getSessionId
to get the value of the current sessionId
:
long sessionId = Amplitude.getInstance().getSessionId();
Setting Custom User IDs
If your app has its own login system that you want to track users with, you can call setUserId()
at any time:
Amplitude.getInstance().setUserId("USER_ID");
You can also add the User ID as an argument to the initialize()
call:
Amplitude.getInstance().initialize(this, "API_KEY", "USER_ID");
You should not assign users a User ID that could change as each unique User ID is interpreted as an unique user in Amplitude. Please see our article on how we identify and count unique users for further information.
Logging Out and Anonymous Users
A user's data will be merged on the backend so that any events up to that point from the same browser will be tracked under the same user. If a user logs out or you want to log the events under an anonymous user, you will need to:
- Set the
userId
tonull
. - Regenerate a new
deviceId
.
After doing that, events coming from the current user/device will appear as a brand new user in Amplitude. Note: If you choose to do this, you will not be able to see that the two users were using the same device. Here is an example:
Amplitude.getInstance().setUserId(null); Amplitude.getInstance().regenerateDeviceId();
Setting Event Properties
You can send event property attributes to any event by passing a JSONObject as the second argument to logEvent()
:
JSONObject eventProperties = new JSONObject(); try { eventProperties.put("KEY", "VALUE"); } catch (JSONException exception) { } Amplitude.getInstance().logEvent("Sent Message", eventProperties);
You will need to add two JSONObject imports to the code:
import org.json.JSONException; import org.json.JSONObject;
Arrays in Event Properties
The SDK supports sending arrays as event properties. Here is an example:
JSONArray colors = new JSONArray(); colors.put("rose").put("gold");
JSONObject eventProperties = new JSONObject();
eventProperties.put("colors", colors);
Amplitude.getInstance().logEvent("Purchased iPhone", colors);
Setting User Properties
IMPORTANT NOTE: Please be sure to not track any user data that may be against your privacy terms. If you need any assistance with privacy concerns, then please reach out to our Platform team here.
The SDK automatically pulls useful data about the browser, including browser type and operating system version. They are displayed as user properties in Amplitude. You can read more about them here. You can turn off this automatic tracking by disabling specific user properties using the provided TrackingOptions
interface.
The SDK supports the operations set
, setOnce
, unset
, and add
on individual user properties. The operations are declared via a provided Identify
interface. Multiple operations can be chained together in a single Identify
object. The Identify
object is then passed to the Amplitude client to send to the server. The results of the operations will be visible immediately in the dashboard and will take effect for events logged after.
To use the Identify
interface, you will first need to import the class:
import com.amplitude.api.Identify;
set
: This sets the value of a user property.Identify identify = new Identify().set("gender", "female").set("age", 20); Amplitude.getInstance().identify(identify);
setOnce
: This sets the value of a user property only once. SubsequentsetOnce
operations on that user property will be ignored. In the following example, 'sign_up_date' will be set once to '2015-08-24', and the followingsetOnce
to '2015-09-14' will be ignored.Identify identify1 = new Identify().setOnce("sign_up_date", "2015-08-24"); Amplitude.getInstance().identify(identify1); Identify identify2 = new Identify().setOnce("sign_up_date", "2015-09-14"); amplitude.identify(identify2);
unset
: This will unset and remove a user property.Identify identify = new Identify().unset("gender").unset("age"); Amplitude.getInstance().identify(identify);
add
: This will increment a user property by some numerical value. If the user property does not have a value set yet, it will be initialized to 0 before being incremented.Identify identify = new Identify().add("karma", 1).add("friends", 1); Amplitude.getInstance().identify(identify);
append
: This will append a value or values to a user property array. If the user property does not have a value set yet, it will be initialized to an empty list before the new values are appended. If the user property has an existing value and it is not on a list, it will be converted into a list with the new value appended.Identify identify = new Identify().append("ab-tests", "new-user-test").append("some_list", new JSONArray().put(1).put("some_string")); Amplitude.getInstance().identify(identify);
prepend
: This will prepend a value or values to a user property. Prepend means inserting the value(s) at the front of a given list. If the user property does not have a value set yet, it will be initialized to an empty list before the new values are prepended. If the user property has an existing value and it is not a list, it will be converted into a list with the new value prepended.Identify identify = new Identify().prepend("ab-tests", "new-user-test").prepend("some_list", new JSONArray().put(1).put("some_string")); Amplitude.getInstance().identify(identify);
Note: If a user property is used in multiple operations on the same Identify
object, then only the first operation will be saved and the rest will be ignored. In this example, only the set
operation will be saved, and the add
and unset
will be ignored:
Identify identify = new Identify().set("karma", 10).add("karma", 1).unset("karma"); Amplitude.getInstance().identify(identify);
Arrays in User Properties
The SDK supports arrays in user properties. Any of the user property operations above (with the exception of add
) can accept a JSONArray or any Java primitive array. You can directly set
arrays or use append
to generate an array. Here is an example:
JSONArray colors = new JSONArray(); colors.put("rose").put("gold"); Identify identify = new Identify().set("colors", colors).append("ab-tests", "campaign_a").append("existing_list", new int[]{4,5}); Amplitude.getInstance().identify(identify);
Setting Multiple User Properties
You may use setUserProperties
shorthand to set multiple user properties at once. This method is simply a wrapper around Identify.set
and identify
. Here is an example:
JSONObject userProperties = new JSONObject(); try { userProperties.put("KEY", "VALUE"); userProperties.put("OTHER_KEY", "OTHER_VALUE"); } catch (JSONException exception) { } Amplitude.getInstance().setUserProperties(userProperties);
Clearing User Properties
You may use clearUserProperties
to clear all user properties at once. This will wipe all of the current user's user properties. Note: The result is irreversible! Amplitude will not be able to sync the user's user property values before the wipe to any future events that the user triggers as they will have been reset.
Amplitude.getInstance().clearUserProperties();
Updating User Properties in the Background
When you are updating user properties in the background and do not wish to trigger a session while updating them, make sure to set outOfSession
to true
:
Identify identify = new Identify().set("color", "blue"); Amplitude.getInstance().identify(identify, true);
Setting Group Properties
Just like setting user properties, you can also use AMPIdentify interface to set and update group properties.
Identify groupIdentify = new Identify().set("members", 80);
Amplitude.getInstance().groupIdentify("company", "Amplitude", groupIdentify);
Tracking Revenue
The preferred method of tracking revenue for a user now is to use logRevenueV2()
in conjunction with the provided Revenue
interface. Revenue
instances will store each revenue transaction and allow you to define several special revenue properties (such as 'revenueType', 'productIdentifier', etc.) that are used in Amplitude's Revenue Analysis and Revenue LTV charts. You can also add event properties to revenue events via the eventProperties
field. These Revenue
instance objects are then passed into logRevenueV2
to send as revenue events to Amplitude. This allows us to automatically display data relevant to revenue in the platform. You can use this to track both in-app and non-in-app purchases. Calling logRevenueV2
will generate up to 2 different event types in the platform:
- '[Amplitude] Revenue': This event is logged for all revenue events, regardless of whether or not verification is turned on.
- '[Amplitude] Revenue (Verified/Unverified)': These revenue events will contain the actual '$revenue' property.
You cannot change the default names given to these client-side revenue events in the raw data but you do have the option to modify the display name. To learn more about tracking revenue, see our documentation here.
IMPORTANT NOTE: Amplitude currently does not support currency conversion. All revenue data should be normalized to your currency of choice, before being sent to Amplitude.
To use the Revenue
interface, you will first need to import the class:
import com.amplitude.api.Revenue;
Each time a user generates revenue, you will need to create an Revenue
object and fill out the revenue properties:
Revenue revenue = new Revenue().setProductId("com.company.productId").setPrice(3.99).setQuantity(3); Amplitude.getInstance().logRevenueV2(revenue);
Each revenue event has fields available, and each field has a corresponding set
method (for example, setProductId
, setQuantity
, etc.). This table describes the different fields:
Name | Type | Description | Default |
---|---|---|---|
(optional) |
String | An identifier for the product. We recommend something like the Google Play store Product ID. | null |
(required) |
int |
The quantity of products purchased. Note: revenue = |
1 |
(required) |
Double |
The price of the products purchased, and this can be negative. Note: revenue = |
null |
(optional) |
String | The type of revenue (e.g. tax, refund, income). | null |
(optional, required for revenue verification) |
String | This is required if you want to verify the revenue event. | null |
(optional, required for revenue verification) |
String | This is required if you want to verify the revenue event. | null |
(optional) |
JSONObject | A JSONObject of event properties to include in the revenue event. | null |
Note: The price can be negative, which may be useful for tracking revenue lost (e.g. refunds or costs). You can also set event properties on the revenue event just like you would with logEvent
by passing in a JSONObject of string key + value pairs. However, these event properties will only appear in the Event Segmentation chart and not in the revenue charts.
Revenue Verification
By default, revenue events recorded on the Android SDK will appear in Amplitude as '[Amplitude] Revenue (Unverified)' events. To enable revenue verification, copy your Google Play License Public Key into the Settings section of your project in Amplitude. You must put in a key for every single project in Amplitude where you want revenue to be verified.
After a successful purchase transaction, add the purchase data and receipt signature to the Revenue
object:
// for a purchase request onActivityResult String purchaseData = data.getStringExtra("PURCHASE_DATA"); String dataSignature = data.getStringExtra("DATA_SIGNATURE"); Revenue revenue = new Revenue().setProductId("com.company.productId").setQuantity(1); revenue.setPrice(3.99).setReceipt(purchaseData, dataSignature); Amplitude.getInstance().logRevenueV2(revenue);
You can see Google's In-App Billing documentation for details on how to retrieve the purchase data and the receipt signature.
Note: Google play integration is optional for revenue events.
Amazon Store Revenue Verification
For purchases on the Amazon store, you should copy your Amazon Developer Shared Secret into the Settings section of your project in Amplitude. After a successful purchase transaction, you should send the purchase token as the 'receipt' and the User ID as the 'receiptSignature':
// for a purchase request onActivityResult
String purchaseToken = purchaseResponse.getReceipt();
String userId = getUserIdResponse.getUserId();
Revenue revenue = new Revenue().setProductId("com.company.productId").setQuantity(1);
revenue.setPrice(3.99).setReceipt(purchaseToken, userId);
Amplitude.getInstance().logRevenueV2(revenue);
Backwards Compatibility
The existing logRevenue
methods still work but are deprecated. Fields such as revenueType
will be missing from events logged with the old methods, so the ability to segment on those revenue events will be limited in the Amplitude platform.
Opting User Out of Logging
To stop all event and session logging for a user, call setOptOut
:
Amplitude.getInstance().setOptOut(true);
Logging can be restarted by calling setOptOut
again and have it set to false
. No events will be logged during the period this is enabled.
Disable Automatic Tracking of User Properties
By default the Android SDK will track several user properties such as city and country. You can use the provided TrackingOptions
interface to customize and disable individual fields.
To use the TrackingOptions
interface, you will first need to import the class:
import com.amplitude.api.TrackingOptions;
Before initializing the SDK with your API Key, create a TrackingOptions
instance with your configuration and set it on the SDK instance:
TrackingOptions options = new TrackingOptions().disableCity().disableIpAddress().disableLatLng(); Amplitude.getInstance().setTrackingOptions(options);
Each field can be individually disabled and has a corresponding disable
method. This table describes the different methods:
IMPORTANT NOTE: These configurations will prevent default properties from being tracked on newly created projects, where data has not yet been sent. Please contact platform@amplitude.com if you would like default properties blocked (moving forward) on projects with existing data.
Method | Description |
---|---|
|
Disable tracking of the device's Google ADID. |
|
Disable tracking of the device's carrier. |
|
Disable tracking of the user's city. |
|
Disable tracking of the user's country. |
|
Disable tracking of the device brand. |
|
Disable tracking of the device model. |
|
Disable tracking of the user's DMA. |
|
Disable tracking of the user's IP address. |
|
Disable tracking of the device's language. |
|
Disable tracking of the user's current latitude and longitude coordinates. |
|
Disable tracking of the device's OS name. |
|
Disable tracking of the device's OS version. |
|
Disable tracking of the device's platform. |
|
Disable tracking of the user's region. |
|
Disable tracking of the app version the user is on for your app. |
Advanced
If you want to use the source files directly, you can download them here. To include them in your project, extract the files and then copy the five *.java files into your Android project.
Setting User Groups
Note: This feature is only available to Enterprise customers who have purchased the Accounts add-on.
Amplitude supports assigning users to groups and performing queries such as Count by Distinct on those groups. An example would be if you want to group your users based on what organization they are in by using an 'orgId'. You can designate Joe to be in 'orgId' '10' while Sue is in 'orgId' '15'. When performing a query in our Event Segmentation chart, you can then select "..performed by" 'orgId' to query the number of different organizations that have performed a specific event. As long as at least one member of that group has performed the specific event, that group will be included in the count.
When setting groups, you will need to define a groupType
and groupName
(s). In the above example, 'orgId' is the groupType
and the values '10' and '15' are groupName
(s). Another example of a groupType
could be 'sport' with groupName
(s) like 'tennis' and 'baseball'. You can use setGroup(groupType, groupName)
to designate which groups a user belongs to. Note: This will also set the 'groupType:groupName' as a user property. This will overwrite any existing groupName
value set for that user's groupType
as well as the corresponding user property value. groupType
is a string and groupName
can be either a string or an JSONArray of strings to indicate a user being in multiple groups (for example, if Joe is in 'orgId' '10' and '16', then the groupName
would be '[10, 16]'). It is important that you use JSONArrays to set multiple groups since primitive arrays do not serialize properly.
You can also call setGroup
multiple times with different groupType
s to track multiple types of groups. IMPORTANT NOTE: You are allowed to track up to five different groupType
s per project. For example, let's say Sue is in 'orgId:15' and she also plays 'sport:soccer'. Now, when querying, you can count by distinct on both 'orgId' and 'sport' (although as separate queries). Any additional groupType
s after the limit will be ignored from the count by distinct user interface, but they will still be saved as user properties. Here is an example:
Amplitude.getInstance().setGroup("orgId", "15"); Amplitude.getInstance().setGroup("sport", new JSONArray().put("tennis").put("soccer")); // list values
You can also use logEvent
with the groups argument to set event-level groups, meaning the group destination only applies for the specific event being logged and does not persist on the user (unless you explicitly set it with setGroup
). Here is an example:
JSONObjecteventProperties=newJSONObject().put("key", "value"); JSONObjectgroups=newJSONObject().put("orgId", 10); Amplitude.getInstance().logEvent("initialize_game", eventProperties, groups);
Setting Date Values
Amplitude compares dates as strings, so it is recommended to use the ISO 8601 format (YYYY-MM-DDTHH:mm:ss), which will allow you to perform date comparisons in the platform (e.g. '2016-01-31' > '2016-01-01'). This will also work for datetime values (e.g. '2017-08-07T10:09:08' > '2017-08-07T01:07:00').
Fine-Grained Location Tracking
Amplitude can access the Android location service (if possible) to add the specific coordinates (longitude and latitude) where an event is logged. This behavior is enabled by default but can be adjusted by calling the following methods after initializing:
Amplitude.getInstance().enableLocationListening();
Amplitude.getInstance().disableLocationListening();
Even if location listening is disabled, the events will still have the '[Amplitude] Country' property filled. This is because that property is retrieved from other sources (e.g. network or device locale).
Custom Device IDs
By default, Device IDs are randomly generated UUID. If you would like to use Google's Advertising ID as the Device ID, you can specify this by calling Amplitude.getInstance().useAdvertisingIdForDeviceId()
prior to initializing. You can retrieve the Device ID that Amplitude uses with Amplitude.getInstance().getDeviceId()
. This method can return null if a Device ID has not been generated yet.
If you have your own system for tracking Device IDs and would like to set a custom Device ID, you can do so with:
Amplitude.getInstance().setDeviceId("DEVICE_ID")
IMPORTANT NOTE: This is not recommended unless you really know what you are doing. Make sure the Device ID you set is sufficiently unique to prevent conflicts with other devices in our system. We recommend something like a UUID (we use UUID.randomUUID().toString()
).
SSL Pinning
The SDK includes support for SSL pinning, but it is undocumented and recommended against unless you have a specific need. Please contact Amplitude support before you ship any products with SSL pinning enabled so that we are aware and can provide documentation and implementation help.
Logging
You can disable all logging done in the SDK by calling Amplitude.getInstance().enableLogging(false). By default, the logging level is Log.INFO, meaning info messages, errors, and asserts are logged but verbose and debug messages are not. You can change the logging level. For example, to enable debug messages you can do:
Amplitude.getInstance().setLogLevel(log.DEBUG)
Push Notification Events
Push notification events should not be sent client-side via the Android SDK because a user must open the app to initialize the Amplitude SDK in order for the SDK to send the event. Therefore, if push notification events are tracked client-side then there can be data delays as the push notification event will not be sent to Amplitude's servers until the next time the user opens the app.
You can use our mobile marketing automation partners or our HTTP API to send push notification events to Amplitude.
COPPA (Children's Online Privacy Protection Act) Controls
Now you can enable or disable COPPA (Children's Online Privacy Protection Act) restrictions on ADID, city, IP address and location tracking.
To enable COPPA control, please call:
AmplitudeClient#enableCoppaControl()
To disable COPPA control, please call:
AmplitudeClient#disableCoppaControl()