Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added npa extras property for GDPR compliance #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions example/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ADTYPES, AdView } from 'titanium-admob';

let appAd;
let ad;
let extras = {npa: 1};

function doShowAd() {
if (!ad) { return; }
Expand All @@ -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);
}
8 changes: 5 additions & 3 deletions example/styles/index.tss
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'.container': {
backgroundColor: 'white'
backgroundColor: 'white',
layout: 'vertical'
}

'Label': {
color: '#000'
}

'#label': {
'.label': {
font: {
fontSize: 12
}
},
top: '30dp'
}
4 changes: 3 additions & 1 deletion example/views/index.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Alloy>
<Window class="container" onOpen="handleOpen">
<Label id="label" onClick="doShowAd">Click to display Ad</Label>
<Label class="label" onClick="loadNpa">Click to load not personalized ad (npa)</Label>
<Label class="label" onClick="loadPa">Click to load personalized ad</Label>
<Label class="label" onClick="doShowAd">Click to display Ad</Label>
</Window>
</Alloy>
21 changes: 17 additions & 4 deletions titanium-admob/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down