Android Acquisition Cost Integration
Magify supports acquisition cost data provided by Adjust and AppsFlyer. This information is included in the Magify user context and can be used for campaign targeting and acquisition performance analysis.
The integration is asynchronous: Magify does not wait for attribution data before starting. The first context request is sent immediately, and the context is refreshed when cost data becomes available.
How it works
During application startup:
- Initialize Magify normally.
- Call
initialSetup()without waiting for attribution. - The first
getContextrequest is sent with empty acquisition cost fields. - Request or receive attribution data asynchronously.
- Pass the cost data to Magify.
- Magify automatically sends a follow-up
getContextrequest.
You do not need to call magify.update() after passing acquisition cost data.
Magify sends the following fields:
Supported cost models
Magify supports the following models:
cpi— cost per installcpc— cost per clickcpm— cost per millecpa— cost per action
Model values are case-insensitive and normalized to lowercase.
If the model is missing or unsupported, all four acquisition cost fields are omitted.
Adjust integration
Start Magify without waiting for Adjust
Do not delay Magify initialization while waiting for attribution:
val magify = Magify.createInstance(application, magifyConfig)
magify.initSdk {
// Magify local initialization completed
}
magify.initialSetup()
The first context request is sent immediately without acquisition cost.
Request attribution asynchronously
Request Adjust attribution and pass its cost fields to Magify when the result becomes available:
Adjust.getAttribution { attribution ->
magify.updateAdjustCost(
costAmount = attribution?.costAmount,
costType = attribution?.costType,
costCurrency = attribution?.costCurrency
)
}
This operation does not block application startup. Magify automatically refreshes the context when the received cost differs from the currently stored value.
Adjust parameters
Example:
magify.updateAdjustCost(
costAmount = 0.0035,
costType = "cpi",
costCurrency = "USD"
)
Adjust cost values are converted to plain decimal strings without scientific notation or unnecessary trailing zeros:
This ensures that small values such as 0.0035 are not sent as "3.5E-3".
AppsFlyer integration
Pass the AppsFlyer cost fields to Magify when conversion data becomes available:
override fun onConversionDataSuccess(conversionData: Map<String, Any>) {
magify.updateAppsFlyerCost(
costCentsUsd = conversionData["cost_cents_USD"]
?.toString()
?.toLongOrNull(),
costValue = conversionData["af_cost_value"]?.toString(),
costModel = conversionData["af_cost_model"]?.toString(),
costCurrency = conversionData["af_cost_currency"]?.toString()
)
}
Do not wait for AppsFlyer conversion data before calling magify.initialSetup().
AppsFlyer parameters
Cost source priority
Magify applies the following priority:
cost_cents_USDaf_cost_value
Using cost_cents_USD
When cost_cents_USD is available:
- It has priority over
af_cost_value. - The value is converted from cents to US dollars.
- The result is formatted without unnecessary trailing zeros.
- The currency is always set to
USD. af_cost_valueandaf_cost_currencyare ignored.
Example:
magify.updateAppsFlyerCost(
costCentsUsd = 50L,
costValue = "99.99",
costModel = "cpm",
costCurrency = "EUR"
)
The resulting data is:
acquisition_cost_value = "0.5"
acquisition_cost_currency = "USD"
acquisition_cost_model = "cpm"
mmp = "appsflyer"
Conversion examples:
Using af_cost_value
When cost_cents_USD is unavailable, Magify uses af_cost_value.
Before sending the value, Magify replaces every comma with a period. The remaining string representation is preserved.
Example:
magify.updateAppsFlyerCost(
costCentsUsd = null,
costValue = "10,2300",
costModel = "cpa",
costCurrency = "gbp"
)
The resulting data is:
acquisition_cost_value = "10.2300"
acquisition_cost_currency = "GBP"
acquisition_cost_model = "cpa"
mmp = "appsflyer"
Normalization examples:
Applications should pass the original AppsFlyer value to Magify and should not convert it from cents. The cents-to-dollars conversion applies only to cost_cents_USD.
Validation rules
A valid acquisition cost must contain:
- A non-negative cost value, including zero.
- One of the supported cost models.
- A currency, or Magify will use
USDby default.
The complete acquisition cost quartet is cleared when:
- The selected cost value is negative.
- The cost value is missing.
- The cost model is missing.
- The model is not
cpi,cpc,cpm, orcpa. - An Adjust value is
NaNor infinite.
If cost_cents_USD is present but negative, Magify clears the entire quartet. It does not fall back to af_cost_value.
Magify never sends a partially valid quartet. If validation fails, all four fields are omitted:
acquisition_cost_value = null
acquisition_cost_currency = null
acquisition_cost_model = null
mmp = null
Currency codes are trimmed and normalized to uppercase. Missing or blank currency values default to USD.
Context refresh behavior
The first getContext request always starts immediately with empty cost fields. Attribution is not required to start Magify.
When cost data is received or changed:
- Magify stores the latest valid value.
- A new
getContextrequest is triggered automatically. - If a request is already running, Magify waits for it to finish and sends one follow-up request with the latest value.
- Repeatedly passing the same normalized value does not trigger additional requests.
Acquisition cost is kept in memory. Pass it to Magify whenever it becomes available after each application start.