0.2.1 • Published 6 years ago

cordova-plugin-google-consent v0.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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.

News

Version 0.2.0 / 2018-08-24: Plugin now supports iOS as platform. Many thanks to einaregilsson and RaudasHugbunadur, who created the iOS version of the plugin.

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
  • iOS

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 user 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 */}
			);

iOS specific issues

When installing the plugin on iOS it will download the Google Consent SDK and install it as a CocoaPod. It will also create a yourprojectname.xcworkspace file. To build your project for iOS you will need to open the .xcworkspace file in XCode and build it there, the command line build does not work correctly with workspaces instead of projects.