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.

  1. Initialize AppsFlyer in a regular way.
  2. Use the method onConversionDataSuccess for attribution retrieval.
  3. 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.

  1. Initialize Adjust in a regular way.
  2. Adjust uses the ADJAttribution object for attribution data processing. Convert it to Dictionary with the dictionary() method and pass it to AppMetrica.
  3. 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.

  1. Initialize Kochava in a regular way.
  2. Kochava features its own attribution retrieval mechanism via a callback. Call the rawDictionary property in the result from the attribution.retrieveResult method. Send the resulting dictionary to AppMetrica.
  3. 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

  1. Initialize Tenjin in a regular way.
  2. Get a TenjinSDK instance with your API key and then call getAttributionInfo(_:).
  3. 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

  1. Initialize Airbridge in a regular way.
  2. Set the attributionCallback property for the ABSetting object retrieved from AirBridge.setting(). Pass the attribution dictionary as a parameter.
  3. 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

  1. Initialize Singular in a regular way.
  2. Initialize SingularConfig with your API key and secret.
  3. Assign a callback named deviceAttributionCallback for attribution data processing.
  4. 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.

Contact support