Coder Social home page Coder Social logo

ulangi / react-native-ad-consent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from birgernass/react-native-ad-consent

0.0 2.0 0.0 120 KB

Uses the Google Mobile Ads Consent SDK to ask users for GDPR compliant ad consent. Supports iOS and Android.

License: MIT License

Java 49.94% Objective-C 44.72% JavaScript 1.20% Ruby 4.14%

react-native-ad-consent's Introduction

react-native-ad-consent

Uses the Google Mobile Ads Consent SDK to ask users for GDPR compliant ad consent. Supports iOS and Android.

Getting started

For React Native versions < 0.60 use version 1.+ of this library and checkout the corresponding README file.

$ yarn add react-native-ad-consent

or

$ npm install react-native-ad-consent --save

Additional Steps (iOS)

Add the following key to your project's Info.plist:

+               <key>GADIsAdManagerApp</key>
+               <true/>
              </dict>
            </plist>

Add the following initalization code to your project's AppDelegate.h:

 #import <React/RCTBridgeDelegate.h>
 #import <UIKit/UIKit.h>
+#import <GoogleMobileAds/GoogleMobileAds.h>

Add the following initalization code to your project's AppDelegate.m. Replace the sample AdMob App ID with your ID:

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
+  [GADMobileAds configureWithApplicationID:@"ca-app-pub-3940256099942544~3347511713"];

Usage

Get ad providers and set consent

import RNAdConsent from 'react-native-ad-consent'

// always request the status of a user's consent first
const consentStatus = await RNAdConsent.requestConsentInfoUpdate({
  publisherId: "pub-1234567890",
})

if (consentStatus === RNAdConsent.UNKNOWN) {
  const isRequestLocationInEeaOrUnknown = await RNAdConsent.isRequestLocationInEeaOrUnknown()

  if (isRequestLocationInEeaOrUnknown) {
    const adProviders = await RNAdConsent.getAdProviders()
    
    // do stuff with ad providers, e.g. show a custom consent modal
    
    await RNAdConsent.setConsentStatus(RNAdConsent.PERSONALIZED)
  }
}

Show Google's consent modal and set consent accordingly

import RNAdConsent from 'react-native-ad-consent'

// always request the status of a user's consent first
const consentStatus = await RNAdConsent.requestConsentInfoUpdate({
  publisherId: "pub-1234567890",
})

if (consentStatus === RNAdConsent.UNKNOWN) {
  const formResponse = await RNAdConsent.showGoogleConsentForm({
    privacyPolicyUrl: "https://your-privacy-link.com",
    shouldOfferAdFree: true,
  })
  
  if (formResponse === RNAdConsent.PREFERS_AD_FREE) {
    // do stuff
  } else {
    await RNAdConsent.setConsentStatus(formResponse)
  }
}

API

Constants

Name Value
NON_PERSONALIZED "non_personalized"
PERSONALIZED "personalized"
UNKNOWN "unknown"
PREFERS_AD_FREE "prefers_ad_free"

Methods

addTestDevice(deviceId: string): Promise<boolean>

Adds a test device ID. See how to get your ID for ios and Android.

The Consent SDK has different behaviors depending on the value of [...] isRequestLocationInEeaOrUnknown(). For example, the consent form fails to load if the user is not located in the EEA. To enable easier testing of your app both inside and outside the EEA, the Consent SDK supports debug options that you can set prior to calling any other methods in the Consent SDK. source

getAdProviders(): Promise<AdProviderItem[]>

type AdProviderItem = {
  id: string,
  name: string,
  privacyPolicyUrl: string,
}

Returns a list of the ad technology providers associated with the publisher IDs used in your app.

isRequestLocationInEeaOrUnknown(): Promise<boolean>

Returns a boolean indicating if the user's consent is needed.

requestConsentInfoUpdate(config: ConsentInfoConfig): Promise<ConsentStatus>

type ConsentInfoConfig = {
  publisherId: string,
}

type ConsentStatus = "non_personalized" | "personalized" | "unknown"

Returns the user's consent status, needs to be called once before any other method is called.

setConsentStatus(status: string): Promise<boolean>

Sets the user's consent choice.

setTagForUnderAgeOfConsent(isUnderAgeOfConsent: boolean): Promise<boolean>

Sets a flag indicating wether the user is under the age of consent.

showGoogleConsentForm(config: ConsentFormObject): Promise<FormResponse>

type ConsentFormObject = {
  privacyPolicyUrl: string,
  shouldOfferAdFree: boolean,
}

type FormResponse = "non_personalized" | "personalized" | "unknown" | "prefers_ad_free"

Shows a Google-rendered consent form. Returns the user's choice as a string.

You should review the consent text carefully: what appears by default is a message that might be appropriate if you use Google to monetize your app; but we cannot provide legal advice on the consent text that is appropriate for you. source

react-native-ad-consent's People

Contributors

ashankz avatar birgernass avatar minhloi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.