cordova-consent-modern-plus
v0.1.2
Published
Standalone Cordova consent plugin for modern iOS and Android builds.
Maintainers
Readme
cordova-consent-modern-plus
Cordova consent plugin for current iOS and Android toolchains using Google's User Messaging Platform SDK.
Install
cordova plugin add cordova-consent-modern-plusYou can also persist it in config.xml:
<plugin name="cordova-consent-modern-plus" spec="0.1.2" />Required app config
This plugin uses Kotlin on Android and App Tracking Transparency on iOS.
<platform name="android">
<preference name="GradlePluginKotlinEnabled" value="true" />
<preference name="GradlePluginKotlinVersion" value="2.1.0" />
</platform>
<platform name="ios">
<edit-config file="*-Info.plist" mode="merge" target="NSUserTrackingUsageDescription">
<string>This identifier will be used to manage consent and advertising preferences.</string>
</edit-config>
</platform>Global
The plugin exposes a global consent object after deviceready.
Basic example
document.addEventListener("deviceready", async () => {
try {
await consent.requestInfoUpdate();
await consent.loadAndShowIfRequired();
const canRequestAds = await consent.canRequestAds();
console.log("canRequestAds:", canRequestAds);
if (canRequestAds) {
// Safe point to start your ad SDK.
}
} catch (err) {
console.error("Consent flow failed", err);
}
});Full consent flow
document.addEventListener("deviceready", async () => {
try {
await consent.requestInfoUpdate({
debugGeography: consent.DebugGeography.EEA,
tagForUnderAgeOfConsent: false,
testDeviceIds: []
});
console.log("form status:", await consent.getFormStatus());
console.log("consent status:", await consent.getConsentStatus());
await consent.loadAndShowIfRequired();
console.log("privacy requirement:", await consent.privacyOptionsRequirementStatus());
console.log("can request ads:", await consent.canRequestAds());
} catch (err) {
console.error(err);
}
});Show privacy options again
async function openPrivacyOptions() {
try {
await consent.showPrivacyOptionsForm();
} catch (err) {
console.error("Privacy options failed", err);
}
}Manual form loading
async function loadAndShowForm() {
try {
const form = await consent.loadForm();
await form.show();
} catch (err) {
console.error("Manual form flow failed", err);
}
}iOS tracking authorization
These methods return false on non-iOS platforms.
async function requestTracking() {
const current = await consent.trackingAuthorizationStatus();
console.log("tracking status:", current);
const updated = await consent.requestTrackingAuthorization();
console.log("tracking result:", updated);
}With cordova-ad-modern-plus
document.addEventListener("deviceready", async () => {
try {
await consent.requestInfoUpdate();
await consent.loadAndShowIfRequired();
if (await consent.canRequestAds()) {
const info = await admob.start();
console.log("AdMob started:", info.version);
}
} catch (err) {
console.error(err);
}
});Events
The plugin emits:
document.addEventListener("consent.ready", () => {
console.log("Consent plugin ready");
});API
await consent.requestInfoUpdate(options);
await consent.loadAndShowIfRequired();
await consent.showPrivacyOptionsForm();
await consent.canRequestAds();
await consent.getConsentStatus();
await consent.getFormStatus();
await consent.privacyOptionsRequirementStatus();
await consent.trackingAuthorizationStatus();
await consent.requestTrackingAuthorization();
await consent.reset();
const form = await consent.loadForm();
await form.show();Build
npm install
npm run buildLicense
MIT.
