|
1 |
| -# google_adsense |
2 |
| -[Google AdSense](https://adsense.google.com/intl/en_us/start/) plugin for Flutter Web |
3 |
| - |
4 |
| -This package initializes AdSense on your website and provides an ad unit `Widget` that can be configured and placed in the desired location in your Flutter web app UI, without having to directly modify the HTML markup of the app directly. |
5 |
| - |
6 |
| -## Disclaimer: Early Access ⚠️ |
7 |
| -This package is currently in early access and is provided as-is. While it's open source and publicly available, it's likely that you'll need to make additional customizations and configurations to fully integrate it with your Flutter Web App. |
8 |
| -Please express interest joining Early Access program using [this form](https://docs.google.com/forms/d/e/1FAIpQLSdN6aOwVkaxGdxbVQFVZ_N4_UCBkuWYa-cS4_rbU_f1jK10Tw/viewform) |
9 |
| - |
10 |
| -## Usage |
11 |
| - |
12 |
| -### Setup your AdSense account |
13 |
| -1. [Make sure your site's pages are ready for AdSense](https://support.google.com/adsense/answer/7299563) |
14 |
| -2. [Create your AdSense account](https://support.google.com/adsense/answer/10162) |
15 |
| - |
16 |
| -### Initialize AdSense |
17 |
| -To start displaying ads, initialize AdSense with your [Publisher ID](https://support.google.com/adsense/answer/105516) (only use numbers). |
18 |
| - |
19 |
| -<?code-excerpt "example/lib/main.dart (init)"?> |
20 |
| -```dart |
21 |
| -import 'package:google_adsense/experimental/ad_unit_widget.dart'; |
22 |
| -import 'package:google_adsense/google_adsense.dart'; |
23 |
| -
|
24 |
| -void main() async { |
25 |
| - // Call `initialize` with your Publisher ID (pub-0123456789012345) |
26 |
| - // (See: https://support.google.com/adsense/answer/105516) |
27 |
| - await adSense.initialize('0123456789012345'); |
28 |
| -
|
29 |
| - runApp(const MyApp()); |
30 |
| -} |
31 |
| -``` |
32 |
| - |
33 |
| -### Displaying Auto Ads |
34 |
| -In order to start displaying [Auto ads](https://support.google.com/adsense/answer/9261805): |
35 |
| - |
36 |
| -1. Configure this feature in your AdSense Console. |
| 1 | +# Before you start |
37 | 2 |
|
38 |
| -Auto ads should start showing just with the call to `initialize`, when available. |
| 3 | +This package is only intended for use by web **games**. |
39 | 4 |
|
40 |
| -If you want to display ad units within your app content, continue to the next step |
| 5 | +Please apply to the beta using [this form]( https://adsense.google.com/start/h5-beta/?src=flutter). Once approved, you may use the package. |
41 | 6 |
|
42 |
| -### Display ad units (`AdUnitWidget`) |
| 7 | +Without approval, your code may not behave as expected, and your AdSense account may face policy issues. |
43 | 8 |
|
44 |
| -To display an Ad unit in your Flutter application: |
45 |
| - |
46 |
| -1. Create [ad units](https://support.google.com/adsense/answer/9183549) in your AdSense account. |
47 |
| - This will provide an HTML snippet, which you need to translate to Dart. |
48 |
| -2. Pick the `AdUnitConfiguration` for your ad type: |
49 |
| - |
50 |
| -| Ad Unit Type | `AdUnitConfiguration` constructor method | |
51 |
| -|----------------|--------------------------------------------| |
52 |
| -| Display Ads | `AdUnitConfiguration.displayAdUnit(...)` | |
53 |
| -| In-feed Ads | `AdUnitConfiguration.inFeedAdUnit(...)` | |
54 |
| -| In-article Ads | `AdUnitConfiguration.inArticleAdUnit(...)` | |
55 |
| -| Multiplex Ads | `AdUnitConfiguration.multiplexAdUnit(...)` | |
56 |
| - |
57 |
| -3. The data-attributes from the generated snippet are available through the `AdUnitConfiguration` object. |
58 |
| -Their Dart name is created as follows: |
59 |
| - |
60 |
| -- The `data-` prefix is **removed**. |
61 |
| -- `kebab-case` becomes `camelCase` |
62 |
| - |
63 |
| -The only exception to this is `data-ad-client`, that is passed to `adSense.initialize`, |
64 |
| -instead of through an `AdUnitConfiguration` object. |
65 |
| - |
66 |
| -For example snippet below: |
67 |
| - |
68 |
| -```html |
69 |
| -<ins class="adsbygoogle" |
70 |
| - style="display:block" |
71 |
| - data-ad-client="ca-pub-0123456789012345" |
72 |
| - data-ad-slot="1234567890" |
73 |
| - data-ad-format="auto" |
74 |
| - data-full-width-responsive="true"></ins> |
75 |
| -<script> |
76 |
| - (adsbygoogle = window.adsbygoogle || []).push({}); |
77 |
| -</script> |
78 |
| -``` |
79 |
| -translates into: |
80 |
| - |
81 |
| -<?code-excerpt "example/lib/main.dart (init-min)"?> |
82 |
| -```dart |
83 |
| -// Call `initialize` with your Publisher ID (pub-0123456789012345) |
84 |
| -// (See: https://support.google.com/adsense/answer/105516) |
85 |
| -await adSense.initialize('0123456789012345'); |
86 |
| -
|
87 |
| -``` |
88 |
| - |
89 |
| -and: |
| 9 | +# google_adsense |
90 | 10 |
|
91 |
| -<?code-excerpt "example/lib/main.dart (adUnit)"?> |
92 |
| -```dart |
93 |
| - AdUnitWidget( |
94 |
| - configuration: AdUnitConfiguration.displayAdUnit( |
95 |
| - // TODO: Replace with your Ad Unit ID |
96 |
| - adSlot: '1234567890', |
97 |
| - // Remove AdFormat to make ads limited by height |
98 |
| - adFormat: AdFormat.AUTO, |
99 |
| - ), |
100 |
| -), |
101 |
| -``` |
| 11 | +[Google AdSense](https://adsense.google.com/start/) plugin for Flutter Web. |
102 | 12 |
|
103 |
| -#### `AdUnitWidget` customizations |
| 13 | +This package provides a way to initialize and use AdSense on your Flutter Web app. |
| 14 | +It includes libraries for the following products: |
104 | 15 |
|
105 |
| -To [modify your responsive ad code](https://support.google.com/adsense/answer/9183363?hl=en&ref_topic=9183242&sjid=11551379421978541034-EU): |
106 |
| -1. Make sure to follow [AdSense policies](https://support.google.com/adsense/answer/1346295?hl=en&sjid=18331098933308334645-EU&visit_id=638689380593964621-4184295127&ref_topic=1271508&rd=1) |
107 |
| -2. Use Flutter instruments for [adaptive and responsive design](https://docs.flutter.dev/ui/adaptive-responsive) |
| 16 | +* [H5 Games Ads](https://adsense.google.com/start/h5-games-ads/) (beta) |
| 17 | +* (Experimental) [AdSense Ad Unit](https://support.google.com/adsense/answer/9183549) Widget |
108 | 18 |
|
109 |
| -For example, when not using responsive `AdFormat` it is recommended to wrap adUnit widget in the `Container` with width and/or height constraints. |
110 |
| -Note some [policies and restrictions](https://support.google.com/adsense/answer/9185043?hl=en#:~:text=Policies%20and%20restrictions) related to ad unit sizing: |
| 19 | +## Documentation |
111 | 20 |
|
112 |
| -<?code-excerpt "example/lib/main.dart (constraints)"?> |
113 |
| -```dart |
114 |
| -Container( |
115 |
| - constraints: |
116 |
| - const BoxConstraints(maxHeight: 100, maxWidth: 1200), |
117 |
| - padding: const EdgeInsets.only(bottom: 10), |
118 |
| - child: AdUnitWidget( |
119 |
| - configuration: AdUnitConfiguration.displayAdUnit( |
120 |
| - // TODO: Replace with your Ad Unit ID |
121 |
| - adSlot: '1234567890', |
122 |
| - // Do not use adFormat to make ad unit respect height constraint |
123 |
| - // adFormat: AdFormat.AUTO, |
124 |
| - ), |
125 |
| - ), |
126 |
| -), |
127 |
| -``` |
128 |
| -## Testing and common errors |
| 21 | +Check the [Flutter API docs](https://pub.dev/documentation/google_adsense/latest/) |
| 22 | +to learn how to: |
129 | 23 |
|
130 |
| -### Failed to load resource: the server responded with a status of 400 |
131 |
| -Make sure to set correct values to adSlot and adClient arguments |
| 24 | +* [Initialize AdSense](https://pub.dev/documentation/google_adsense/latest/topics/Initialization-topic.html) |
| 25 | +* [Use H5 Games Ads](https://pub.dev/documentation/google_adsense/latest/topics/H5%20Games%20Ads-topic.html) (beta) |
| 26 | +* [Display Ad Units](https://pub.dev/documentation/google_adsense/latest/topics/Ad%20Units-topic.html) (experimental) |
132 | 27 |
|
133 |
| -### Failed to load resource: the server responded with a status of 403 |
134 |
| -1. When happening in **testing/staging** environment it is likely related to the fact that ads are only filled when requested from an authorized domain. If you are testing locally and running your web app on `localhost`, you need to: |
135 |
| - 1. Set custom domain name on localhost by creating a local DNS record that would point `127.0.0.1` and/or `localhost` to `your-domain.com`. On mac/linux machines this can be achieved by adding the following records to you /etc/hosts file: |
136 |
| - `127.0.0.1 your-domain.com` |
137 |
| - `localhost your-domain.com` |
138 |
| - 2. Specify additional run arguments in IDE by editing `Run/Debug Configuration` or by passing them directly to `flutter run` command: |
139 |
| - `--web-port=8080` |
140 |
| - `--web-hostname=your-domain.com` |
141 |
| -2. When happening in **production** it might be that your domain was not yet approved or was disapproved. Login to your AdSense account to check your domain approval status |
| 28 | +## Support |
142 | 29 |
|
143 |
| -### Ad unfilled |
| 30 | +For technical problems with the code of this package, please |
| 31 | +[create a Github issue](https://github.com/flutter/flutter/issues/new?assignees=&labels=&projects=&template=9_first_party_packages.yml). |
144 | 32 |
|
145 |
| -There is no deterministic way to make sure your ads are 100% filled even when testing. Some of the way to increase the fill rate: |
146 |
| -- Ensure your ad units are correctly configured in AdSense |
147 |
| -- Try setting `adTest` parameter to `true` |
148 |
| -- Try setting AD_FORMAT to `auto` (default setting) |
149 |
| -- Try setting FULL_WIDTH_RESPONSIVE to `true` (default setting) |
150 |
| -- Try resizing the window or making sure that ad unit Widget width is less than ~1200px |
| 33 | +For any questions or support, please reach out to your Google representative or |
| 34 | +leverage the [AdSense Help Center](https://support.google.com/adsense#topic=3373519). |
0 commit comments