react-native-google-mobile-ads 4.2.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/RNGoogleMobileAds.podspec +16 -9
  2. package/__tests__/consent.test.ts +17 -9
  3. package/android/build.gradle +4 -3
  4. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsConsentModule.java +111 -168
  5. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +1 -1
  6. package/docs/common-reasons-for-ads-not-showing.mdx +26 -24
  7. package/docs/displaying-ads-hook.mdx +99 -0
  8. package/docs/displaying-ads.mdx +3 -4
  9. package/docs/european-user-consent.mdx +67 -156
  10. package/docs/index.mdx +16 -16
  11. package/docs/migrating-to-v5.mdx +63 -0
  12. package/docs.json +4 -2
  13. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.h +0 -1
  14. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.m +83 -124
  15. package/ios_config.sh +8 -0
  16. package/lib/commonjs/AdsConsent.js +58 -98
  17. package/lib/commonjs/AdsConsent.js.map +1 -1
  18. package/lib/commonjs/AdsConsentPurposes.js +47 -0
  19. package/lib/commonjs/AdsConsentPurposes.js.map +1 -0
  20. package/lib/commonjs/AdsConsentSpecialFeatures.js +39 -0
  21. package/lib/commonjs/AdsConsentSpecialFeatures.js.map +1 -0
  22. package/lib/commonjs/AdsConsentStatus.js +4 -3
  23. package/lib/commonjs/AdsConsentStatus.js.map +1 -1
  24. package/lib/commonjs/hooks/useAppOpenAd.js +51 -0
  25. package/lib/commonjs/hooks/useAppOpenAd.js.map +1 -0
  26. package/lib/commonjs/hooks/useFullScreenAd.js +120 -0
  27. package/lib/commonjs/hooks/useFullScreenAd.js.map +1 -0
  28. package/lib/commonjs/hooks/useInterstitialAd.js +51 -0
  29. package/lib/commonjs/hooks/useInterstitialAd.js.map +1 -0
  30. package/lib/commonjs/hooks/useRewardedAd.js +51 -0
  31. package/lib/commonjs/hooks/useRewardedAd.js.map +1 -0
  32. package/lib/commonjs/index.js +40 -0
  33. package/lib/commonjs/index.js.map +1 -1
  34. package/lib/commonjs/types/AdStates.js +6 -0
  35. package/lib/commonjs/types/AdStates.js.map +1 -0
  36. package/lib/commonjs/version.js +1 -1
  37. package/lib/commonjs/version.js.map +1 -1
  38. package/lib/module/AdsConsent.js +56 -98
  39. package/lib/module/AdsConsent.js.map +1 -1
  40. package/lib/module/AdsConsentPurposes.js +39 -0
  41. package/lib/module/AdsConsentPurposes.js.map +1 -0
  42. package/lib/module/AdsConsentSpecialFeatures.js +31 -0
  43. package/lib/module/AdsConsentSpecialFeatures.js.map +1 -0
  44. package/lib/module/AdsConsentStatus.js +4 -3
  45. package/lib/module/AdsConsentStatus.js.map +1 -1
  46. package/lib/module/hooks/useAppOpenAd.js +38 -0
  47. package/lib/module/hooks/useAppOpenAd.js.map +1 -0
  48. package/lib/module/hooks/useFullScreenAd.js +109 -0
  49. package/lib/module/hooks/useFullScreenAd.js.map +1 -0
  50. package/lib/module/hooks/useInterstitialAd.js +38 -0
  51. package/lib/module/hooks/useInterstitialAd.js.map +1 -0
  52. package/lib/module/hooks/useRewardedAd.js +38 -0
  53. package/lib/module/hooks/useRewardedAd.js.map +1 -0
  54. package/lib/module/index.js +5 -0
  55. package/lib/module/index.js.map +1 -1
  56. package/lib/module/types/AdStates.js +2 -0
  57. package/lib/module/types/AdStates.js.map +1 -0
  58. package/lib/module/version.js +1 -1
  59. package/lib/module/version.js.map +1 -1
  60. package/lib/typescript/AdsConsentPurposes.d.ts +148 -0
  61. package/lib/typescript/AdsConsentSpecialFeatures.d.ts +22 -0
  62. package/lib/typescript/AdsConsentStatus.d.ts +10 -6
  63. package/lib/typescript/hooks/useAppOpenAd.d.ts +9 -0
  64. package/lib/typescript/hooks/useFullScreenAd.d.ts +5 -0
  65. package/lib/typescript/hooks/useInterstitialAd.d.ts +9 -0
  66. package/lib/typescript/hooks/useRewardedAd.d.ts +9 -0
  67. package/lib/typescript/index.d.ts +6 -1
  68. package/lib/typescript/types/AdStates.d.ts +85 -0
  69. package/lib/typescript/types/AdsConsent.interface.d.ts +229 -180
  70. package/lib/typescript/version.d.ts +1 -1
  71. package/package.json +10 -4
  72. package/src/AdsConsent.ts +91 -135
  73. package/src/AdsConsentPurposes.ts +182 -0
  74. package/src/AdsConsentSpecialFeatures.ts +48 -0
  75. package/src/AdsConsentStatus.ts +11 -6
  76. package/src/hooks/useAppOpenAd.ts +46 -0
  77. package/src/hooks/useFullScreenAd.ts +104 -0
  78. package/src/hooks/useInterstitialAd.ts +46 -0
  79. package/src/hooks/useRewardedAd.ts +46 -0
  80. package/src/index.ts +5 -0
  81. package/src/types/AdStates.ts +87 -0
  82. package/src/types/AdsConsent.interface.ts +230 -187
  83. package/src/version.ts +1 -1
