Skip to content
This repository was archived by the owner on Mar 12, 2022. It is now read-only.

Initialize

Bruno D'Luka edited this page Jan 3, 2021 · 21 revisions

Initialize

Before creating any native ads, you must initalize the admob. It can be initialized only once:

import 'package:flutter/foundation.dart';

String get admobUnitId {
  /// Always test with test ads
  if (kDebugMode)
    return 'ca-app-pub-3940256099942544/2247696110';
  else return 'your-native-ad-unit-id';
}

void main() {
  // Add this line if you will initialize it before runApp
  WidgetsFlutterBinding.ensureInitialized();
  // default native ad unit id: ca-app-pub-3940256099942544/2247696110
  NativeAds.initialize(admobUnitId);
  runApp(MyApp());
}

❗NOTE:❗ Unit IDs are NOT App IDs

Always test with test ads

When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account.

The easiest way to load test ads is to use the dedicated test ad unit ID for Native Ads on Android:

App ID: ca-app-pub-3940256099942544~3347511713
Unit ID: ca-app-pub-3940256099942544/2247696110

It's been specially configured to return test ads for every request, and you're free to use it in your own apps while coding, testing, and debugging. Just make sure you replace it with your own ad unit ID before publishing your app.

For more information about how the Mobile Ads SDK's test ads work, see Test Ads.

Learn how to create your own native ads unit ids here

When to request ads

Applications displaying native ads are free to request them in advance of when they'll actually be displayed. In many cases, this is the recommended practice. An app displaying a list of items with native ads mixed in, for example, can load native ads for the whole list, knowing that some will be shown only after the user scrolls the view and some may not be displayed at all.


Next: Creating an ad
Clone this wiki locally