Initialization topic
AdSense initialization
AdSense initialization is the same both for H5 Games Ads and the Ad Unit Widget.
To initialize AdSense:
Setup your AdSense account
- Make sure your site's pages are ready for AdSense
- Sign up for AdSense
- Adhere to the AdSense program policies while using ads from AdSense, and any specific policies for the ad formats that you use (for example, there's a specific Policy for ad units that offer rewards.)
Configure your Publisher ID
To start displaying ads, initialize AdSense with your Publisher ID (only use numbers).
import 'package:google_adsense/google_adsense.dart';
void main() async {
// Call `initialize` with your Publisher ID (pub-0123456789012345)
// (See: https://support.google.com/adsense/answer/105516)
await adSense.initialize('0123456789012345');
runApp(const MyApp());
}
Configure additional AdSense code parameters
You can pass an AdSenseCodeParameters
object to the adSense.initialize
call
to configure additional settings, like a custom channel ID, or for regulatory
compliance.
await adSense.initialize(
'0123456789012345',
adSenseCodeParameters: AdSenseCodeParameters(
adbreakTest: 'on',
adFrequencyHint: '30s',
),
);
Check the Google AdSense Help for a complete list of AdSense code parameter descriptions.