MyTracker - cleveradssolutions/CAS-Track-revenue GitHub Wiki

Integrate the SDK into your app


The integration of MyTracker SDK into your application is presented in the official source.

Track CAS revenue

Initialization

Android

More information about initialization of CAS SDK here and Adjust SDK here.

public class GlobalApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        
        // Initialize CAS
        CAS.buildManager().initialize(); 

        // Initialize myTracker SDK
        MyTracker.initTracker(SDK_KEY, this);
    }
}

Replace SDK_KEY with your SDK Key. You can find this in your myTarget dashboard.

iOS

More information about initialization of CAS SDK here and Adjust 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))")
           }

    // Initialize MyTracker SDK
    MRMyTracker.setupTracker(SDK_KEY)
}

Replace SDK_KEY with your SDK Key. You can find this in your myTarget dashboard.

Unity3d

More information about initialization of CAS SDK here and Adjust SDK here.

class CleverAdsSolutionsDemoScript : MonoBehaviour
{
    IMediationManager manager;
    void Start()
    {
        // Initialize CAS
        manager = builder.Initialize();

        // Initialize MyTracker SDK
        #if UNITY_IOS
            MyTracker.Init("SDK_KEY_IOS");
        #elif UNITY_ANDROID
            MyTracker.Init("SDK_KEY_ANDROID");
        #endif
    }
}

Replace SDK_KEY_ANDROID with your Android SDK Key and SDK_KEY_IOS with your iOS SDK Key You can find them in your myTarget dashboard.

Track Impression Level Data

Android

Use our Ad Content Callback for tracking your Impression Level Data.

class MyActivity extends Activity 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, String> eventParams = new HashMap<>();

     eventParams.put("AdType", adStatusHandler.getAdType().name());
     eventParams.put("Currency", "USD");
     eventParams.put("Network", adStatusHandler.getNetwork());

     if (adStatusHandler.getPriceAccuracy() != PriceAccuracy.UNDISCLOSED) {
         eventParams.put("Revenue", String.format("%f", cpm / 1000));
         eventParams.put("PriceAccuracy",
                 adStatusHandler.getPriceAccuracy() == PriceAccuracy.BID ? "BID" : "FLOOR");
     } else {
         eventParams.put("PriceAccuracy", "UNDISCLOSED");
     }

     MyTracker.trackEvent("AdImpression", eventParams);
  }
}
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 : String] = ["AdType": adStatus.adType.description, "Network": adStatus.network]
                
        if (adStatus.priceAccuracy != CASPriceAccuracy.undisclosed) {
            params["Revenue"] = String(format: "%f", adStatus.cpm / 1000)
                    
            if (adStatus.priceAccuracy == CASPriceAccuracy.bid) {
                params["PriceAccuracy"] = "BID"
            } else {
                params["PriceAccuracy"] = "FLOOR"
            }
        } else {
            params["PriceAccuracy"] = "UNDISCLOSED"
        }
             
        MRMyTracker.trackEvent(withName: "AdImpression", eventParams: 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, string> impressionData = new Dictionary<string, string>();
        
        impressionData.Add("Network", adMetaData.network.ToString());
        impressionData.Add( "AdType", adMetaData.type.ToString());

        if(adMetaData.priceAccuracy != PriceAccuracy.Undisclosed) {
            impressionData.Add( "Revenue", Convert.ToDecimal( cpm / 1000 ).ToString());
            impressionData.Add( "PriceAccuracy", 
                 adMetaData.priceAccuracy == PriceAccuracy.Floor ? "Floor" : "Bid");
        } else { 
             impressionData.Add( "PriceAccuracy", "Undisclosed");
        }

        MyTracker.TrackEvent( "AdImpression", impressionData );
    }
}
⚠️ **GitHub.com Fallback** ⚠️