AppsFlyer - cleveradssolutions/CAS-Track-revenue GitHub Wiki
The integration of AppsFlyer SDK into your application is presented in the official source.
Android
More information about initialization of CAS SDK here and AppsFlyer SDK here.
public class GlobalApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        
        //Initialize CAS
        CAS.buildManager().initialize(); 
        //Initialize AppsFlyer SDK
        AppsFlyerLib.getInstance().init(<AF_DEV_KEY>, null, this);
        
        //Start AppsFlyer SDK
        AppsFlyerLib.getInstance().start(this);
    }
}Replace <AF_DEV_KEY> with your AppsFlyer dev key. Get the AppsFlyer dev key.
iOS
More information about initialization of CAS SDK here and AppsFlyer SDK here.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool
{
    // Initialize CAS
    let manager = CAS.create(managerID: "demo",
                             enableTypes: [.banner, .interstitial, .rewarded],
                             demoAdMode: true) { complete, error in
               print("[CAS Sample] Mediation manager initialization: \(complete) with error: \(String(describing: error))")
           }
    // Configure AppsFlyer SDK
    AppsFlyerLib.shared().appsFlyerDevKey = "<AF_DEV_KEY>"
    AppsFlyerLib.shared().appleAppID = "<APPLE_APP_ID>"
        
    // Start AppsFlyer SDK
    AppsFlyerLib.shared().start()
}Replace <AF_DEV_KEY> with your AppsFlyer dev key. Get the AppsFlyer dev key. Replace <APPLE_APP_ID> with your Apple App Id.
Unity3d
More information about initialization of CAS SDK here and AppsFlyer SDK here.
class CleverAdsSolutionsDemoScript : MonoBehaviour, IAppsFlyerConversionData
{
    IMediationManager manager;
    void Awake() 
    {
        DontDestroyOnLoad(this);
    }   
 
    void Start()
    {
        // Initialize CAS
        manager = builder.Initialize();
  
        // Initialize AppsFlyer SDK 
        AppsFlyer.initSDK("devkey", "appID", this);
     
        // Start AppsFlyer SDK
        AppsFlyer.startSDK();
    }
    public void onConversionDataSuccess(string conversionData)
    {
        AppsFlyer.AFLog("onConversionDataSuccess", conversionData);
        Dictionary<string, object> conversionDataDictionary = AppsFlyer.CallbackStringToDictionary(conversionData);
        // add deferred deeplink logic here
    }
    public void onConversionDataFail(string error)
    {
        AppsFlyer.AFLog("onConversionDataFail", error);
    }
    public void onAppOpenAttribution(string attributionData)
    {
        AppsFlyer.AFLog("onAppOpenAttribution", attributionData);
        Dictionary<string, object> attributionDataDictionary = AppsFlyer.CallbackStringToDictionary(attributionData);
        // add direct deeplink logic here
    }
    public void onAppOpenAttributionFailure(string error)
    {
        AppsFlyer.AFLog("onAppOpenAttributionFailure", error);
    }
}
⚠️ Important: Make sure not to call destroy on the game object.
Replace devkey with your AppsFlyer dev key. Get the AppsFlyer dev key. Replace appID with your Application Id.
Android
Use our Ad Content Callback for tracking your Impression Level Data.
class MyActivity implements AdCallback {
  MediationManager manager; 
  CASBannerView banner;
  void createBanner() {
      banner = new CASBannerView(this, manager);
      banner.setListener(this);
  }
  void showInterstitial() {
      manager.showInterstitial(MyActivity.this, this);
  }
  void showRewarded() {
      manager.showRewarded(MyActivity.this, this);
  }
  @Override
  void onShown(AdStatusHandler ad) {
     // Executed when the ad is begin displayed.
     // AdStatusHandler is information of ad impression.
     Map<String, Object> eventValues = new HashMap<String, Object>();
     eventValues.put(AFInAppEventParameterName.AD_REVENUE_AD_TYPE, adStatusHandler.getAdType().name());
     eventValues.put(AFInAppEventParameterName.AD_REVENUE_NETWORK_NAME, adStatusHandler.getNetwork());
     if (adStatusHandler.getPriceAccuracy() != PriceAccuracy.UNDISCLOSED) {
         eventValues.put(AFInAppEventParameterName.REVENUE, adStatusHandler.getCpm() / 1000);
         eventValues.put("PriceAccuracy",
                 adStatusHandler.getPriceAccuracy() == PriceAccuracy.BID ? "BID" : "FLOOR");
     } else {
         eventValues.put("PriceAccuracy", "UNDISCLOSED");
     }
     AppsFlyerLib.getInstance().logEvent(getApplicationContext(),
             AFInAppEventType.AD_VIEW, eventValues);
  }
}iOS
Use our Ad Content Callback for tracking your Impression Level Data.
class AdExample : UIViewController, CASCallback {
    let manager: CASMediationManager
    @IBOutlet var bannerView: CASBannerView!
    
