Repro - Mobile Analytics for growth
日本語
Sign Up Back to Dashboard
  • System Requirements
  • Dashboard Guide
  • Development Guide
    • Signup
    • iOS/Android SDK
      • Get Started
      • Session Lifecycle
      • User ID
      • Device ID
      • User Profile
      • Event Tracking
      • Push Notification
      • NewsFeed
      • In-App Message
      • Silver Egg Recommendation Messages
      • Remote Config
      • WebView
      • Opt-out feature
      • Settings regarding the collection of advertiser IDs
      • Registering an user device into a specific audience with the help of a QR code
      • Set attribution data from Adjust to Repro
      • Set attribution data from AppsFlyer to Repro
        • Set as user profile
        • Set as event property
      • Log Level
      • Verification Method
    • Web
    • Audience API
    • Audience Import(β)
    • Push API
    • User Profile API
    • User Profile Bulk Import
    • NewsFeed API
    • Deletion Targeted User Registration API
    • Booster installation guide
    • Mail(β)
  • Release Notes
  • FAQ
objc, swift, java

Set attribution data from AppsFlyer to Repro¶

Warning

iOS14.5 or later, implementation for App Tracking Transparency (ATT) is required. Please refer to this document for more details

iOS14.5 or later, if the user does not agree to ATT, it will basically not be possible to get attribution. Please refer to this document for more details

If you use a custom link, you can continue to get attribution and set it in your user profile or event properties.

The attribution data set in the sample code below is a sample and may differ from the actual attribution data available in your app. It is not necessary to set all the attribution data in Repro. Please refer to the sample code and set the ones you use for your campaign or analysis.

Set as user profile¶

You can set AppsFlyer's attribution data as User Profile.

You can use the set attribution data to optimize the user experience according to the content of the attribution, such as Advertisement Linked Message.

iOS: Implement the onConversionDataSuccess method, and set the attribution data as a user profile.

Android: Implement the onConversionDataSuccess method, and set the attribution data as a user profile

// AppDelegate.h
#import <UIKit/UIKit.h>
#import <AppsFlyerLib/AppsFlyerLib.h>
#import <AppTrackingTransparency/ATTrackingManager.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, AppsFlyerLibDelegate> {
 ...
}
@end

// AppDelegate.m
#import "AppDelegate.h"
#import <AppsFlyerLib/AppsFlyerLib.h>
@interface AppDelegate ()
@end
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // init AppsFlyer
    NSString* appsFlyerDevKey = [properties objectForKey:@"appsFlyerDevKey"];
    NSString* appleAppID = [properties objectForKey:@"appleAppID"];

    [[AppsFlyerLib shared] setAppsFlyerDevKey:appsFlyerDevKey];
    [[AppsFlyerLib shared] setAppleAppID:appleAppID];
    [AppsFlyerLib shared].delegate = self;

    [[AppsFlyerLib shared] start];

    // setup Repro
    [Repro setup:"YOUR_APP_TOKEN"];
}

- (void)onConversionDataSuccess:(NSDictionary*)installData {
    id status = [installData objectForKey:@"af_status"];
    if ([status isEqualToString:@"Non-organic"]) {
        id mediaSource = [installData objectForKey:@"media_source"];
        id campaign = [installData objectForKey:@"campaign"];

        [Repro setStringUserProfile:mediaSource forKey:@"AppsFlyer: media_source"];
        [Repro setStringUserProfile:campaign forKey:@"AppsFlyer: campaign"];

        NSLog(@"This is a none organic install. Media source: %@  Campaign: %@", sourceID, campaign);
    } else if ([status isEqualToString:@"Organic"]) {
        NSLog(@"This is an organic install.");
    }
}

- (void)onConversionDataFail:(NSError *)error {
    NSLog(@"%@",error);
}
func applicationDidBecomeActive(_ application: UIApplication) {
    // init AppsFlyer
    AppsFlyerLib.shared().appsFlyerDevKey = "MY_DEV_KEY"
    AppsFlyerLib.shared().appleAppID = "id123456789"

    // load the conversion data
    AppsFlyerLib.shared().delegate = self

    // track launch
    AppsFlyerLib.shared().start()
}

func onConversionDataSuccess(_ installData: [AnyHashable: Any]) {

    guard let status = installData["af_status"] as? String else {
        return
    }

    if(status == "Non-organic") {
        if let media_source = installData["media_source"] , let campaign = installData["campaign"] {
                Repro.setUserProfile(stringValue: media_source, forKey: "AppsFlyer: media_source")
                Repro.setUserProfile(stringValue: campaign, forKey: "AppsFlyer: campaign")

                print("This is a Non-Organic install. Media source: \(media_source) Campaign: \(campaign) ")
        }
    } else {
        print("This is an organic install.")
    }
}

func onConversionDataFail(_ error: Error!) {
    if let err = error{
    print(err)
}

func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]!) {
    if let data = attributionData{
    print("\(data)")
    }
}

