2017-01-17 98 views
2

我已經設置了我的Admob,以在我的科爾多瓦/離子型應用程序中每隔30秒投放廣告。有什麼方法可以捕獲何時發送新廣告或何時從API旋轉添加?甚至是用戶點擊廣告時的方式?有沒有一種方法可以跟蹤API內的廣告?

我知道Adsense和Admob管理部門提供了所有這些詳細信息和報告,但我正在尋找一種方法來爲每個用戶執行基本捕獲 - 即:在單個會話期間爲特定用戶投放了多少廣告應用程序,特定用戶是否點擊任何廣告等......

回答

2

您可以使用cordova-admob提供的事件來做到這一點。在這裏看到:https://github.com/appfeel/admob-google-cordova/wiki/Events

在這裏你去使用一個完整的事件例如:

var isAppForeground = true; 

function onAdLoaded(e) { 
    // Called when an ad is received. 
    if (isAppForeground) { 
    if (e.adType === admob.AD_TYPE.INTERSTITIAL) { 
     admob.showInterstitialAd(); 
    } 
    } 
} 

function onAdClosed(e) { 
    // Called when the user is about to return to the application after clicking on an ad. Please note that onResume event is raised when an interstitial is closed. 
    if (isAppForeground) { 
    if (e.adType === admob.AD_TYPE.INTERSTITIAL) { 
     setTimeout(admob.requestInterstitialAd, 1000 * 60 * 2); 
    } 
    } 
} 

function onPause() { 
    if (isAppForeground) { 
    admob.destroyBannerView(); 
    isAppForeground = false; 
    } 
} 

function onResume() { 
    if (!isAppForeground) { 
    setTimeout(admob.createBannerView, 1); 
    setTimeout(admob.requestInterstitialAd, 1); 
    isAppForeground = true; 
    } 
} 

function registerAdEvents() { 
    // See https://github.com/appfeel/admob-google-cordova/wiki/Events 
    document.addEventListener(admob.events.onAdLoaded, onAdLoaded); 
    document.addEventListener(admob.events.onAdClosed, onAdClosed); 

    document.addEventListener("pause", onPause, false); 
    document.addEventListener("resume", onResume, false); 
} 

function initAds() { 
    if (admob) { 
    var adPublisherIds = { 
     ios : { 
     banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB", 
     interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII" 
     }, 
     android : { 
     banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB", 
     interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII" 
     } 
    }; 

    var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios; 

    admob.setOptions({ 
     publisherId:   admobid.banner, 
     interstitialAdId:  admobid.interstitial, 
     autoShowInterstitial: false 
    }); 

    registerAdEvents(); 

    } else { 
    alert('AdMobAds plugin not ready'); 
    } 
} 

function onDeviceReady() { 
    document.removeEventListener('deviceready', onDeviceReady, false); 
    initAds(); 

    // display a banner at startup 
    admob.createBannerView(); 

    // request an interstitial 
    admob.requestInterstitialAd(); 
} 

document.addEventListener("deviceready", onDeviceReady, false); 
相關問題