New: Video Guide
Watch this video for a detailed view of the integration process. We recommend that you use both the video and the written guide below.
Before You Begin: SDK Prerequisites
Follow the steps in Integrating a Singular SDK: Planning and Prerequisites.
These steps are prerequisites for any Singular SDK integration.
1. Adding the SDK to Your Project
1.1 Adding the SDK Using Gradle
Note: Starting with Gradle 7, Android suggests using centralized repository declarations in settings.gradle over project or module level build.gradle declarations.
-
Add the Singular SDK repository to the settings.gradle file:
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven{ url 'https://maven.singular.net/' } } }
OR in older Gradle versions, Add the Singular SDK repository to the project/build.gradle file:
repositories { mavenCentral() maven { url 'https://maven.singular.net/' } }
-
Add the Singular library to the dependencies list in app/build.gradle:
dependencies { ... implementation 'com.google.android.gms:play-services:6.5.87' implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.singular.sdk:singular_sdk:12.6.1' ... }
Additionally, add the following to support the Samsung Galaxy Store's install referrer if your app is distributed through the Samsung Galaxy Store:
dependencies { ... implementation 'store.galaxy.samsung.installreferrer:samsung_galaxystore_install_referrer:4.0.0' ... }
-
If you have disabled transitive dependencies for the Singular SDK, add the following to your app/build.gradle:
dependencies { ... implementation 'com.android.installreferrer:installreferrer:2.2' implementation 'com.google.android.gms:play-services-appset:16.0.0' ... }
-
If your app doesn't implement Google Play Services API 17.0.0 or higher, add the following dependency to the app/build.gradle file:
dependencies { ... implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0+' ... }
Note: Gradle 1.x-2.x users should use "compile" instead of "implementation" to add dependencies.
1.2. Adding the SDK Without Gradle
- Download the SDK from the link at the top of the page.
- Unzip the SDK package and add Singular.aar into your Android project's libs directory. If it doesn't exist, create a directory called libs in your project folder (usually at <project>/app/libs).
Add our maven repository to your project's pom.xml:
<project ...>
<repositories>
<repository>
<id>singular.net</id>
<url>http://maven.singular.net/</url>
</repository>
</repositories>
</project>
Add the dependency:
<dependency>
<groupId>com.singular.sdk</groupId>
<artifactId>singular_sdk</artifactId>
<version>12.5.6</version>
</dependency>
You can use the Eclipse AAR plugin: gradle-eclipse-aar-plugin
If you don't want to use the plugin, follow these steps:
- Unzip singular_sdk-12.6.1.aar.
- Rename classes.jar to singular_sdk-12.6.1.jar (this is the main SDK jar).
- Add the 'com.android.installreferrer:installreferrer:2.2' library to your project in any way you prefer.
- Copy the BIND_GET_INSTALL_REFERRER_SERVICE permission from the AndroidManifest.xml contained in the AAR to your AndroidManifest.xml
- copy the CHECK_LICENSE permissions from the AndroidManifest.xml contained in the AAR to your AndroidManifest.xml
Add the following lines of code to your proguard.config file:
-keep class com.singular.sdk.** { *; }
-keep public class com.android.installreferrer.** { *; }
# Uncomment this line in case your are calling the 'revenue' function using the Google billing library
#-keep public class com.android.billingclient.** { *; }
1.3. Adding Required Permissions
Add these permissions under the <manifest> tag in your AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="BIND_GET_INSTALL_REFERRER_SERVICE" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
Note: If your app build is targeting Android 12/API level 31 or higher, add permissions to access the Google Advertising ID:
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
Do not add this permission if you're integrating the Kids SDK.
Additionally add the following to support Samsung Galaxy Store's install referrer if your app is distributed through the Samsung Galaxy Store and targets Android 11 or higher:
<queries>
<package android:name="com.sec.android.app.samsungapps" />
</queries>
2. Setting Up a Basic SDK Integration
Note: Remember to remain compliant with the various privacy laws enacted in regions where you are doing business, including GDPR, CCPA, and COPPA, when implementing the Singular SDKs. For more information, see SDK Opt-In and Opt-Out Practices.
2.1. Importing the Singular Library
To import the Singular library, add the following import to your MainActivity file:
import com.singular.sdk.*;
import com.singular.sdk.*
2.2. Constructing a Configuration Object
Before initializing the SDK, you have to create a SingularConfig object. This object will contain the following:
- Your SDK Key and SDK Secret (to retrieve them, log into your Singular account and go to DEVELOPER TOOLS > SDK Integration > SDK Keys).
- Optionally, any SDK preferences you may want to set.
- META Install Referrer Attribution Support
Required SDK configuration to enable "Meta Install Referrer" attribution:
- Provide your Facebook App Id in the Singular Configuration Object.
// To enable META Install Referrer config.withFacebookAppId("INSERT YOUR FACEBOOK APP ID HERE");
- Provide your Facebook App Id in the Singular Configuration Object.
The following code example creates a configuration object and sets the common configuration options before initializing the Singular SDK.
The following sections give more details about these options and how you can customize them.
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Create a configuration object
SingularConfig config = new SingularConfig("SDK KEY", "SDK SECRET");
// Set up a deep links handler
config.withSingularLink(
getIntent(),
new SingularLinkHandler() {
@Override
public void onResolved(SingularLinkParams params) {
String deeplink = params.getDeeplink();
String passthrough = params.getPassthrough();
boolean isDeferred = params.isDeferred();
// Add deep link handling code here
}
}
);
Singular.init(context, config);
...
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Create a configuration object
val config = SingularConfig("SDK KEY", "SDK SECRET")
// Set up a deep links handler
config.withSingularLink(
intent
) { params ->
val deeplink = params.deeplink
val passthrough = params.passthrough
val isDeferred = params.isDeferred
// Add deep link handling code here
}
Singular.init(this, config)
...
}
The table below lists all the available ".with" methods for the SingularConfig object to add options and features to your app.
You will find details about each feature in the sections below or under Advanced Options.
Method |
Description |
.withFacebookAppId(String facebookAppID) |
Configure the Facebook App ID. Required for "Meta Install Referrer" attribution. |
.withCustomUserId(String customId) |
Send the user ID to Singular. |
.withSingularLink(getIntent(), SingularLinkHandler handler) |
Enable deep linking with Singular Links. |
.withDDLTimeoutInSec (long timeout) |
Set the length of time Singular searches for a deferred deep link when the app is first opened. |
.withDDLHandler (DeferredDeepLinkHandler handler) |
Enable deep linking with legacy tracking links (instead of the newer Singular Links). |
.withOpenURI (URI openURI) |
Fetch the URI from the intent (to process deep links if the app is opened through a link that doesn't originate from Singular). |
.withGlobalProperty(String key, String value, boolean overrideExisting) |
Set a global property to a given value. The key and value will be sent to Singular with any event/session sent from the app. |
.withSessionTimeoutInSec (long timeout) |
Set the session timeout. |
.withFCMDeviceToken(String token) |
Sets the FCM token to be sent on the first session. |
.withLoggingEnabled () |
Enable logging. |
.withLogLevel (int level) |
Configure the logging level (default is Log.ERROR). |
2.3. Adding Deep Linking Support
Deep links are links that lead to specific content inside an app. When a user clicks a deep link on a device with the app installed, the app opens and shows a specific product or experience. Singular tracking links can include deep linking as well as deferred deep linking (see our Deep Linking FAQ and the Singular Links FAQ for more information).
Enabling Deep Links Using Singular Links
To enable deep links for your app, see Singular Links Prerequisites.
Adding a Deep Linking Intent Filter
Add an intent filter like the following to your AndroidManifest.xml to enable deep link support in an activity. If you have more than one activity that should be opened through a deep link, do this for each activity.
Note: The Intent should NOT be configured with a 'android:host' value. If a 'android:host' value must be used: be sure to include the host value in the Singular Apps page configuration for the App scheme, and use the same 'scheme://host' value for all Singular deeplinks.
<activity>
<intent-filter>
<data android:scheme="singular-example" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Handling Deep Links
The Singular SDK provides a handler mechanism to read the details of the tracking link that led to the app being opened. A sample handler is included above in the sample code for Constructing a Configuration Object.
Note: The SingularLinkHandler is called only if the app was opened through a Singular Link (see the Singular Links FAQ). Other types of app links will only trigger if the domain is included in supportedDomains when you create the Singular Config object. See "Handling Non-Singular Deep Links" for more information
Modifying the Deferred Deep Link Timeout
By default, when an app sends the first session to Singular from a certain device, the Singular server looks in its records to see if there is a deferred deep link that matches that device (see What are deferred deep links?). If a deferred deep link is found, it is sent back to the app to process. But if no deferred deep link is found within 60 seconds, the server stops searching.
You can modify the timeout value by calling withDDLTimeoutInSec when you create the SingularConfig object. The example below changes the timeout to 30 seconds:
SingularConfig config = new SingularConfig("SDK KEY", "SDK SECRET");
...
config.withDDLTimeoutInSec(30);
...
Singular.init(context, config);
Handling Non-Singular Deep Links
The Singular SDK supports non-Singular-served deep links. This is required to measure attribution for partners such as Google Ads.
Starting with Android SDK version 12.1.1, non-Singular Universal Links are supported by default. No action is needed on your part to support third-party links if you have the new version of the SDK.
To support these deep links, provide a list of supported Android app links in supportedDomains when you create your SingularConfig object:
SingularConfig config = new SingularConfig("SDK KEY", "SDK SECRET");
// supportedDomains
List<String> supportedDomains = Arrays.asList("subdomain.mywebsite.com", "subdomain.myotherwebsite.com");
config.withSingularLink(
getIntent(),
new SingularLinkHandler() {
@Override
public void onResolved(SingularLinkParams params) {
// handle callback
}
},
supportedDomains
);
2.4. Initializing Singular
The Singular SDK should be initialized every time your app is opened. This is a prerequisite to all Singular attribution functionality, and it also sends a new user session to Singular (sessions are used to calculate user retention).
To initialize Singular, use the following code:
Singular.init(context, config);
Parameter | Description |
Context context | From the application class, you can pass this or getApplicationContext() as the context. To get the application context from inside an activity, call currentActivity.getApplicationContext(). |
SingularConfig config | The SingularConfig object you created in previous steps. |
The init method can be called at every point in the app but must get called before any event is reported. We recommend calling init in the onCreate of the main activity as well as any activity that will be opened directly by a deep link.
Note: You have to initialize Singular inside any activity that will be opened by a deep link (see Implementing deep links). Therefore, we don't recommend initializing Singular in the application's onCreate. If Singular is initialized on the application level and then again inside an activity, it will cause duplicate sessions in the Singular database.
2.5. Sending the User ID to Singular (Optional)
You may send your internal User ID to Singular using a Singular SDK method.
Note: If you use Singular's Cross-Device solution, you must collect the User ID across all platforms.
- The User ID can be any identifier and should not expose PII (Personally Identifiable Information). For example, you should not use a User's email address, username, or phone number. Singular recommends using a hashed value unique only to your first-party data.
- The User ID value passed to Singular should also be the same internal User ID you capture across all platforms (Web/Mobile/PC/Console/Offline).
- Singular will include the User ID in user-level exports, ETL, and Internal BI postbacks (if configured). The User ID is first-party data, and Singular does not share it with other parties.
- The User ID value, when set with the Singular SDK Method, will persist until it is unset using the unsetCustomUserId method or until the app is uninstalled. Closing or restarting the app does not unset the User ID.
To set the User ID, use the setCustomUserId method. To unset it (for example, if the User "logs out" of the account), call unsetCustomUserId.
Note: If multiple Users use a single device, we recommend implementing a logout flow to set and unset the User ID for each login and logout.
If you already know the user ID when the app opens, call setCustomUserId before initializing the Singular SDK. This way, Singular can have the User ID from the first Session. However, the User ID is typically unavailable until the User registers or performs a login. In that case, call setCustomUserId after the registration flow is complete.
Singular.setCustomUserID Method | |
---|---|
Description | Send the user ID to Singular. |
Signature | public void setCustomUserId(string customUserId) |
Usage Example |
|
Singular.unsetCustomUserID Method | |
Description | Unset the user ID that has been sent to Singular. |
Signature | public void unsetCustomUserId() |
Usage Example |
|
Important: This advanced Enterprise feature is only available in exceptional cases. Please consult with one of Singular’s Solution Engineers before implementing it.
Singular can receive additional mobile event tracking data via a server-to-server integration. To utilize this feature, you must map the User ID to Singular’s Mobile Device tracking identifier.
Note: Call this method as soon as possible after initializing the Singular SDK or once you have the User ID.
Singular.setDeviceCustomUserId Method | |
---|---|
Description | Sets the Custom User Id the same as login and maps it to Singular’s tracking identifier. |
Signature | public void setDeviceCustomUserId(string customUserId) |
Usage Example |
|
2.6. Implementing Global Properties (Optional)
The Singular SDK lets you define additional custom properties to send to the Singular servers with every session and event sent from the app. These properties can represent any information you want about the user, the app mode or status, or anything else. Once you set these properties, they are available as dimensions in your reports and you can use them to break down your data.
For example, if you have a gaming app, you can define a property called "Level" and set it initially to "0". Any session and event sent from the app will be sent with "Level": "0". Once the user levels up you reset the property to "1" and so on. You can then get your reports, including sessions, event counts, and revenue data, broken down by user level.
- You can define up to 5 global properties.
- They persist between app runs (with the latest value you gave them) until you unset them or the user uninstalls the app.
- Each property name and value can be up to 200 characters long. If you pass a longer property name or value, it will be truncated to 200 characters.
- Global properties are accessible and available in user-level exports and postbacks. In the future, aggregate reporting support will be added. Let your Singular customer success manager know if you have any questions, or are interested in updates to global properties support!
Setting Global Properties through SingularConfig
You can use the withGlobalProperty method to set global properties through SingularConfig before initializing the SDK.
Note that since global properties and their values persist between app runs, the property that you are setting may already be set to a different value. Use the overrideExisting parameter to tell the SDK whether to override an existing property with the new value or not.
withGlobalProperty Method | |
---|---|
Description | Set a global property. |
Signature | withGlobalProperty(String key, String value, boolean overrideExisting) |
Usage Example |
|
Setting Global Properties After Initialization
Use the following methods to set, unset, and retrieve global properties at any time in the app's run.
Singular.setGlobalProperty Method | |
---|---|
Description |
Set a global property to a given value. Notes:
|
Signature | public static bool setGlobalProperty(String key, String value, boolean overrideExisting) |
Usage Example |
|
Singular.getGlobalProperties Method | |
Description | Retrieve all the global properties and their current values as a Map. |
Signature | public static Map<String, String> getGlobalProperties() |
Usage Example |
|
Singular.unsetGlobalProperty Method | |
Description | Remove a global property. |
Signature | public static void unsetGlobalProperty(String key) |
Usage Example |
|
Singular.clearGlobalProperties Method | |
Description | Remove all global properties. |
Signature | public static void clearGlobalProperties() |
Usage Example |
|
3. Tracking Events and Revenue
3.1. Tracking Events (Non Revenue)
Singular can collect data about in-app events to help analyze the performance of your campaigns and measure KPIs. For example, your organization may want to collect data about user logins, registrations, tutorial completions, or leveling up in a gaming app.
What are Standard Events and Attributes?
Singular supports a variety of standard events. These commonly used events are often supported by ad networks for reporting and optimization. Another advantage is that when you use standard event names, Singular recognizes them automatically and adds them to the Events list without you having to define them manually. We recommend using standard events whenever possible.
The list of events sent to Singular (with the accompanying attributes) should be compiled by the UA/marketing/business team based on your organization's marketing KPIs. The business team can follow the guide at How to Track In-App Events: Guide For Singular Attribution Customers.
With each event you track, you can pass various attributes. See the recommended standard attributes per event.
Sending Events
In your code, send events to Singular using the eventJSON or event methods (we recommend eventJSON for readability).
- For standard events, use the event's Android name as it appears in the list of standard events and attributes for the Android SDK, e.g., sngTutorialComplete. See the code examples below.
- If you send any custom events (events that your organization wants to measure that do not match any of Singular's standard events), use any string you like that complies with the limitations.
Singular.eventJSON Method | |
---|---|
Description | Report a user event to Singular with additional information in JSONObject format. |
Signature |
Singular.eventJSON(String name, JSONObject args)
Note: 'args' is a JSONObject containing one or more key-value pairs. The key is a string and the value can be any type that's allowed as a JSONObject value.
|
Usage Example |
|
Singular.event Method | |
Description | Report a user event to Singular with or without additional information. |
Signature |
Singular.event(String eventName) Note: 'args' is one or more key-value pairs (see the example below). The key is a string and the value can be any type that's allowed as a JSONObject value (i.e., JSONObject, JSONArray, String, Boolean, Integer, Long, Double or NULL). The 'args' list must contain an even number of elements or the event will be rejected by Singular. |
Usage Example |
|
Notes:
- We highly recommend passing event names and attributes in English to guarantee compatibility with third-party partners and analytics solutions if you plan to use them.
- Event names are limited to 32 ASCII characters. Strings in non-ASCII characters have to be under 32 bytes once converted to UTF-8.
- Attributes and values are limited to 500 ASCII characters.
3.2. Tracking Revenue
Singular captures revenue events from in-app purchases (IAP), subscriptions, and custom revenue to measure campaign performance and return on ad spend (ROAS). The revenue data becomes available through three key channels:
- Interactive reports in the Singular dashboard
- Detailed export logs and ETL data destinations for custom analysis
- Real-time postbacks to external platforms
This comprehensive revenue tracking enables data-driven decisions about marketing spend and campaign optimization while providing flexibility in how you consume and analyze the data.
Requirements
- If Custom Revenue Event Names are used the Custom Revenue Event Names are limited to 32 ASCII characters. For non-ASCII characters, the limit is 32 bytes once converted to UTF-8.
- Event attribute names and attribute values are limited to 500 ASCII characters.
-
Pass currency as a three-letter ISO 4217 currency code:
USD, EUR, INR
Best Practice
- Singular recommends passing events using Singular's standard event and attribute naming convention.
- If Custom Revenue Event Names are used they should be sent in English to improve compatibility with Ad Network postbacks.
- Revenue Events should only be sent to Singular when the Revenue Amount is greater than or less than 0.
Revenue Tracking Implementations
Non-Subscription In-App Purchase
To report revenue events to Singular, pass the Purchase object received from the Google Billing Library into the revenue or customRevenue SDK methods. This has two advantages:
- Singular gets all the details of the transaction, which enriches your Singular reports.
- Singular gets the transaction receipt from Google which can be used to validate the transaction in the context of fighting in-app fraud.
Notes:
- customRevenue allows you to pass a custom event name, so that you'll be able to view revenue in Singular reports broken down by the different types of revenue events.
- Any revenue reported in a different currency will be auto-converted to your organization's preferred currency, as set in your Singular account.
revenue Method
Send a revenue event to Singular with the Purchase object.
Signatures
Singular.revenue(String currency, double amount, Object purchase)
Usage Examples
Singular.revenue("USD", 5.50, purchase);
Singular.revenue("USD", 5.50, purchase)
customRevenue Method
Send a revenue event to Singular with a custom event name and the Purchase object.
Signatures
Singular.customRevenue(String eventName, String currency, double amount, Object purchase)
Usage Examples
Singular.customRevenue("MyCustomRevenue", "USD", 5.50, purchase);
Singular.customRevenue("MyCustomRevenue", "USD", 5.50, purchase)
Subscription Revenue
Tracking Subscriptions:
Singular enables you to track your subscriptions and renewals within your app, providing insights into user behavior and revenue generation. Review our comprehensive guide on how to implement subscription events using the Singular SDK. [Subscription Event Technical Implementation Guide]
Custom Revenue without Purchase Validation
While we strongly recommend reporting revenue events the way described above, you can also use revenue and customRevenue without passing the purchase object. Instead, you pass the currency and amount of the transaction, and optional product details.
The customRevenue method also lets you pass a custom event name.
Note that if you use these methods, Singular does not get the transaction receipt and cannot validate the transaction.
revenue Method
Send a revenue event to Singular with the revenue amount, currency, and optional details.
Signatures
Singular.revenue(String currency, double amount)
Singular.revenue(String currency, double amount, String productSKU, String productName, String productCategory, int productQuantity, double productPrice)
Singular.revenue(String currency, double amount, Map<String, Object> attributes)
Usage Examples
Without Product Details
Singular.revenue("USD", 5.50);
With Product Details
Singular.revenue("EUR", 5.00, "SKU1928375", "Reservation Fee", "Fee" , 1, 5.00);
With Product Details in an Attribute Map
Map<string, object="Object"> attributes = new HashMap<>();
attributes.put("product_id", "com.app.premium");
attributes.put("transaction_id", "T12345");
attributes.put("quantity", 1);
attributes.put("is_trial", false);
// Call the revenue method
Singular.revenue("USD", 9.99, attributes);
Without Product Details
Singular.revenue("USD", 5.50)
With Product Details
Singular.revenue("EUR", 5.00, "SKU1928375", "Reservation Fee", "Fee" , 1, 5.00)
With Product Details in an Attribute Map
val attributes = mutableMapOf<String, Any>().apply {
put("product_id", "com.app.premium")
put("transaction_id", "T12345")
put("quantity", 1)
put("is_trial", false)
}
// Call the revenue method
Singular.revenue("USD", 9.99, attributes)
customRevenue Method
Send custom revenue events to Singular by specifying the event name, revenue amount, currency code, and any additional transaction attributes. Singular processes these events to track in-app revenue.
Signatures
Singular.customRevenue(String eventName, String currency, double amount)
Singular.customRevenue(String eventName, String currency, double amount, String productSKU, String productName, String productCategory, int productQuantity, double productPrice)
Singular.customRevenue(String eventName, String currency, double amount, Map<String, Object> attributes)
Usage Examples
Without Product Details
Singular.customRevenue("MyCustomRevenue", "USD", 5.50);
With Product Details
Singular.customRevenue("MyCustomRevenue", "EUR", 5.00, "SKU1928375", "Reservation Fee", "Fee" , 1, 5.00);
With Product Details in an Attribute Map
Map<string, object="Object"> attributes = new HashMap<>();
attributes.put("product_id", "com.app.premium");
attributes.put("transaction_id", "T12345");
attributes.put("quantity", 1);
attributes.put("is_trial", false);
// Call the revenue method
Singular.customRevenue("MyCustomRevenue", "USD", 9.99, attributes);
Without Product Details
Singular.customRevenue("MyCustomRevenue", "USD", 5.50)
With Product Details
Singular.customRevenue("MyCustomRevenue", "EUR", 5.00, "SKU1928375", "Reservation Fee", "Fee" , 1, 5.00)
With Product Details in an Attribute Map
val attributes = mutableMapOf<String, Any>().apply {
put("product_id", "com.app.premium")
put("transaction_id", "T12345")
put("quantity", 1)
put("is_trial", false)
}
// Call the revenue method
Singular.customRevenue("MyCustomRevenue", "USD", 9.99, attributes)
3.3. Hybrid Event Tracking (Advanced)
Singular recommends sending all events and revenue through the Singular SDK integrated into your app. However, Singular can collect events and revenue from other sources.
Any event NOT sent from the Singular SDK must comply with Singular's Server-to-Server Event documentation requirements and provide the matching device identifier to correctly attribute an event.
Important:
Discrepancies will occur if device identifiers used on Server-to-Server event requests do not have a matching device identifier in Singular. Be aware of the following possibilities:
- If an event request is received "before" the Singular SDK has recorded the device identifier, from an App Session, then the event request will be considered the "first session" for the unknown device, and Singular will attribute the device as an organic attribution.
- If the Singular SDK did record a device identifier, but the Singular SDK identifier differs from the device identifier specified in the Server-to-Server Event request then the event will be attributed incorrectly.
Hybrid Event Tracking Guides
Singular can collect data about revenue from your Server to help analyze the performance and ROI of your campaigns.
Requirements:
- From an in-app Registration or Login Event, capture and pass the device identifiers and store this data with the User ID on your server. Because device identifiers may change for a user, be sure to update the identifiers when a user generates an app session. This guarantees the server-side event will be attributed to the correct device.
- Server-side events are platform specific and should only be sent with the device identifier matching the device platform (e.g., IDFA or IDFV for iOS devices).
- You can use the Singular Internal BI postback mechanism to push an event in real time to your internal endpoint so that you can update the data set on the server side. See the Internal BI Postback FAQ.
- Review the "Tracking Revenue" section in the Server-to-Server Integration guide for details.
Follow the links below for details on how to enable these partners.
4. Advanced Options
4.1. Creating Short Referrer Links
Note: This functionality is available in SDK version 12.1.1+. Once created, short links remain active for 30 days.
Use short links to transform long, parameter-filled Singular Links into shorter and more secure links that are convenient for sharing.
Typically, you will want to create short links dynamically so that your app's users can share them with friends to invite them to use the app.
To create a short link, you need:
- A Singular Link that leads to your app download (see the Singular Links FAQ).
- Any parameters you want to add to the link dynamically (see Tracking Link Parameters for the list of options).
- The name and ID of the referring user, if you want to be able to track new app installs back to the user who shared the link.
Use the createReferrerShortLink method to create a short link as in the example below.
// Create a JSON object to add parameters to the Singular Link (if they don't exist in the link URL yet)
JSONObject params = new JSONObject();
try {
params.put("channel","sms");
params.put("another parameter","parameter value");
} catch (JSONException e) {
e.printStackTrace();
}
Singular.createReferrerShortLink (
"https://sample.sng.link/D52wc/cuvk?pcn=test", // The original Singular Link URL
"Referrer Name",
"Referrer ID",
params,
new ShortLinkHandler() {
@Override
public void onSuccess(final String shortLinkURL) {
view.post(new Runnable() {
@Override
public void run() {
// Add your share logic here
}
});
}
@Override
public void onError(final String error) {
view.post(new Runnable() {
@Override
public void run() {
// Logic to retry/abort/modify the params passed to
// the function, based on the cause of the error
}
});
}
});
// Create a JSON object to add parameters to the Singular Link (if they don't exist in the link URL yet)
val params = JSONObject()
try {
params.put("channel", "sms")
params.put("another parameter", "parameter value")
} catch (e: JSONException) {
e.printStackTrace()
}
Singular.createReferrerShortLink(
"https://sample.sng.link/D52wc/cuvk?pcn=test", // The original Singular Link URL
"Referrer Name",
"Referrer ID",
params,
object : ShortLinkHandler {
override fun onSuccess(shortLinkURL: String) {
view.post(Runnable {
// Add your share logic here
})
}
override fun onError(error: String) {
view.post(Runnable {
// Logic to retry/abort/modify the params passed to
// the function, based on the cause of the error
})
}
})
Adding_Ad_Revenue_Attribution_Support
4.2. Adding Ad Revenue Attribution Support
Singular is integrated with mediation platforms such as Google AdMob, AppLovin, Unity LevelPlay (IronSource), and TradPlus for ad revenue attribution. Singular also supports other mediation platforms through our generic ad revenue SDK integration.
You can get ad revenue attribution data from your mediation platform by adding a code snippet to your Singular SDK integration. This also allows you to get ad revenue data for SKAdNetwork campaigns.
Getting user-level ad revenue from your mediation platform enables Singular to send attributed ad revenue back to media sources that can accept this data to run AdROAS campaigns.
See instructions and code snippets for SDK Implementation [HERE].
4.3. Uninstall Tracking
To enable uninstall tracking for your Android app, first configure the app in the Singular platform as detailed in Setting Up Uninstall Tracking. Then follow the instructions below.
Note: Google deprecated the GCM APIs in April 2018. Use Firebase Cloud Messaging (FCM) for uninstall tracking, as described below.
I. Integrate with FCM:
To track uninstalls, you can use the services of the Firebase Cloud Messaging (FCM) platform. If you are not already using FCM follow Google's instructions on how to Set up a Firebase Cloud Messaging client app on Android.
FCM Requirements ( source )
FCM clients require devices running Android 4.1 or higher that also have the Google Play Store app installed, or an emulator running Android 4.1 with Google APIs. Note that you are not limited to deploying your Android apps through the Google Play Store.
Users/devices who are not running on supported versions of Android will not be available for Singular uninstall tracking.
II. Update the AndroidManifest.xml File:
Update your AndroidManifest.xml file to add the necessary intent filter for your app (replace MyFirebaseMessagingService with your class that implements the Firebase Service):
<service android:name=".java.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
III. Register and Send the FCM Device Token:
Finally, set the FCM device token after your SingularConfig is initialized in OnCreate(), as follows:
Singular.setFCMDeviceToken(String fcmDeviceToken);
4.4. Collecting the Install Referrer on Older Devices
Note: Google is deprecating the install_referrer intent broadcast. See: Still Using InstallBroadcast? Switch to the Play Referrer API by March 1, 2020
The install referrer is Singular's most accurate tool to determine attribution, in addition to helping Singular detect and analyze fraud attempts. It is an identifier provided by the Google Play Store that points to the ad that the user clicked on before installing the app.
On devices that have the latest version of the Google Play Store, the Singular SDK collects the install referrer value automatically (since Singular is integrated with the latest Google Play Referrer API).
To collect the install referrer on older devices:
If you have an existing install referrer receiver:
Chances are your app already has a BroadcastReceiver that receives the INSTALL_REFERRER from Android.
If so, just go into the BroadcastReceiver's onReceive method and add the following line:
new SingularInstallReceiver().onReceive(context, intent);
For example, if your existing receiver is called MyCustomInstallReceiver, it should look as follows:
public class MyCustomInstallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Pass install referrer information on to Singular
new SingularInstallReceiver().onReceive(context, intent);
// ...
}
}
If there is no other install referrer receiver:
If you don't have any install referrer receiver in your app, you can let the Singular SDK register the only receiver simply by adding the following to your <application> tag in your manifest file:
<receiver android:exported="true" android:name="com.singular.sdk.SingularInstallReceiver">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
4.5. Managing Sessions
For Android API 14 (Ice Cream Sandwich) and above, the Singular SDK can handle session management automatically. If your app's minSdkVersion is 14 or higher, no additional configuration is required for session management.
Modifying the Session Timeout
By default, if the app runs in the background for 60 seconds or more before returning to the foreground, the SDK registers a new session.
To change the timeout value, use withSessionTimeoutInSec(<timeout in seconds>) in SingularConfig before initializing the SDK.
For example:
// Set the session timeout to 120 seconds
SingularConfig config = new SingularConfig("SDK KEY", "SDK SECRET")
.withSessionTimeoutInSec(120);
Manual Session Management
If your app's minSdkVersion is below 14, you need to manage sessions manually by calling the Singular's SDK two session-handling methods, onActivityPaused and onActivityResumed, from each of your activities.
Note: If you have a custom common base activity class from which all other activities are derived, you can place these calls to onActivityResumed and onActivityPaused in the common activity's "onResume and onPause methods.
Singular.onActivityResumed Method | |
---|---|
Description | Call this method inside the activity's onResume method to manage the Singular session. |
Signature | public static void onActivityResumed() |
Usage Example |
|
Singular.onActivityPaused Method | |
Description | Call this method inside the activity's onPause method to manage the Singular session. |
Signature | public static void onActivityPaused() |
Usage Example |
|
4.6. Using the JavaScript Interface
Singular provides a JavaScript interface that you can use in order to call Singular from within javaScript code in your app.
For example, if you set up the JavaScript interface, you can send events to Singular from JavaScript code as follows:
Event Example
SingularInterface.event('event');
SingularInterface.event('test',
JSON.stringify({"a1":"bar", "a2":"boo", "a3":"baz"}));
The interface supports the following SDK methods:
- setCustomUserID
- unsetCustomUserID
- event
- revenue
To enable the JavaScript interface, add the following lines of code to your main activity, where "myWebView" is the name of your webview.
SingularJSInterface singularJSInterfaceInstance = new SingularJSInterface(this);
singularJSInterfaceInstance.setWebViewId(R.id.webview);
myWebView.addjavascriptInterface(singularJSInterfaceInstance, "SingularInterface");
Notes:
- If you have more than one webview, do this for each one.
- We recommend placing the code in the onCreate method of your application.
Your onCreate method may look like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView myWebView = (WebView) this.findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setjavaScriptEnabled(true);
myWebView.loadUrl("file:///android_asset/index.html");
SingularConfig config = new SingularConfig("SDK KEY", "SDK SECRET");
Singular.init(this, config);
SingularJSInterface singularJSInterfaceInstance =
new SingularJSInterface(this);
singularJSInterfaceInstance.setWebViewId(R.id.webview);
myWebView.addjavascriptInterface(singularJSInterfaceInstance,
"SingularInterface");
}
4.7. Collecting the OAID (Open Advertising ID)
In countries that do not use Google Play, Android devices do not have a Google Advertising ID (GAID, also called AIFA in Singular). Instead, the devices may offer an identifier called OAID (Open Advertising Identifier) that can be used to track sessions and events coming from the device.
OAID is currently offered on devices by Huawei and by brands that belong to the Mobile Security Alliance (MSA).
For your app to collect the OAID, you first have to integrate the MSA SDK and Huawei OAID SDK. You need to integrate both SDKs to be able to collect the OAID on all the platforms that offer it.
Then, to tell the Singular SDK to use OAID for tracking, add a call to withOAIDCollection in the config object before initializing Singular.
SingularConfig config = new SingularConfig("SDK KEY","SDK SECRET")
.withOAIDCollection();
Singular.init(context, config);
The Singular SDK will automatically detect if the device has an OAID as well as which OAID SDK should be used to collect the identifier.
4.8. Collecting the IMEI Number
If your app is offered in countries that do not use Google Play, devices do not have a Google Advertising ID. In this case, you may want to collect the device IMEI (International Mobile Equipment Identity) instead.
Note: If you use Google Play Services, you should not collect the IMEI number because it's a violation of the Google Play service agreement.
To collect the IMEI number:
Add the android.permission.READ_PHONE_STATE permission to the app's AndroidManifest.xml file:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Add code like the following to fetch the device's IMEI number:
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
imei = telephonyManager.getImei();
} else {
imei = telephonyManager.getDeviceId();
}
To send the IMEI number to Singular, use one of the following methods:
Recommended: Set the IMEI number in SingularConfig using withIMEI before you initialize the Singular SDK, as in the following example. This makes the IMEI number available to Singular from the very first session.
SingularConfig config = new SingularConfig("SDK KEY","SDK SECRET")
.withIMEI("537769845792516");
Singular.init(context, config);
To set the IMEI number at any point in the code after the SDK initialization, call setIMEI.
Singular.setIMEI Method | |
---|---|
Description | Send the device's IMEI number to Singular. |
Signature | public void setIMEI(string IMEIString) |
Usage Example |
|
4.9. Complying with Data Privacy Laws
Singular provides privacy-safeguarding functionality to help you cooperate with any partners who may be complying with consumer privacy laws such as GDPR and CCPA (California Consumer Privacy Act). These partners want to be notified if the end-user has consented to share their private information.
If you have implemented a way to ask users for consent to share their information, use the limitDataSharing method to notify Singular of the user's choice:
Use Singular.limitDataSharing(false) to indicate that the user consented (opted in) to share their information.
Use Singular.limitDataSharing(true) if the user did not consent.
Singular uses LimitDataSharing in "User Privacy Postbacks" as well as passing this information on to partners who require it in order to comply with relevant regulations. See "User Privacy and Limit Data Sharing" for more information.
Note: The use of the method is optional, but there may be attribution information that the partner will share with Singular only if specifically notified that the user has opted in.
Singular.limitDataSharing Method | |
---|---|
Signature | Singular.limitDataSharing(boolean shouldLimitDataSharing) |
Description | Notify Singular of user consent (opt-in) for sharing private data. The Limit Data Sharing method gives you an option to control whether your app sends user data to third parties. This is useful if you want to restrict data sharing based on user preferences or privacy requirements. |
Usage Example |
|
Additional Methods for GDPR Compliance
The Singular SDK provides several methods to help you comply with GDPR policies and let Singular know about user consent or non-consent for tracking.
Singular.trackingOptIn Method | |
---|---|
Description | Notify Singular of user consent (opt-in) for tracking. The TrackingOptIn() method is used to send a "gdpr" event to Singular's servers. If you don't call this method, the app will continue tracking users as if they have given consent, but it won't specifically mark them as GDPR opt-in. If your app needs to comply with GDPR (General Data Protection Regulation), you should call this function to ensure that user consent is properly recorded. |
Usage Example |
|
Singular.stopAllTracking Method | |
Description |
Stop all tracking activities for this user on this app.
Note: Calling this method effectively disables the SDK, even after the app restarts (the state is persistent)! The only way to re-enable tracking is by calling resumeAllTracking().
|
Usage Example |
|
Singular.resumeAllTracking Method | |
Description | Resume tracking for this user on this app. |
Usage Example |
|
Singular.isAllTrackingStopped Method | |
Description | Check the tracking status for this user on this app. Returns true if tracking has been stopped using StopAllTracking() and not resumed. |
Usage Example |
|