Get attribution information
When a user interacts with an Adtrace tracker link or a deep link, their attribution information can update. Attribution details are represented by the AdTraceAttribution class.
Use this guide to:
- Read the current attribution with
AdTrace.getAttribution(). - Run code when attribution changes with
setOnAttributionChangedListener.
AdTrace.getAttribution() is available in Adtrace SDK v2.3+.
AdTraceAttribution properties
The AdTraceAttribution class holds the current attribution status for the device. Any value that is not set for the user is returned as null.
| Property | Type | Description |
|---|---|---|
trackerToken | String | Token of the tracker the device is currently attributed to. |
trackerName | String | Name of the tracker the device is currently attributed to. |
network | String | Network the device is currently attributed to. |
campaign | String | Campaign the device is currently attributed to. |
adgroup | String | Ad group the device is currently attributed to. |
creative | String | Creative the device is currently attributed to. |
clickLabel | String | Click label tagged on the install. |
adid | String | Unique Adtrace device identifier. |
costType | String | Campaign pricing model (for example cpi). Requires cost data in attribution. |
costAmount | Double | Cost of the install. Requires cost data in attribution. |
costCurrency | String | ISO 4217 currency code for the cost. Requires cost data in attribution. |
Cost fields are only available when you enable them with setNeedsCost(true) on AdTraceConfig before AdTrace.onCreate(). If cost is not enabled or not part of the attribution, these fields are null.
Get current attribution information
Access the user's current attribution whenever you need it by calling getAttribution on AdTrace.
Method signature
public static AdTraceAttribution getAttribution()
When a user installs your app, Adtrace attributes the install to a campaign. Call AdTrace.getAttribution() to read the current attribution as an AdTraceAttribution object.
Current attribution is only available after Adtrace tracks the app install and the attribution callback has been triggered. You cannot access attribution before the SDK is initialized and that callback has run.
Example
- Java
- Kotlin
- Javascript
AdTraceAttribution attribution = AdTrace.getAttribution();
val attribution = AdTrace.getAttribution()
let attribution = AdTrace.getAttribution();
Then read fields from the returned object (for example attribution.trackerToken, attribution.campaign).
Trigger a function when attribution changes
Like the attribution callback flow, the SDK can notify you whenever attribution information changes. Register a listener on your AdTraceConfig instance before AdTrace.onCreate().
Attribution can come from different sources, so this information is not available synchronously at init time. The listener runs after the SDK receives updated attribution data.
Method signature
public void setOnAttributionChangedListener(OnAttributionChangedListener listener)
| Parameter | Type | Description |
|---|---|---|
listener | OnAttributionChangedListener | Called when attribution data changes. Receives an AdTraceAttribution object. |
Call setOnAttributionChangedListener before you initialize the SDK with AdTrace.onCreate().
Example
- Java
- Kotlin
- Javascript
config.setOnAttributionChangedListener(new OnAttributionChangedListener() {
@Override
public void onAttributionChanged(AdTraceAttribution attribution) {
// Use attribution.trackerToken, attribution.campaign, and so on.
}
});
config.setOnAttributionChangedListener { attribution ->
// Use attribution.trackerToken, attribution.campaign, and so on.
}
function attributionCallback(attribution) {
// Use attribution.trackerToken, attribution.campaign, and so on.
}
config.setAttributionCallback(attributionCallback);
See Configuration for how to create the AdTraceConfig instance.