有没有办法跟踪在 API 内投放的广告?

Is there a way to track ads served from within API?

我已将 Admob 设置为在基于 cordova/ionic 的应用程序中每 30 秒投放一次特定广告。有没有办法在发送新广告或从 API 轮换添加时进行捕获?甚至是一种捕捉用户点击广告的方式?

我知道 Adsense 和 Admob 管理部门提供了所有这些详细信息和报告,但我正在寻找一种方法来对每个用户进行基本捕获 - 即:在单个会话期间为特定用户投放了多少广告应用程序,特定用户是否点击了任何广告等...

您可以使用 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);