From f9c3b8db87e39da0631a9b9652aa93bdfb2dcc02 Mon Sep 17 00:00:00 2001 From: Astrovic Date: Wed, 30 May 2018 12:48:24 +0200 Subject: [PATCH] Added npa extras property for GDPR compliance --- example/controllers/index.js | 25 ++++++++++++++++++------- example/styles/index.tss | 8 +++++--- example/views/index.xml | 4 +++- titanium-admob/index.js | 21 +++++++++++++++++---- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/example/controllers/index.js b/example/controllers/index.js index d554aea..e82ed9a 100755 --- a/example/controllers/index.js +++ b/example/controllers/index.js @@ -1,6 +1,8 @@ import { ADTYPES, AdView } from 'titanium-admob'; +let appAd; let ad; +let extras = {npa: 1}; function doShowAd() { if (!ad) { return; } @@ -15,17 +17,26 @@ function doShowAd() { $.index.open(); function handleOpen() { - const appAd = new AdView({ + appAd = new AdView({ adType: ADTYPES.AD_TYPE_INTERSTITIAL, onAdLoaded: () => { - alert('Ad loaded!'); - }, - onAdClosed: () => { - setTimeout(() => { - appAd.load(); - }, 2500); + if(extras.npa){ + alert('Npa loaded!'); + }else{ + alert('Pa loaded!'); + } } }); ad = appAd.ad; } + +function loadNpa(){ + extras.npa = true; + appAd.load(extras); +} + +function loadPa(){ + extras.npa = false; + appAd.load(extras); +} diff --git a/example/styles/index.tss b/example/styles/index.tss index 03e102c..5fedfbc 100755 --- a/example/styles/index.tss +++ b/example/styles/index.tss @@ -1,13 +1,15 @@ '.container': { - backgroundColor: 'white' + backgroundColor: 'white', + layout: 'vertical' } 'Label': { color: '#000' } -'#label': { +'.label': { font: { fontSize: 12 - } + }, + top: '30dp' } diff --git a/example/views/index.xml b/example/views/index.xml index 963a550..cb66877 100755 --- a/example/views/index.xml +++ b/example/views/index.xml @@ -1,5 +1,7 @@ - + + + diff --git a/titanium-admob/index.js b/titanium-admob/index.js index c3037f7..648643c 100644 --- a/titanium-admob/index.js +++ b/titanium-admob/index.js @@ -4,6 +4,8 @@ const MobileAds = require('com.google.android.gms.ads.MobileAds'); const InterstitialAd = require('com.google.android.gms.ads.InterstitialAd'); const AdRequest = require('com.google.android.gms.ads.AdRequest'); const AdListener = require('com.google.android.gms.ads.AdListener'); +const Bundle = require('android.os.Bundle'); +const AdMobAdapter = require('com.google.ads.mediation.admob.AdMobAdapter'); let hasInitApp = false; @@ -40,14 +42,25 @@ class AdView { this.createInterstitialAdAndroid(); } - if (this.adView !== null) { + /*if (this.adView !== null) { // first time, load already this.load(); - } + }*/ } - load() { - this.adView.loadAd(new AdRequest.Builder().build()); + load(_extras) { + let request = new AdRequest.Builder().build(); + if(_extras){ + if(_extras.npa){ + // https://developers.google.com/admob/android/eu-consent#forward_consent_to_the_google_mobile_ads_sdk + let extras = new Bundle(); + extras.putString("npa", "1"); + request = new AdRequest.Builder() + .addNetworkExtrasBundle(AdMobAdapter.class, extras) + .build(); + } + } + this.adView.loadAd(request); } createInterstitialAdAndroid() {