Skip to main content

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:

  1. Read the current attribution with AdTrace.getAttribution().
  2. Run code when attribution changes with setOnAttributionChangedListener.
tip

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.

PropertyTypeDescription
trackerTokenStringToken of the tracker the device is currently attributed to.
trackerNameStringName of the tracker the device is currently attributed to.
networkStringNetwork the device is currently attributed to.
campaignStringCampaign the device is currently attributed to.
adgroupStringAd group the device is currently attributed to.
creativeStringCreative the device is currently attributed to.
clickLabelStringClick label tagged on the install.
adidStringUnique Adtrace device identifier.
costTypeStringCampaign pricing model (for example cpi). Requires cost data in attribution.
costAmountDoubleCost of the install. Requires cost data in attribution.
costCurrencyStringISO 4217 currency code for the cost. Requires cost data in attribution.
tip

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.

Important

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

AdTraceAttribution 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)
ParameterTypeDescription
listenerOnAttributionChangedListenerCalled when attribution data changes. Receives an AdTraceAttribution object.
Important

Call setOnAttributionChangedListener before you initialize the SDK with AdTrace.onCreate().

Example

config.setOnAttributionChangedListener(new OnAttributionChangedListener() {
@Override
public void onAttributionChanged(AdTraceAttribution attribution) {
// Use attribution.trackerToken, attribution.campaign, and so on.
}
});

See Configuration for how to create the AdTraceConfig instance.