Initialize CAS - cleveradssolutions/CAS-Flutter GitHub Wiki

:zap: Before you start
Make sure you have correctly Project Setup.


Initialize MediationManager

To display ads, you must initialize the mediation manager with a unique CasId.
This needs to be done only once for each manager, ideally at app launch.

If you haven't created an CAS account and registered an app yet, now's a great time to do so at cleveradssolutions.com. In a real app, it is important that you use your actual CAS ID.

  • In a real app, it is important that you use your actual CAS ID.

Do not initialize mediated advertising SDKs (CAS does that for you).
Not following this step will result in noticeable integration issues.

  • Before the initialization, set the Flutter version you are using to build your app as below:
CAS.setFlutterVersion(YOUR_FLUTTER_VERSION);
import 'package:clever_ads_solutions/public/MediationManager.dart';
import 'package:clever_ads_solutions/public/ManagerBuilder.dart';
import 'package:clever_ads_solutions/public/AdTypes.dart';
import 'package:clever_ads_solutions/public/InitializationListener.dart';
import 'package:clever_ads_solutions/CAS.dart';

class CleverAdsSolutionsDemoScript
{
    MediationManager? manager;

    void main() {
      initialize();
    }

    void initialize() {
      // Set your Flutter version
      CAS.setFlutterVersion(YOUR_FLUTTER_VERSION);

      manager = CAS.buildManager()
       // Set initialization listener
       .withInitializationListener(InitializationListenerWrapper())
       // Set your CAS ID
       .withCasId("demo")
       // List Ad formats used in app
       .withAdTypes(AdTypeFlags.Banner | AdTypeFlags.Rewarded | AdTypeFlags.Interstitial)
       // Use Test ads or live ads
       .withTestAdMode(isTestBuild)
       .initialize();
    }
}

class InitializationListenerWrapper extends InitializationListener {
  @override
  void onCASInitialized(InitConfig initialConfig) {
    String error = initialConfig.error;
    String countryCode = initialConfig.countryCode;
    bool isTestMode = initialConfig.isTestMode;
    bool isConsentRequired = initialConfig.isConsentRequired;
  }
}

Ads processing

CAS have functionality to limit the processing of specific AdType.
This can be useful when you need to improve application performance by turning off unused formats.
Or if you have determined that the user will no longer need to be shown ads, for example after purchase.
The default ad type activity is selected in the settings window.
However, the state can be changed after initialization using the following methods:

manager.setEnabled(AdTypeFlags.Interstitial, false);
  • If processing is inactive then all calls to the selected ad type will fail with error ManagerIsDisabled.
  • ⚠️ Turning off the processing leads to the complete destruction of the ready ads from memory. And reactivation after destruction requires a new load of ads to memory.
  • The state will not be saved between sessions.

Retrieve the Version Number

To programmatically retrieve the native SDK version number at runtime, CAS provides the following string:

String nativeSDKVersion = CAS.getSDKVersion();

Targeting options

You can now easily tailor the way you serve your ads to fit a specific audience!
You’ll need to inform our servers of the users’ details so the SDK will know to serve ads according to the segment the user belongs to.

Set user gender using the following method:

CAS.setGender(Gender.MALE);

Set user age with limitation 1-99 and 0 is 'unknown' using the following method:

CAS.setAge(12);

🔗 Done! What’s Next?