Importing attributions on iOS
Note
Attribution import is available starting with AppMetrica SDK 5.2.0 for iOS.
To set up import, call the attribution retrieval method on the client, then call the attribution sending method reportExternalAttribution
of the AppMetrica / AMAAppMetrica class in the АppMetrica SDK.
AppsFlyer
To integrate AppsFlyer for attribution into your project, make sure you added support for AppDelegate to SwiftUI projects.
- Initialize AppsFlyer in a regular way.
- Use the method
onConversionDataSuccess
for attribution retrieval. - Set up the sending of attribution data (the
reportExternalAttribution
method) in the AppMetrica SDK.
import AppMetricaCore
import AppsFlyerLib
extension AppDelegate: AppsFlyerLibDelegate {
func onConversionDataSuccess(_ installData: [AnyHashable: Any]) {
AppMetrica.reportExternalAttribution(installData, from: .appsflyer)
}
}
#import <AppMetricaCore/AppMetricaCore.h>
#import <AppsFlyerLib/AppsFlyerLib.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (void)onConversionDataSuccess:(NSDictionary *)installData {
[AMAAppMetrica reportExternalAttribution:installData
source:kAMAAttributionSourceAppsflyer
onFailure:nil];
}
@end
Adjust
To integrate Adjust for attribution into your project, make sure you added support for AppDelegate to SwiftUI projects.
- Initialize Adjust in a regular way.
- Adjust uses the ADJAttribution object for attribution data processing. Convert it to
Dictionary
with thedictionary()
method and pass it to AppMetrica. - Set up the sending of attribution data (the
reportExternalAttribution
method) in the AppMetrica SDK.
import AppMetricaCore
import Adjust
extension AppDelegate: AdjustDelegate {
func adjustAttributionChanged(_ attribution: ADJAttribution?) {
if let attribution = attribution?.dictionary() {
AppMetrica.reportExternalAttribution(attribution, from: .adjust)
}
}
}
#import <AppMetricaCore/AppMetricaCore.h>
#import <Adjust/Adjust.h>
@interface AppDelegate () <AdjustDelegate>
@end
@implementation AppDelegate
- (void)adjustAttributionChanged:(ADJAttribution *)attribution {
NSDictionary *attributionDictionary = [attribution dictionary];
if (attributionDictionary != nil) {
[AMAAppMetrica reportExternalAttribution:attributionDictionary
source:kAMAAttributionSourceAdjust
onFailure:nil];
}
}
@end
Kochava
For Kochava, use its attribution search method within a callback by calling the rawDictionary
property on the result retrieved from the singleton's attribution.retrieveResult
method.
- Initialize Kochava in a regular way.
- Kochava features its own attribution retrieval mechanism via a callback. Call the
rawDictionary
property in theresult
from theattribution.retrieveResult
method. Send the resulting dictionary to AppMetrica. - Set up the sending of attribution data (the
reportExternalAttribution
method) in the AppMetrica SDK.
import AppMetricaCore
import KochavaNetworking
import KochavaMeasurement
Measurement.shared.attribution.retrieveResult { result in
if let attribution = result.rawDictionary {
AppMetrica.reportExternalAttribution(attribution, from: .kochava)
}
}
#import <AppMetricaCore/AppMetricaCore.h>
@import KochavaNetworking;
@import KochavaMeasurement;
[KVAMeasurement.shared.attribution retrieveResultWithClosureDidComplete:^(KVAMeasurement_Attribution_Result * _Nonnull result) {
NSDictionary *attributionDictionary = result.rawDictionary;
if (attributionDictionary) {
[AMAAppMetrica reportExternalAttribution:attributionDictionary
source:kAMAAttributionSourceKochava
onFailure:nil];
}
}];
Tenjin
- Initialize Tenjin in a regular way.
- Get a TenjinSDK instance with your API key and then call
getAttributionInfo(_:)
. - Set up the sending of attribution data (the
reportExternalAttribution
method) in the AppMetrica SDK.
import AppMetricaCore
import TenjinSDK
TenjinSDK.getInstance("<SDK_KEY>").getAttributionInfo { (attribution: [AnyHashable : Any]?, error: Error?) in
if let attribution = attribution {
AppMetrica.reportExternalAttribution(attribution, from: .tenjin)
}
}
#import <AppMetricaCore/AppMetricaCore.h>
#import <TenjinSDK/TenjinSDK.h>
[[TenjinSDK getInstance:@"<SDK_KEY>"] getAttributionInfo:^(NSDictionary *attribution, NSError *error) {
if (attribution) {
[AMAAppMetrica reportExternalAttribution:attribution
source:kAMAAttributionSourceTenjin
onFailure:nil];
}
}];
Airbridge
- Initialize Airbridge in a regular way.
- Set the
attributionCallback
property for theABSetting
object retrieved fromAirBridge.setting()
. Pass the attribution dictionary as a parameter. - Set up the sending of attribution data (the
reportExternalAttribution
method) in the AppMetrica SDK.
import AppMetricaCore
import AirBridge
AirBridge.setting().attributionCallback = { (attribution: [String : String]) in
AppMetrica.reportExternalAttribution(attribution, from: .airbridge)
}
#import <AppMetricaCore/AppMetricaCore.h>
#import <AirBridge/AirBridge.h>
[AirBridge.setting setAttributionCallback:^(NSDictionary<NSString *,NSString *> * _Nonnull attribution) {
[AMAAppMetrica reportExternalAttribution:attribution
source:kAMAAttributionSourceAirbridge
onFailure:nil];
}];
Singular
- Initialize Singular in a regular way.
- Initialize
SingularConfig
with your API key and secret. - Assign a callback named
deviceAttributionCallback
for attribution data processing. - Set up the sending of attribution data (the
reportExternalAttribution
method) in the AppMetrica SDK.
import AppMetricaCore
import Singular
if let singularConfig = SingularConfig(apiKey: "API_KEY", andSecret: "SECRET") {
singularConfig.deviceAttributionCallback = { (attribution: [AnyHashable : Any]?) in
if let attribution = attribution {
AppMetrica.reportExternalAttribution(attribution, from: .singular)
}
}
}
#import <AppMetricaCore/AppMetricaCore.h>
#import <Singular/Singular.h>
SingularConfig *singularConfig = [[SingularConfig alloc] initWithApiKey:@"API_KEY" andSecret:@"SECRET"];
singularConfig.deviceAttributionCallback = ^(NSDictionary *attribution) {
if (attribution) {
[AMAAppMetrica reportExternalAttribution:attribution
source:kAMAAttributionSourceSingular
onFailure:nil];
}
};
If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.