React Native bindings for Google's User Messaging Platform SDK for Android and iOS.
npm install react-native-google-ump
or
yarn add react-native-google-ump
Obtain your app ID by following the Help Center instructions.
Add the following to your AndroidManifest.xml
after replacing YOUR-APP-ID
.
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="YOUR-APP-ID"/>
Take a look at our example app in the example
directory if you're unsure where exactly the meta-data
tag belongs.
Obtain your app ID by following the Help Center instructions.
Add the following to your Info.plist
after replacing YOUR-APP-ID
:
<key>GADApplicationIdentifier</key>
<string>YOUR-APP-ID</string>
The User Messaging Platform SDK is designed to be used in a linear fashion, so is this package. The steps for using the SDK and this package are:
- Request the latest consent information.
- Check if consent is required.
- Check if a form is available and if so load a form.
- Present the form.
- Provide a way for users to change their consent.
These steps are explained in more detail in the SDK's documentation.
import * as React from 'react';
import { Text } from 'react-native';
import UMP, { ConsentStatus } from 'react-native-google-ump';
export default function ConsentScreen() {
React.useEffect(() => {
async function effect() {
// 1. Request the latest consent information
await UMP.requestConsentInfoUpdate();
const consentInfo = await UMP.getConsentInfo();
// 2. Check if consent is required
if (result.consentStatus == ConsentStatus.REQUIRED) {
// 3. Check if a form is available...
if (result.consentFormAvailable) {
// ... and if so load a form
await UMP.loadConsentForm();
// 4. Present the form
await UMP.showConsentForm();
}
}
}
effect();
}, []);
return <Text>Loading consent info...</Text>;
}
It is recommended that you request an update of the consent information at every app launch. This will determine whether or not your user needs to provide consent.
import UMP from 'react-native-google-ump';
await UMP.requestConsentInfoUpdate({
underAgeOfConsent: false,
});
import UMP, { ConsentStatus } from 'react-native-google-ump';
const consentInfo = await UMP.getConsentInfo();
if (consentInfo.consentStatus === ConsentStatus.REQUIRED) {
// Consent is required
if (consentInfo.consentFormAvailable) {
// A consent form is available
}
}
Note that consent information is cached between app sessions and can be read without requesting an info update.
Once you've determined that a form is available, the next step is to load the form.
import UMP from 'react-native-google-ump';
await UMP.loadConsentForm();
You should determine if the user requires consent prior to presenting the form. If consent is not required, you can still show a form so that your user can change their consent.
import UMP from 'react-native-google-ump';
await UMP.showConsentForm();
Note that a consent form can only be shown once.
To show another form you need to call loadConsentForm
again.
To use the debug functionality, you need to provide your test device's hashed id. Emulators and simulators have testing enabled by default.
import UMP from 'react-native-google-ump';
await UMP.requestConsentInfoUpdate({
testDeviceHashedIds: ["test-device-id-here"];
});
This package provides a way to test your app's behavior as though the device was located or not located in the EAA.
import UMP from 'react-native-google-ump';
await UMP.requestConsentInfoUpdate({
debugGeography: DebugGeography.EEA,
});
await UMP.requestConsentInfoUpdate({
debugGeography: DebugGeography.NOT_EEA,
});
For testing it's helpful to reset the state of the SDK to simulate a user's first install experience. This package provides the reset method to do this:
import UMP from 'react-native-google-ump';
await UMP.resetConsentInfo();
By default, the Google Mobile Ads SDK initializes app measurement and begins sending user-level event data to Google immediately when the app starts. If your app requires user consent before these events can be sent, you can delay app measurement until you explicitly initialize the Mobile Ads SDK or load an ad.
To delay app measurement, follow the official instructions for Android and IOS.
This readme file only covers basics about the User Messaging Platfom SDK. The SDK's documentation is more detailed and discusses more topics such as mediation, forwarding consent and handling App Tracking Transparency requirements.
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT