Singular - cleveradssolutions/CAS-Track-revenue GitHub Wiki

Integrate the SDK into your app


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

Track CAS revenue

Initialization

Android

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

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

        // Initialize Singular SDK
        SingularConfig config = new SingularConfig(apiKey, secretKey);
        Singular.init(this, config);
    }
}

Replace apiKey and secretKey with your API Key and API Secret. You can find this in your Singular dashboard.

iOS

More information about initialization of CAS SDK here and Singular 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 Singular SDK
    [Singular startSession:@"APIKEY" withKey:@"SECRET"];

    return YES;
}

Replace apiKey and secretKey with your API Key and API Secret. You can find this in your Singular dashboard.

Unity3d

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

Attach SingularSDK script to the prefab on first scene of your Unity project.

Replace apiKey and secretKey with your API Key and API Secret. You can find this in your Singular dashboard.

Initialize CAS and Singular SDK's

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

        // API Key and API Secret are set on the 
        // game object associated with SingularSDK 
        SingularSDK.InitializeSingularSDK();
    }
}

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;
  FirebaseAnalytics mFirebaseAnalytics;

  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.

     if (adStatusHandler.getPriceAccuracy() != PriceAccuracy.UNDISCLOSED) {
         SingularAdData data = new SingularAdData("CAS", "USD", adStatusHandler.getCpm() / 1000)
                 .withAdType(adStatusHandler.getAdType().name())
                 .withNetworkName(adStatusHandler.getNetwork());

         Singular.adRevenue(data);
     }
  }
}

Replace API_KEY with your API Key. You can find this in your Tenjin dashboard.

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 {
    if (adStatus.priceAccuracy != CASPriceAccuracyUndisclosed) {
        double revenue = adStatus.cpm / 1000;
        SingularAdData* data = [[SingularAdData alloc] initWithAdPlatfrom: @"CAS" withCurrency: @"USD" withRevenue: [NSNumber numberWithDouble:revenue]];
        
        [data setAdType: [self getAdTypeName:adStatus.adType]];
        [data setNetworkName: adStatus.network];
        
        [Singular adRevenue: data];
    }
}

- (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.
        if (adMetaData.priceAccuracy != PriceAccuracy.Undisclosed)
        {
            SingularAdData data = new SingularAdData( "CAS", "USD", adMetaData.cpm / 1000 )
                .WithAdType( adMetaData.type.ToString() )
                .WithNetworkName( adMetaData.network.ToString() );

            SingularSDK.AdRevenue( data );
        }
    }
}

Replace API_KEY with your API Key. You can find this in your Tenjin dashboard.

⚠️ **GitHub.com Fallback** ⚠️