@@ -6,16 +6,9 @@ other local storage, where legally required, and to use personal data (such as `
6
6
  reflects the requirements of the `EU ePrivacy Directive` and the `General Data Protection Regulation` (GDPR).
7
7
 
8
8
  The React Native Google Mobile Ads module provides out of the box support for helping to manage your users consent
9
- within your application. The `AdsConsent` helper which comes with the module wraps the Google Consent SDK for both
9
+ within your application. The `AdsConsent` helper which comes with the module wraps the Google UMP SDK for both
10
10
  Android & iOS, and provides a single JavaScript interface for both platforms.
11
11
 
12
- The `AdsConsent` helper & AdMob module provides out of the box support for:
13
-
14
- - Requesting consent for multiple publisher IDs.
15
- - Showing a Google-rendered consent form, listing all providers on your enabled mediation networks.
16
- - Manually handling user consent if you prefer not to use the Google-rendered consent form.
17
- - Forwarding your user consent status onto AdMob ad requests.
18
-
19
12
  ## Understanding AdMob Ads
20
13
 
21
14
  Ads served by Google can be categorized as personalized or non-personalized, both requiring consent from users in the EEA. By default,
@@ -25,8 +18,6 @@ ad requests to Google serve personalized ads, with ad selection based on the use
25
18
 
26
19
  ## Handling consent
27
20
 
28
- The following steps show the various methods and ways of handling consent within your app.
29
-
30
21
  ### Delaying app measurement
31
22
 
32
23
  By default, the Google Mobile Ads SDK initializes app measurement and begins sending user-level event data to Google immediately when the app starts.
@@ -54,156 +45,105 @@ npx react-native run-ios
54
45
  npx react-native run-android
55
46
  ```
56
47
 
57
- ### Requesting consent information
48
+ ### App Tracking Transparency
58
49
 
59
- It is recommended you request consent information each time your application starts. The Consent SDK stores the users consent status
60
- based on the state of your AdMob network. If the state changes (e.g. a new mediation provider is added) the SDK automatically
61
- invalidates the consent status (setting is to "UNKNOWN").
50
+ If you want to handle Apple's App Tracking Transparency requirements, ensure you've configured and published your [ATT message](https://developers.google.com/admob/ump/ios/quick-start#app_tracking_transparency) in your Google AdMob account.
51
+ Also, within your projects `app.json` file, you have to use the `user_tracking_usage_description` to to describe your usage:
52
+
53
+ ```json
54
+ {
55
+ "react-native-google-mobile-ads": {
56
+ "android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
57
+ "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
58
+ "user_tracking_usage_description": "This identifier will be used to deliver personalized ads to you."
59
+ }
60
+ }
61
+ ```
62
62
 
63
- The `AdsConsent` helper provides a promised based method to return the users consent status called `requestInfoUpdate`. This method
64
- accepts an array of publisher IDs, which are used by the Consent SDK to determine the users consent status.
63
+ Once set, rebuild your application.
65
64
 
66
- Your own publisher ID can be found on the [Google AdMob dashboard](https://apps.admob.com/v2/settings) under "Settings > Account Information":
65
+ ### Requesting consent information
67
66
 
68
- ![Publisher ID](https://prismic-io.s3.amazonaws.com/invertase%2Fbcb7e7d6-2bb3-4e8c-8e6e-be99d6bc4f56_new+project+%2816%29.jpg)
67
+ It is recommended you request consent information each time your application starts to determine if the consent modal should be shown, e.g. due to provider changes.
69
68
 
70
- To request consent, call the method as early as possible within your app before presenting any ads:
69
+ The `AdsConsent` helper provides a promise based method to return the users consent status called `requestInfoUpdate`.
71
70
 
72
71
  ```js
73
72
  import { AdsConsent } from 'react-native-google-mobile-ads';
74
73
 
75
- const consentInfo = await AdsConsent.requestInfoUpdate(['pub-6189033257628123']);
74
+ const consentInfo = await AdsConsent.requestInfoUpdate();
76
75
  ```
77
76
 
78
- The result of the method returns an `AdsConsentInfo` interface, which provides information about the users status and location:
77
+ The method returns an `AdsConsentInfo` interface, which provides information about consent form availability and the users consent status:
79
78
 
80
- - **status**: The status can be one of 3 outcomes:
81
- - `UNKNOWN`: The user has not yet given consent, or has been invalidated since the last time they gave consent.
82
- - `NON_PERSONALIZED`: The user gave consent to see non-personalized ads only.
83
- - `PERSONALIZED`: The user gave consent to see personalized ads.
84
- - **isRequestLocationInEeaOrUnknown**: A boolean value. If `true` the users location is within the EEA or is unknown.
85
-
86
- The combination of status and location allows you to handle the next steps for requesting consent, if required:
87
-
88
- 1. If the users location is within the EEA or unknown, and their status is unknown, you must request consent before showing any ads.
89
- 2. If the users location is within the EEA or unknown, and their status is **not** unknown, you can show only the ad personalization they have requested.
90
- 3. If the users location is outside of the EEA, you do not have to give consent.
79
+ - **status**: The status can be one of 4 outcomes:
80
+ - `UNKNOWN`: Unknown consent status.
81
+ - `REQUIRED`: User consent required but not yet obtained.
82
+ - `NOT_REQUIRED`: User consent not required.
83
+ - `OBTAINED`: User consent already obtained.
84
+ - **isConsentFormAvailable**: A boolean value. If `true` a consent form is available.
91
85
 
92
86
  ### Gathering user consent
93
87
 
94
- Now we understand the consent status of the user, we can gather their consent (if required). This can be done in two ways:
95
-
96
- 1. Using a Google-rendered consent form.
97
- 2. Using a custom method.
98
-
99
- If you are aware that users are under the age of consent in Europe, it is possible to set this using the `setTagForUnderAgeOfConsent`
100
- method (TFUA). Once the setting is enabled, the Google-rendered consent form will fail to load. All ad requests that include
101
- TFUA will be made ineligible for personalized advertising and remarketing. TFUA disables requests to third-party ad technology
102
- providers, such as ad measurement pixels and third-party ad servers.
103
-
104
- To remove this setting, pass `false` to the method.
105
-
106
- #### 1. Google-rendered consent form
107
-
108
- The Google-rendered consent form is a full-screen configurable form that displays over your app content.
109
- You can configure the form to present the user with combinations of the following options:
110
-
111
- - Consent to view personalized ads
112
- - Consent to view non-personalized ads
113
- - Use a paid version of the app instead of viewing ads
114
-
115
- You should review the consent text carefully: what appears by default is a message that might be appropriate if you use
116
- Google to monetize your app; but Google cannot provide legal advice on the consent text that is appropriate for you.
117
- To update consent text of the Google-rendered consent form, modify the `consentform.html` file included in the Consent SDK as required.
118
-
119
- > An [example of a Google-rendered](https://developers.google.com/admob/images/android_eu_consent_form.png) consent form.
120
-
121
- To show the consent form, the `AdsConsent` helper provides a `showForm` method, which takes options to configure the form.
122
- You must provide a privacy policy URL.
88
+ To request consent, call these methods as early as possible within your app before presenting any ads.
89
+ Once the user has selected their preference, the `showForm` method returns an `AdsConsentFormResult` interface, containing the updated consent status:
123
90
 
124
91
  ```js
125
92
  import { AdsConsent, AdsConsentStatus } from 'react-native-google-mobile-ads';
126
93
 
127
- const consentInfo = await AdsConsent.requestInfoUpdate(['pub-6189033257628123']);
128
-
129
- if (
130
- consentInfo.isRequestLocationInEeaOrUnknown &&
131
- consentInfo.status === AdsConsentStatus.UNKNOWN
132
- ) {
133
- const formResult = await AdsConsent.showForm({
134
- privacyPolicy: 'https://invertase.io/privacy-policy',
135
- withPersonalizedAds: true,
136
- withNonPersonalizedAds: true,
137
- withAdFree: true,
138
- });
139
- }
140
- ```
141
-
142
- Once the user has selected their preference, the `formResult` contains their status and whether or not they prefer an
143
- ad-free option of your application (if enabled):
94
+ const consentInfo = await AdsConsent.requestInfoUpdate();
144
95
 
145
- ```js
146
- const formResult = await AdsConsent.showForm({
147
- privacyPolicy: 'https://invertase.io/privacy-policy',
148
- withPersonalizedAds: true,
149
- withNonPersonalizedAds: true,
150
- withAdFree: true,
151
- });
152
-
153
- if (formResult.userPrefersAdFree) {
154
- // Handle the users request, e.g. redirect to a paid for version of the app
96
+ if (consentInfo.isConsentFormAvailable && consentInfo.status === AdsConsentStatus.REQUIRED) {
97
+ const { status } = await AdsConsent.showForm();
155
98
  }
156
-
157
- // The user requested non-personalized or personalized ads
158
- const status = formResult.status;
159
99
  ```
160
100
 
161
- The `formResult.status` provides feedback on whether the user consented to personalized ads, or non-personalized ads.
162
- It is important that you forward this status onto all ad requests (see below).
163
-
164
101
  > Do not persist the status. You could however store this locally in application state (e.g. React Context) and update the status on every app launch as it may change.
165
102
 
166
- #### 2. Custom consent method
103
+ ### Inspecting consent choices
167
104
 
168
- If you wish to implement your own consent flow, the `AdsConsent` helper provides the tools needed to accomplish this.
169
- Depending on your requirements, a list of the enabled network mediation providers for the AdMob App ID can be returned and shown
170
- to the user via the `getAdProviders` method:
105
+ The AdsConsentStatus tells you if you should show the modal to a user or not. Often times you want to run logic based on the user's choices though.
106
+ Especially since the Google Mobile Ads SDK won't show any ads if the user didn't give consent to store and/or access information on the device.
107
+ This library exports a method that returns some of the most relevant consent flags to handle common use cases.
171
108
 
172
109
  ```js
173
110
  import { AdsConsent } from 'react-native-google-mobile-ads';
174
111
 
175
- const providers = await AdsConsent.getAdProviders();
176
- ```
177
-
178
- Each provider is an interface of `AdProvider`, containing information such as their company ID, company name and privacy policy URL.
179
- Using this information you can request consent from your users.
180
-
181
- Once consent has been returned, the Consent SDK needs to be aware of the custom user consent status. This can be forwarded on using the
182
- `setStatus` method, for example:
183
-
184
- ```js
185
- import { AdsConsent, AdsConsentStatus } from 'react-native-google-mobile-ads';
186
-
187
- // After getting user consent...
188
- await AdsConsent.setStatus(AdsConsentStatus.PERSONALIZED);
112
+ const {
113
+ activelyScanDeviceCharacteristicsForIdentification,
114
+ applyMarketResearchToGenerateAudienceInsights,
115
+ createAPersonalisedAdsProfile,
116
+ createAPersonalisedContentProfile,
117
+ developAndImproveProducts,
118
+ measureAdPerformance,
119
+ measureContentPerformance,
120
+ selectBasicAds,
121
+ selectPersonalisedAds,
122
+ selectPersonalisedContent,
123
+ storeAndAccessInformationOnDevice,
124
+ usePreciseGeolocationData,
125
+ } = await AdsConsent.getUserChoices();
126
+
127
+ if (storeAndAccessInformationOnDevice === false) {
128
+ /**
129
+ * The user declined consent for purpose 1,
130
+ * the Google Mobile Ads SDK won't serve ads.
131
+ */
132
+ }
189
133
  ```
190
134
 
191
- To invalidate the users consent status (e.g. if the providers list changes since their last consent), set the status back to
192
- `UNKNOWN`. When your application next boots, you can get the users previous consent status using the `getStatus` method.
193
-
194
135
  ### Testing
195
136
 
196
137
  When developing the consent flow, the behavior of the `AdsConsent` responses may not be reliable due to the environment
197
138
  (e.g. using an emulator vs real device). It is possible to set a debug location to test the various responses from the
198
- Consent SDK.
139
+ UMP SDK.
199
140
 
200
- If using a real device, ensure you whitelist it using the device ID, which can be obtained from native logs or using a library
201
- such as [react-native-device-info](https://github.com/react-native-community/react-native-device-info). Once found,
202
- call the `addTestDevice(deviceId)` method.
141
+ If using a real device, ensure you add it to the list of allowed devices by passing the device ID, which can be obtained from native logs or using a library
142
+ such as [react-native-device-info](https://github.com/react-native-community/react-native-device-info), to `testDeviceIdentifiers`.
203
143
 
204
144
  > Emulators are automatically whitelisted.
205
145
 
206
- To set a debug location, use the `setDebugGeography` method. It accepts 3 values:
146
+ To set a debug location, use the `debugGeography` key. It accepts 3 values:
207
147
 
208
148
  - **DISABLED**: Removes any previous debug locations.
209
149
  - **EEA**: Set the test device to be within the EEA.
@@ -214,45 +154,16 @@ For example:
214
154
  ```js
215
155
  import { AdsConsent, AdsConsentDebugGeography } from 'react-native-google-mobile-ads';
216
156
 
217
- await AdsConsent.setDebugGeography(AdsConsentDebugGeography.EEA);
157
+ const consentInfo = await AdsConsent.requestInfoUpdate({
158
+ debugGeography: AdsConsentDebugGeography.EEA,
159
+ testDeviceIdentifiers: ['TEST-DEVICE-HASHED-ID'],
160
+ });
218
161
  ```
219
162
 
220
- > Always ensure debug information is removed for production apps!
221
-
222
- ### Forwarding the consent status to ads
223
-
224
- Assuming the user is within the EEA and has provided consent, their status needs to be forwarded to every ad request we
225
- make in our application.
226
-
227
- > If the user is within the EEA and has not given consent, do not display AdMob ads (even non-personalized).
228
-
229
- Taking a Rewarded Video as an example, we can apply the users consent when our ad is loaded via the `RequestOptions`. For example:
163
+ It is possible to reset the UMP state for test devices. To reset the ATT state you have to delete and reinstall your app though.
230
164
 
231
165
  ```js
232
- import { AdsConsent, RewardedAd } from 'react-native-google-mobile-ads';
233
-
234
- const status = await AdsConsent.getStatus();
166
+ import { AdsConsent } from 'react-native-google-mobile-ads';
235
167
 
236
- const rewardedAd = RewardedAd.createForAdRequest('AD_UNIT_ID', {
237
- requestNonPersonalizedAdsOnly: status === AdsConsentStatus.NON_PERSONALIZED,
238
- });
168
+ AdsConsent.reset();
239
169
  ```
240
-
241
- The requested ad URL via the SDK will send a request with an additional parameter `&npa=1`, which will return a
242
- non-personalized ad.
243
-
244
- ### Troubleshooting
245
-
246
- #### "Could not parse Event FE preflight response."
247
-
248
- This is a common error which occurs on both Android & iOS when making a request to display a Google-rendered consent form. Unfortunately the reasoning for this error is generic, making it hard to debug. There are a number of steps to check which are usually the cause for this error:
249
-
250
- - The AdMob App ID is incorrect: Ensure you have entered the correct ID into the `app.json` file under the `android_app_id` or `ios_app_id` key in the `react-native-google-mobile-ads` config.
251
- - A publisher ID is incorrect: Ensure your entered publisher IDs are correct.
252
- - The publisher ID needs to be available on the same account as your AdMob App ID.
253
- - The user is outside of the EEA: If a user does not need to provide consent, the form request will error. Ensure you have checked the users status via `requestInfoUpdate`. If using an emulator, ensure you set a debug location via `setDebugGeography`.
254
- - Your AdMob account is not valid:
255
- - Your account is disabled: This can occur if Google notices you have duplicate accounts. They will email you about this, and block you from entering the dashboard.
256
- - You have provided invalid payment information: If your account has no payment information set up, this seems to cause this error to trigger.
257
-
258
- If you are still struggling to present the consent form, reach out to AdMob support to investigate your account status via https://support.google.com/admob
package/docs/index.mdx CHANGED
@@ -7,21 +7,21 @@ yarn add react-native-google-mobile-ads
7
7
 
8
8
  > On Android, before releasing your app, you must select _Yes, my app contains ads_ in the Google Play Store, Policy, App content, Manage under Ads.
9
9
 
10
- # What does it do
10
+ ## What does it do
11
11
 
12
12
  The AdMob module allows you to display adverts to your users. All adverts are served over the Google AdMob network, meaning
13
13
  a [Google AdMob account](https://apps.admob.com) is required.
14
14
 
15
15
  <YouTube id="9qCxo0D-Sak" />
16
16
 
17
- The module supports three types of Ads:
17
+ The module supports four types of Ads:
18
18
 
19
19
  1. Full screen [App Open Ads](/displaying-ads#app-open-ads).
20
20
  2. Full screen [Interstitial Ads](/displaying-ads#interstitial-ads).
21
21
  3. Full screen [Rewarded Ads](/displaying-ads#rewarded-ads).
22
22
  4. Component based [Banner Ads](/displaying-ads#banner-ads).
23
23
 
24
- # Getting Started
24
+ ## Getting Started
25
25
 
26
26
  A number of steps must be taken and considered before you start serving adverts to your users:
27
27
 
@@ -33,7 +33,7 @@ A number of steps must be taken and considered before you start serving adverts
33
33
  - [Test ads](#test-ads)
34
34
  - [Next Steps](#next-steps)
35
35
 
36
- ## Setting up Google AdMob
36
+ ### Setting up Google AdMob
37
37
 
38
38
  Before you are able to display ads to your users, you must have a [Google AdMob account](https://apps.admob.com). Under the
39
39
  "Apps" menu item, create or choose an existing Android/iOS app. Each app platform exposes a unique account ID which needs to
@@ -62,14 +62,14 @@ For the changes to take effect, rebuild your project:
62
62
 
63
63
  ```bash
64
64
  # For iOS
65
- cd ios/ && pod install
65
+ npx pod-install
66
66
  npx react-native run-ios
67
67
 
68
68
  # For Android
69
69
  npx react-native run-android
70
70
  ```
71
71
 
72
- ## Configure outbound requests
72
+ ### Configure outbound requests
73
73
 
74
74
  If the default ad settings are not correct for your app, you can provide settings that will apply to all ad requests.
75
75
 
@@ -93,8 +93,8 @@ mobileAds()
93
93
  // manner suitable for users under the age of consent.
94
94
  tagForUnderAgeOfConsent: true,
95
95
 
96
- // An array of test device IDs to whitelist.
97
- testDeviceIdentifiers: ["EMULATOR"]
96
+ // An array of test device IDs to allow.
97
+ testDeviceIdentifiers: ['EMULATOR'],
98
98
  })
99
99
  .then(() => {
100
100
  // Request config successfully set!
@@ -103,37 +103,37 @@ mobileAds()
103
103
 
104
104
  To learn more about the request configuration settings, view the [`RequestConfiguration`](/reference/admob/requestconfiguration) documentation.
105
105
 
106
- ## Initialize the Google Mobile Ads SDK
106
+ ### Initialize the Google Mobile Ads SDK
107
107
 
108
108
  Before loading ads, have your app initialize the Google Mobile Ads SDK by calling `initialize` which initializes the SDK and returns a promise once initialization is complete (or after a 30-second timeout).
109
109
  This needs to be done only once, ideally at app launch.
110
110
 
111
111
  > ⚠️ **Warning:** Ads may be preloaded by the Mobile Ads SDK or mediation partner SDKs upon calling `initialize`.
112
- If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags (such as tagForChildDirectedTreatment), or otherwise take action before loading ads, ensure you do so before initializing the Mobile Ads SDK.
112
+ > If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags (such as tagForChildDirectedTreatment), or otherwise take action before loading ads, ensure you do so before initializing the Mobile Ads SDK.
113
113
 
114
114
  ```js
115
115
  import mobileAds from 'react-native-google-mobile-ads';
116
116
 
117
117
  mobileAds()
118
118
  .initialize()
119
- .then((adapterStatuses) => {
119
+ .then(adapterStatuses => {
120
120
  // Initialization complete!
121
121
  });
122
122
  ```
123
123
 
124
124
  If you are using mediation, you may wish to wait until the promise is settled before loading ads, as this will ensure that all mediation adapters are initialized.
125
125
 
126
- ## European User Consent
126
+ ### European User Consent
127
127
 
128
128
  Out of the box, AdMob does not handle any related regulations which you may need to enforce on your application.
129
129
  It is up to the developer to implement and handle this on a user-by-user basis. You must consent to EEA users
130
130
  being served both personalized and non-personalized adverts before showing them. For more information, see
131
- [Requesting Consent from European Users](https://developers.google.com/admob/android/eu-consent).
131
+ [Obtaining Consent with the User Messaging Platform](https://developers.google.com/admob/ump/android/quick-start).
132
132
 
133
- The AdMob module provides a `AdConsent` helper to help developers quickly implement consent flows within their application.
133
+ The AdMob module provides a `AdsConsent` helper to help developers quickly implement consent flows within their application.
134
134
  See the [European User Consent page](/european-user-consent) for full examples of how to integrate the helper into your application.
135
135
 
136
- ## Test ads
136
+ ### Test ads
137
137
 
138
138
  Whilst developing your app with AdMob, you'll want to make sure you use test ads rather than production ads from your
139
139
  Google AdMob account - otherwise your account may be disabled!
@@ -157,7 +157,7 @@ RewardedAd.createForAdRequest(TestIds.REWARDED);
157
157
  <BannerAd unitId={TestIds.BANNER} />
158
158
  ```
159
159
 
160
- # Next Steps
160
+ ## Next Steps
161
161
 
162
162
  Now the basics of setting up and configuring AdMob have been explained, we can go ahead and start to display different
163
163
  adverts to our users. The AdMob module provides integration with three different types:
@@ -0,0 +1,63 @@
1
+ # Migrating to v5
2
+
3
+ ## AdsConsent
4
+
5
+ Google replaced their Consent SDK with the User Messaging Platform (UMP) SDK, which supports the latest IAB standards and Apple's App Tracking Transparency requirements.
6
+
7
+ Please refer to the following links for more information:
8
+
9
+ - [User Messaging Platform](https://developers.google.com/admob/ump/ios/quick-start)
10
+ - [EU User Consent Policy](https://www.google.com/about/company/user-consent-policy/)
11
+ - [IAB Europe Transparency](https://iabeurope.eu/iab-europe-transparency-consent-framework-policies/)
12
+ - [App Tracking Transparency](https://developer.apple.com/documentation/apptrackingtransparency)
13
+
14
+ Previously it was possible to request the ad providers and to update the consent status. This is no longer the case.
15
+ Also, while the old Consent SDK provided information about user preferences, the new `AdsConsentStatus` only tells you if you should show the modal to a user or not.
16
+
17
+ - `requestInfoUpdate` does now accept an optional `AdsConsentInfoOptions` object instead of expecting `publisherIds` and returns a changed `AdsConsentInfo` interface
18
+ - `showForm` does not expect any parameters any longer and now only returns the changed `AdsConsentStatus` as part of it's `AdsConsentFormResult` interface
19
+ - `getAdProviders`, `getStatus` and `setStatus` methods were removed without replacements
20
+ - `addTestDevices`, `setDebugGeography` and `setTagForUnderAgeOfConsent` methods were removed, but their functionality is available via `AdsConsentInfoOptions`
21
+ - the `user_tracking_usage_description` key is needed in your project's `app.json` if you want to handle Apple's App Tracking Transparency
22
+ - newly added `getUserChoices` can be used to inspect some of the consent choices
23
+
24
+ ```diff
25
+ {
26
+ "react-native-google-mobile-ads": {
27
+ "android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
28
+ "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
29
+ + "user_tracking_usage_description": "This identifier will be used to deliver personalized ads to you."
30
+ }
31
+ }
32
+ ```
33
+
34
+ ```diff
35
+ import { AdsConsent, AdsConsentStatus } from 'react-native-google-mobile-ads';
36
+
37
+ -const consentInfo = await AdsConsent.requestInfoUpdate(['pub-6189033257628123']);
38
+ +const consentInfo = await AdsConsent.requestInfoUpdate();
39
+
40
+ if (
41
+ - consentInfo.isRequestLocationInEeaOrUnknown &&
42
+ + consentInfo.isConsentFormAvailable &&
43
+ - consentInfo.status === AdsConsentStatus.UNKNOWN
44
+ + consentInfo.status === AdsConsentStatus.REQUIRED
45
+ ) {
46
+ - const formResult = await AdsConsent.showForm({
47
+ - privacyPolicy: 'https://invertase.io/privacy-policy',
48
+ - withPersonalizedAds: true,
49
+ - withNonPersonalizedAds: true,
50
+ - withAdFree: true,
51
+ - });
52
+ + const formResult = await AdsConsent.showForm()
53
+ +
54
+ + const { storeAndAccessInformationOnDevice } = await AdsConsent.getUserChoices();
55
+ +
56
+ + if (storeAndAccessInformationOnDevice === false) {
57
+ + /**
58
+ + * The user declined consent for purpose 1,
59
+ + * the Google Mobile Ads SDK won't serve ads.
60
+ + */
61
+ + }
62
+ }
63
+ ```
package/docs.json CHANGED
@@ -4,7 +4,9 @@
4
4
  "sidebar": [
5
5
  ["Installation", "/"],
6
6
  ["Displaying Ads", "/displaying-ads"],
7
+ ["Displaying Ads via Hook", "/displaying-ads-hook"],
7
8
  ["European User Consent", "/european-user-consent"],
8
- ["Common Reasons For Ads Not Showing", "/common-reasons-for-ads-not-showing"]
9
+ ["Common Reasons For Ads Not Showing", "/common-reasons-for-ads-not-showing"],
10
+ ["Migrating to v5", "/migrating-to-v5"]
9
11
  ]
10
- }
12
+ }
@@ -18,7 +18,6 @@
18
18
 
19
19
  #import <Foundation/Foundation.h>
20
20
 
21
- #import <PersonalizedAdConsent/PersonalizedAdConsent.h>
22
21
  #import <React/RCTBridgeModule.h>
23
22
 
24
23
  @interface RNGoogleMobileAdsConsentModule : NSObject <RCTBridgeModule>