Attribution
Implement these features to track installs from specific stores, monitor uninstalls, and handle deep links.
Differentiating Organic Installs by Store
If you publish your app on multiple stores (e.g., Cafe Bazaar, Google Play, Myket), you can differentiate your organic installs by their source. To do this, create separate builds for each store and configure the store name.
Method 1: Using AndroidManifest.xml (Recommended)
Place the store name in your AndroidManifest.xml file.
<manifest>
<application>
<!-- Add the following lines and replace with the store name -->
<meta-data
android:name="metrix_storeName"
android:value="YOUR_STORE_NAME" />
</application>
</manifest>- Replace
YOUR_STORE_NAMEwith the store’s name (e.g.,GooglePlay,CafeBazaar, orMyket). For data consistency, use the exact same name for a specific store across all versions.
(Note: Do not change the metrix_storeName key.)
- In the Metrix panel, this value appears as the campaign name for the
organictracker, allowing you to segment organic installs by store.
Method 2: Programmatically
Alternatively, you can set the store name in your code.
MetrixAttribution.setStore("GooglePlay");Uninstall Tracking
Metrix uses silent push notifications via Firebase Cloud Messaging (FCM) to track app uninstalls.
Setup Steps:
- Enter Firebase Credentials: In your Metrix panel, go to your app settings and select the Uninstall Config tab. Upload your Firebase Service Account Data file. You can generate this file in your Firebase console under Project Settings → Service Accounts → Generate New Private Key.

- Activate Tracking: After saving your credentials, enable uninstall tracking by turning on the toggle in the panel.
- Send Push Token: In your app, after initializing FCM and receiving the push token, send it to Metrix.
MetrixAttribution.setPushToken("YOUR_FCM_PUSH_TOKEN");Setting a Default Tracker
Assign a default tracker for users who install your app directly from an APK file (i.e., not from a click). This is useful for tracking installs from direct distribution channels.
Important: Never publish an app to a store with a default tracker set. Doing so will cause all your organic installs from that store to be incorrectly attributed to the default tracker.
Method 1: Using AndroidManifest.xml
<manifest>
<application>
<meta-data
android:name="metrix_trackerToken"
android:value="YOUR_TRACKER_TOKEN" />
</application>
</manifest>Method 2: Programmatically
MetrixAttribution.setDefaultTracker("YOUR_TRACKER_TOKEN");Deep Linking
If you use trackers with deep linking enabled, you can receive the deep link URL and its content. The device responds based on whether the application is installed (standard scenario) or not installed (deferred scenario). If your application is installed, the deep link information is sent to your application.
The Android platform does not automatically support the deferred scenario. In this case, Metrix has its own specific scenario to deliver deep link information to the application.
Standard Scenario (App is Installed)
If your users have your application installed and you want a specific page of your application to open after clicking on a deep link, you must first choose a unique scheme name.
Then, you need to assign it to the activity you intend to launch when the deep link is clicked. To do this, go to the AndroidManifest.xml file and add the intent-filter section to the desired activity, along with your chosen scheme name.
As shown below:
-
Configure
AndroidManifest.xml: Add anintent-filterto the target activity with a unique URL scheme.<activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="metrixExample" /> </intent-filter> </activity> -
Handle the Intent: Access the deep link data in your activity’s
onCreateandonNewIntentmethods.@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); Uri data = intent.getData(); // Handle deep link data... } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); Uri data = intent.getData(); // Handle deep link data if the activity is already running... }
Deferred Scenario (App is Not Installed)
If a user without your app clicks the link, they are sent to the app store. After they install and open the app for the first time, Metrix delivers the deep link data.
Set a listener to receive the deferred deep link.
Native
MetrixAttribution.setOnDeeplinkResponseListener(new OnDeeplinkResponseListener() {
@Override
public boolean launchReceivedDeeplink(Uri deeplink) {
// Your custom logic to handle the deeplink
// ...
// Return true to let Metrix automatically open the link (standard scenario)
// Return false if you have handled it completely yourself
if (shouldMetrixSdkLaunchTheDeeplink(deeplink)) {
return true;
} else {
return false;
}
}
});Note: Deferred deep linking is currently supported for installs from Google Play and Cafe Bazaar.
Retrieving Campaign Information
Listen for attribution changes to get details about the campaign that drove the install.
Native
MetrixAttribution.setOnAttributionChangedListener(new OnAttributionChangeListener() {
@Override
public void onAttributionChanged(AttributionData attributionData) {
// Use attributionData object here
}
});AttributionData Fields:
The AttributionData object contains the following fields:
Native
attributionData.getAcquisitionAd() // Ad name
attributionData.getAcquisitionAdSet() // Ad group
attributionData.getAcquisitionCampaign() // Campaign name
attributionData.getAcquisitionSource() // Ad network
attributionData.getAcquisitionSubId() // Ad sub-group
attributionData.getAttributionStatus() // Attribution statusAttribution Status Values:
ATTRIBUTED: Successfully attributed to a campaign.NOT_ATTRIBUTED_YET: Attribution is in progress.ATTRIBUTION_NOT_NEEDED: User is organic.UNKNOWN: Status is unknown.
Retrieving Metrix Device ID
Get the unique device identifier generated by Metrix. This ID becomes available once the device is identified by Metrix servers.
Native
MetrixAttribution.setUserIdListener(new UserIdListener() {
@Override
public void onUserIdReceived(String metrixUserId) {
// Your logic with the Metrix User ID
}
});Session Tracking
Every user interaction occurs within a session. The Metrix SDK automatically collects session information, including duration and activity, giving you insight into user engagement.
Session Identifier
Retrieve the unique identifier for the current user session. This is useful for correlating data with other services like crash reporters or analytics platforms.
Native
MetrixAnalytics.setSessionIdListener(new SessionIdListener() {
@Override
public void onSessionIdChanged(String sessionId) {
// e.g., Crashlytics.setString("metrix_session_id", sessionId);
}
});Session Number
Track the user’s cumulative session count to understand their journey over time.
Native
MetrixAnalytics.setSessionNumberListener(new SessionNumberListener() {
@Override
public void onSessionNumberChanged(int sessionNumber) {
// your logic
}
});Practical Use Cases and Examples
Onboarding and Retention
Use the session number to tailor the user experience.
MetrixAnalytics.setSessionNumberListener(sessionNumber -> {
if (sessionNumber == 1) {
// This is the user's first session
showOnboardingTutorial();
MetrixAnalytics.newEvent("first_session_started");
} else if (sessionNumber == 2) {
// User returned for a second session
MetrixAnalytics.newEvent("user_retained_session_2");
} else if (sessionNumber >= 10) {
// Highly engaged user
offerLoyaltyReward();
MetrixAnalytics.newEvent("user_highly_engaged");
}
});Correlating with Crash Reports
Include the session ID in your crash reports to easily debug issues related to a specific session.
MetrixAnalytics.setSessionIdListener(sessionId -> {
// Example with Firebase Crashlytics
FirebaseCrashlytics.getInstance().setCustomKey("metrix_session_id", sessionId);
});