Code Monkey home page Code Monkey logo

cordova-plugin-google-consent's Introduction

cordova-plugin-google-consent

This plugin is an ionic cordova wrapper for the Google Consent SDK. Google consent sdk is used for asking users in the European Economic Area (EEA) for permission to display personalized ads.

Installation

ionic cordova plugin add cordova-plugin-google-consent

Ionic Include

Include the plugin in your app.module.ts

...

import {Consent} from '../../plugins/cordova-plugin-google-consent/www/consent-typescript-wrapper';

...

@NgModule({
  ...

  providers: [
    ...
    Consent
    ...
  ]
  ...
})
export class AppModule { }
})

AdMob Settings

In order to use Google Consent SDK, two points must be fulfilled (see https://developers.google.com/admob/android/eu-consent)

Supported Platforms

  • Android

Methods

  • consent.verifyConsent
  • consent.changeConsentDecision

consent.verifyConsent

Should be called (according to Google) on every app start. Checks and returns consent of the user. If the user has not made any consent decision yet, it asks the users for consent. If the user is not located in the EEA, no dialog is presented to the user. Only users in EEA can make a decision.

Params

verifyConsent(publisherIds :Array<string>, privacyPolicyUrl :string, showProVersionOption :boolean, isDebug :boolean) :Promise<ConsentResult>
  • publisherIds: Array of all your AdMob ID's used in the app. (see https://support.google.com/admob/answer/2784578)
  • privacyPolicyUrl: URL to your GDPR conform privacy policy.
  • showProVersionOption: If set to true, on the dialog is shown an option to the user, where he can choose to buy an ad-free pro version.
  • isDebug: If set to true, the device acts like it is in the EEA, even if it is not.

Result

interface ConsentResult {
	consent: "PERSONALIZED" | "NON_PERSONALIZED" | "UNKNOWN" | null; // is UNKNOWN in case of the user has chosen to buy the pro option
	isAdFree: boolean; // user has chosen the "buy the pro version" option on the dialog
	hasShownDialog: boolean; // if false, user already made a decision earlier and there was no need to show the dialog
	isNotInEea: boolean; // if true, user is not in EEA and can make no decision. No dialog has been shown to the user if this is the case. Ignore other results if this is the case, you can show personalized ads without asking.
}

Example (Ionic)

this.consent.verifyConsent(["pub-123xxxxxxx"], "https://www.mycoolapp.com/privacy",	true, false)
			.then((result) => {
				console.log(result);
			})
			.catch((error) => {
				console.log(error);
			});

Example (Cordova)

window['Consent'].verifyConsent(publisherIds, privacyPolicyUrl, showProVersionOption, isDebug,
				function(result) {/* do something with the result */},
				function(error) {/* handle the error case */}
			);

consent.changeConsentDecision

Method to change the made decision later. This option should be offered to the user in the settings, that he can change his decision at any time. This method has no check if a user is really in the EEA or not, the dialog is shown to every user. Use method verifyConsent first to determine if a user is in EEA or not.

Params

changeConsentDecision(privacyPolicyUrl :string, showProVersionOption :boolean) :Promise<ConsentResult>
  • privacyPolicyUrl: URL to your GDPR conform privacy policy.
  • showProVersionOption: If set to true, on the dialog is shown an option to the user, where he can choose to buy an ad-free pro version.

Result

interface ConsentResult {
	consent: "PERSONALIZED" | "NON_PERSONALIZED" | "UNKNOWN" | null; // is UNKNOWN in case of the user has chosen to buy the pro option
	isAdFree: boolean; // user has chosen the to buy the pro option on the dialog
	hasShownDialog: boolean; // in this case is always true
	isNotInEea: boolean; // in this case is always false, because there is no check if the user is really in EEA or not
}

Example (Ionic)

this.consent.changeConsentDecision("https://www.mycoolapp.com/privacy", true)
			.then((result) => {
				console.log(result);
			})
			.catch((error) => {
				console.log(error);
			});

Example (Cordova)

window['Consent'].changeConsentDecision(privacyPolicyUrl, showProVersionOption,
				function(result) {/* do something with the result */},
				function(error) {/* handle the error case */}
			);

cordova-plugin-google-consent's People

Contributors

tobyherrmann 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.