Use admob on specific tabs


#1

Hi, I’ve just implemented admob into my app and now I want to show the interstitial ad at every two minutes but only on specific pages. The thing is that the count should be on all over the pages and after that to prepare the ad and show it only when I enter on specific page. Right now I have this! But I don’t know how to show it on specific pages after I navigated two minutes on the entire app. Thank you!

var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
interstitial: ‘xxxxxxxx’
};
}
if(window.AdMob) AdMob.prepareInterstitial({
adId:admobid.interstitial,
isTesting:true,
autoShow:false
});
function showAdMinute(){
if(window.AdMob) AdMob.showInterstitial();
};
setInterval(showAdMinute, 2 * 60 * 1000);


#2

Hi, I managed to do something and it works, but first please correct me if I don’t use a good method and the problems are:

  1. If I have 6 tabs only on 2 tabs I’ll show the interstitial. The problem is that if I don’t enter after two minutes into those 2 tabs, the interstitial is prepared again after two minutes. Is this a problem? It will show twice the interstitial?
  2. After the interstitial is prepared, if I enter in tab1 the ads is shown but right after I’ll enter inside tab2 the ad is shown again. I want to show the ad once/2 minutes
  3. If I’m reading an article and I stay there two minutes, the ad is not triggered, only after I read another article or I refresh the tab. The alert() func is triggered!
    This is the method.

service.js

.factory(‘admobFactory’, function(){
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
// banner: ‘xxxx’,
interstitial: ‘xxx’
};
}
var service = {
prepareAdmob: startPrepareAd
}
function startPrepareAd()
{
console.log(“Start preparing ad”);
if(window.AdMob) AdMob.prepareInterstitial({
adId:admobid.interstitial,
isTesting:true,
autoShow:false
});
}
setInterval(startPrepareAd, 2* 60* 1000);
return service;
})

app.js

run(function($ionicPlatform,admobFactory) {

})

and in controller.js the tabs where I want to show the ad

.controller(‘ResultCtrl’, function ($scope){
if(window.AdMob) AdMob.showInterstitial();

})

.controller(‘ReadCtrl’, function ($scope){
if(window.AdMob) AdMob.showInterstitial();

})

Here as you can see I use the same code for each tab. Is there a way to use showInterstitial(); in factory for specific tabs? In this way for surely will work and will not trigger the showInterstitial() twice if I visit the pages exactly after.
Thank you!