Adjust - cleveradssolutions/CAS-Track-revenue GitHub Wiki

Integrate the SDK into your app


The integration of Adjust 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 AdjustSDK
        String appToken = "{YourAppToken}";
        String environment = AdjustConfig.ENVIRONMENT_SANDBOX;
        AdjustConfig config = new AdjustConfig(this, appToken, environment);
        Adjust.onCreate(config);
    }
}

Replace {YourAppToken} with your app token. You can find this in your Adjust dashboard.

Next, you must set the environment to either sandbox or production mode:

String environment = AdjustConfig.ENVIRONMENT_SANDBOX;
String environment = AdjustConfig.ENVIRONMENT_PRODUCTION;

⚠️ Important: Set the value to AdjustConfig.ENVIRONMENT_SANDBOX if (and only if) you or someone else is testing your app. Make sure to set the environment to AdjustConfig.ENVIRONMENT_PRODUCTION before you publish the app. Set it back to AdjustConfig.ENVIRONMENT_SANDBOX if you start developing and testing it again.

Adjust use this environment to distinguish between real traffic and test traffic from test devices. Keeping the environment updated according to your current status is very important!

iOS

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

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Initialize CAS
    CASMediationManager *manager =
        [CAS createWithManagerID:@"demo"
                     enableTypes:CASTypeInt.everything
                      demoAdMode:YES
                          onInit:^(BOOL complete, NSString *_Nullable error) {
                              NSLog(@"[CAS Sample] Mediation manager initialization: %s with error: %@",
                                    complete ? "true" : "false", error);
                          }];

    // Initialize Adjust
    NSString *yourAppToken = @"{YourAppToken}";
    NSString *environment = ADJEnvironmentSandbox;
    ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken
                                            environment:environment];

    [Adjust appDidLaunch:adjustConfig];

    return YES;
}

Replace {YourAppToken} with your app token. You can find this in your Adjust dashboard.

Next, you must set the environment to either sandbox or production mode:

NSString *environment = ADJEnvironmentSandbox;
NSString *environment = ADJEnvironmentProduction;

⚠️ Important: Set the value to ADJEnvironmentSandbox if (and only if) you or someone else is testing your app. Make sure to set the environment to ADJEnvironmentProduction before you publish the app. Set it back to ADJEnvironmentSandbox if you start developing and testing it again.

Adjust use this environment to distinguish between real traffic and test traffic from test devices. Keeping the environment updated according to your current status is very important!

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 AdjustSDK
        string appToken = "{YourAppToken}";
        AdjustEnvironment environment = AdjustEnvironment.Sandbox;

        AdjustConfig config = new AdjustConfig(appToken, environment, true);
        Adjust.start(config);
    }
}

Replace {YourAppToken} with your app token. You can find this in your Adjust dashboard.

Next, you must set the environment to either sandbox or production mode:

AdjustEnvironment environment = AdjustEnvironment.Sandbox;
AdjustEnvironment environment = AdjustEnvironment.Production;

⚠️ Important: Set the value to AdjustConfig.ENVIRONMENT_SANDBOX if (and only if) you or someone else is testing your app. Make sure to set the environment to AdjustConfig.ENVIRONMENT_PRODUCTION before you publish the app. Set it back to AdjustConfig.ENVIRONMENT_SANDBOX if you start developing and testing it again.

Adjust use this environment to distinguish between real traffic and test traffic from test devices. Keeping the environment updated according to your current status is very important!

Track Impression Level Data

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.

     AdjustEvent adjustEvent = new AdjustEvent(ad.getAdType().name());
     adjustEvent.addCallbackParameter("Network", ad.getNetwork());
     
     if(ad.getPriceAccuracy() != PriceAccuracy.UNDISCLOSED) {
         adjustEvent.setRevenue(ad.getCpm() / 1000, "USD");
         adjustEvent.addCallbackParameter("PriceAccuracy", 
              ad.getPriceAccuracy() == PriceAccuracy.FLOOR ? "FLOOR" : "BID");
     } else { 
         adjustEvent.addCallbackParameter("PriceAccuracy", "UNDISCLOSED");
     }
    
     Adjust.trackEvent(adjustEvent);
  }
}
iOS

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

@inteface AdExample : UIViewController<CASCallback>

@property (strong, nonatomic) CASMediationManager * _Nullable manager;
@property (strong, nonatomic) IBOutlet CASBannerView *bannerView;

- (CASMediationManager * _Nullable)manager

@implementation AdExample

- (void) createBanner {
   [self.bannerView setTranslatesAutoresizingMaskIntoConstraints:NO];
   [self.bannerView setRootViewController:self];
   [self.bannerView setDelegate:self];
}

- (void) showInterstitial {
    [_manager presentInterstitialFromRootViewController:self callback:self];
}

- (void) showRewarded {
    [_manager presentRewardedAdFromRootViewController:self callback:self]; 
}

- (void) willShownWithAd:(id<CASStatusHandler>)adStatus {
    ADJEvent *event = [ADJEvent eventWithEventToken:[self getAdTypeName:adStatus.adType]];
    [event addCallbackParameter:@"Network" value:adStatus.network];
    
    if (adStatus.priceAccuracy != CASPriceAccuracyUndisclosed) {
        double revenue = adStatus.cpm / 1000;
        [event setRevenue:revenue currency:@"USD"];
        
        if (adStatus.priceAccuracy == CASPriceAccuracyBid) {
            [event addCallbackParameter:@"PriceAccuracy" value:@"BID"];
        } else {
            [event addCallbackParameter:@"PriceAccuracy" value:@"FLOOR"];
        }
    } else {
        [event addCallbackParameter:@"PriceAccuracy" value:@"UNDISCLOSED"];
    }
}

- (NSString *) getAdTypeName : (CASType)casType {
    switch (casType) {
        case CASTypeBanner:
            return @"Banner";
        case CASTypeInterstitial:
            return @"Interstitial";
        case CASTypeRewarded:
            return @"Rewareded";
        default:
            return @"None";
    }
}
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.

        AdjustEvent adjustEvent = new AdjustEvent(adMetaData.type.ToString());
        adjustEvent.addCallbackParameter("Network", adMetaData.network.ToString());
     
        if(adMetaData.priceAccuracy != PriceAccuracy.Undisclosed) {
             adjustEvent.setRevenue(adMetaData.cpm / 1000, "USD");
             adjustEvent.addCallbackParameter("PriceAccuracy", 
                  adMetaData.priceAccuracy == PriceAccuracy.Floor ? "Floor" : "Bid");
        } else { 
             adjustEvent.addCallbackParameter("PriceAccuracy", "Undisclosed");
        }
    
        Adjust.trackEvent(adjustEvent);
    }
}
⚠️ **GitHub.com Fallback** ⚠️