    func createBanner() {
        bannerView.rootViewController = self
        bannerView.delegate = self
    }
    
    func showInterstitial() {
        manager.presentInterstitial(fromRootViewController: self, callback: self)
    }
    
    func showRewarded() {
        manager.presentRewardedAd(fromRootViewController: self, callback: self)
    }
    func willShown(ad adStatus: CASStatusHandler) {
        var params : [String : Any] = [AFEventParamAdRevenueAdType: adStatus.adType.description, AFEventParamAdRevenueNetworkName: adStatus.network]
        
        if (adStatus.priceAccuracy != CASPriceAccuracy.undisclosed) {
            params[AFEventParamRevenue] = adStatus.cpm / 1000
            
            if (adStatus.priceAccuracy == CASPriceAccuracy.bid) {
                params["PriceAccuracy"] = "BID"
            } else {
                params["PriceAccuracy"] = "FLOOR"
            }
        } else {
            params["PriceAccuracy"] = "UNDISCLOSED"
        }
        
        AppsFlyerLib.shared().logEvent(AFEventAdView, withValues: params)
    }
}Unity3d
Use our Ad Content Callback for tracking your Impression Level Data.
class CleverAdsSolutionsDemoScript : MonoBehaviour
{
    IMediationManager manager;
    
    void Start()  
    {
        manager.OnBannerAdOpening += onAdOpening;
        manager.OnInterstitialAdOpening += onAdOpening;
        manager.OnRewardedAdOpening += onAdOpening;
    }
    void showInterstitial()
    {
        manager.ShowAd( AdType.Interstitial );
    }
    void showRewarded()
    {
        manager.ShowAd( AdType.Rewarded );
    } 
    void showBanner()
    {
        manager.ShowAd( AdType.Banner );
    }
     
    void onAdOpening(AdMetaData adMetaData)
    {
        // Executed when the ad is begin displayed.
        // AdStatusHandler is information of ad impression.
        Dictionary<string, object> impressionData = new Dictionary<string, object>();
        
        impressionData.add(AFInAppEventParameterName.AD_REVENUE_NETWORK_NAME, adMetaData.network.ToString());
        impressionData.add(AFInAppEventParameterName.AD_REVENUE_AD_TYPE, ad.getAdType().name());
        if(adMetaData.priceAccuracy != PriceAccuracy.Undisclosed) {
             impressionData.add(AFInAppEventParameterName.REVENUE, adMetaData.cpm / 1000);
             impressionData.add("PriceAccuracy", 
                  adMetaData.priceAccuracy == PriceAccuracy.Floor ? "Floor" : "Bid");
        } else { 
             impressionData.add("PriceAccuracy", "Undisclosed");
        }
    
        AppsFlyer.sendEvent(AFInAppEventType.AD_VIEW, impressionData);
    }
}