func onAppOpenAttributionFailure(_ error: Error!) {
    if let err = error{
    print(err)
    }
}
AppsFlyerConversionListener conversionListener = new AppsFlyerConversionListener() {
    @Override
    public void onConversionDataSuccess(Map<String, String> conversionData) {
        for (String attrName : conversionData.keySet()) {
          String attrValue = conversionData.get(attrName);
            Log.d(AppsFlyerLib.LOG_TAG, "attribute: " + attrName + " = " + attrValue);
            if (attrName.equals("media_source")) {
                Repro.setStringUserProfile("AppsFlyer: media_source", attrValue);
            }
            else if (attrName.equals("campaign")) {
                Repro.setStringUserProfile("AppsFlyer: campaign", attrValue);
            }
        }
    }

    @Override
    public void onConversionFail(String errorMessage) {
        Log.d(AppsFlyerLib.LOG_TAG, "error getting conversion data: " + errorMessage);
    }

    @Override
    public void onAppOpenAttribution(Map<String, String> conversionData) {
    }

    @Override
    public void onAttributionFailure(String errorMessage) {
        Log.d(AppsFlyerLib.LOG_TAG, "error onAttributionFailure : " + errorMessage);
    }
});

Warning

  • This callback will be called only when your app is installed.

  • Please run the Repro SDK's setup before AppsFlyer's initialization.

Set as event property¶

You can set AppsFlyer's attribution data as Event Tracking.

You can use the set attribution data to optimize the user experience according to the content of the attribution, such as Advertisement Linked Message.

iOS: Implement the onConversionDataSuccess method, and set the attribution data as a custom event property of Event Tracking.

Android: Implement the onConversionDataSuccess method, and set the attribution data as a custom event property of Event Tracking.

// AppDelegate.h
#import "AppsFlyerTracker.h"

@interface AppDelegate : UIResponder<UIApplicationDelegate, AppsFlyerTrackerDelegate> {

    ...

}

// AppDelegate.m

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // setup Repro
    [Repro setup:"YOUR_APP_TOKEN"];

    // init AppsFlyer
    [[AppsFlyerLib shared] setAppsFlyerDevKey:@"MY_DEV_KEY"];
    [[AppsFlyerLib shared] setAppleAppID:@"id123456789"];

    // load the conversion data
    [AppsFlyerLib shared].delegate = self;
    // track launch
    [[AppsFlyerLib shared] start];
}

- (void)onConversionDataSuccess:(NSDictionary*)installData {
    id status = [installData objectForKey:@"af_status"];
    if ([status isEqualToString:@"Non-organic"]) {
        id mediaSource = [installData objectForKey:@"media_source"];
        id campaign = [installData objectForKey:@"campaign"];
        id adset = [installData objectForKey:@"af_adset"];
        id ad = [installData objectForKey:@"af_ad"];
        [Repro track:@"AppsFlyerAttribution" properties:@{
            @"mediaSource": mediaSource,
            @"campaign": campaign,
            @"adset": adset,
            @"ad": ad,
        }];

        NSLog(@"This is a none organic install. Media source: %@  Campaign: %@", sourceID, campaign);
    } else if ([status isEqualToString:@"Organic"]) {
        NSLog(@"This is an organic install.");
    }
}

- (void)onConversionDataFail:(NSError *)error {
    NSLog(@"%@",error);
}
func applicationDidBecomeActive(_ application: UIApplication) {
    // init AppsFlyer
    AppsFlyerLib.shared().appsFlyerDevKey = "MY_DEV_KEY"
    AppsFlyerLib.shared().appleAppID = "id123456789"

    // load the conversion data
    AppsFlyerLib.shared().delegate = self
    // track launch
    AppsFlyerLib.shared().start()
}

func onConversionDataSuccess(_ installData: [AnyHashable: Any]) {

    guard let status = installData["af_status"] as? String else {
        return
    }

    if(status == "Non-organic") {
        if let mediaSource = installData["media_source"], let campaign = installData["campaign"], let adset = installData["af_adset"], let ad = installData["af_ad"] {
            Repro.track(
                event: "AppsFlyerAttribution",
                properties: [
                    "mediaSource": mediaSource,
                    "campaign": campaign,
                    "adset": adset,
                    "ad": ad
                ])
        }
    } else {
        print("This is an organic install.")
    }
}

func onConversionDataFail(_ error: Error!) {
    if let err = error{
    print(err)
}
AppsFlyerConversionListener conversionListener = new AppsFlyerConversionListener() {
    @Override
    public void onConversionDataSuccess(Map<String, Object> conversionData) {
        final Object afStatus = conversionData.get("af_status");
        if (afStatus instanceof String && afStatus.equals("Non-organic")) {
            Map<String, Object> map = new HashMap<String, Object>();
            for (String attrName : conversionData.keySet()) {
                Object attrValue = conversionData.get(attrName);
                Log.d(AF_TAG, "attribute: " + attrName + " = " + attrValue);
                if (attrName.equals("network")) {
                    map.put("network", attrValue);
                }
                else if (attrName.equals("campaign")) {
                    map.put("campaign", attrValue);
                }
                else if (attrName.equals("af_adset")) {
                    map.put("adset", attrValue);
                }
                else if (attrName.equals("af_ad")) {
                    map.put("ad", attrValue);
                }
            }
            Repro.track("AppsFlyerAttribution", map);
        }
    }

    @Override
    public void onConversionFail(String errorMessage) {
        Log.d(AppsFlyerLib.LOG_TAG, "error getting conversion data: " + errorMessage);
    }
});

Warning

  • This callback will be called only when your app is installed.

  • Please run the Repro SDK's setup before AppsFlyer's initialization.

  • « Set attribution data from Adjust to Repro
  • Log Level »

About Us Careers Terms of Service Privacy Policy Cookie Policy

© 2022 Repro Inc.