Tenjin - cleveradssolutions/CAS-Track-revenue GitHub Wiki

Integrate the SDK into your app


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

Track CAS revenue

Initialization

Android

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

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

        // Initialize Tenjin SDK
        TenjinSDK instance = TenjinSDK.getInstance(this, "<API_KEY>");
        instance.connect();
    }
}

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

iOS

More information about initialization of CAS SDK here and Tenjin 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 Tenjin
    [TenjinSDK init:@"<API_KEY>"];
    [TenjinSDK connect];

    return YES;
}

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

Unity3d

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

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

        // Initialize Tenjin SDK
        TenjinConnect();
    }

    void OnApplicationPause(bool pauseStatus) 
    {
        if (!pauseStatus) {
            TenjinConnect();
        } 
    }

    void TenjinConnect() 
    {
        BaseTenjin instance = Tenjin.getInstance("API_KEY");

        #if UNITY_IOS

        // Registers SKAdNetwork app for attribution
        instance.RegisterAppForAdNetworkAttribution();

        // Sends install/open event to Tenjin
        instance.Connect();

        // Sets SKAdNetwork Conversion Value
        // You will need to use a value between 0-63 for <YOUR 6 bit value>
        instance.UpdateConversionValue(<your 6 bit value>);

        #elif UNITY_ANDROID

        // Sends install/open event to Tenjin
        instance.Connect();

        #endif
    }
}

Replace API_KEY with your API Key. You can find this in your Tenjin 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;
  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.

 
     String apiKey = "<API_KEY>";
     TenjinSDK instance = TenjinSDK.getInstance(this, apiKey);
     
     if (adStatusHandler.getPriceAccuracy() != PriceAccuracy.UNDISCLOSED) {
         instance.eventWithNameAndValue("AdImpression", cpm / 1000);  
     } 
   }
}

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;
        [TenjinSDK sendEventWithName:@"AdImpression" andEventValue:[[NSNumber numberWithDouble:revenue] stringValue]];
    }
}
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) {
            var tenjin = Tenjin.getInstance( "<API_KEY>" );
            tenjin.Connect();

            tenjin.SendEvent( "AdImpression", adMetaData.cpm / 1000 );
        }
    }
}

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

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