Entrate pubblicitarie a livello di impressione

Quando si verifica un'impressione, l'SDK Google Mobile Ads chiama il gestore di eventi a pagamento con i dati sulle entrate associati. Se implementi questo gestore, puoi utilizzare i dati per calcolare il lifetime value di un utente o inoltrare i dati downstream ad altri sistemi pertinenti.

Questa guida ha lo scopo di aiutarti a implementare l'acquisizione dei dati relativi al lifetime value nelle tue app per iOS.

Prerequisiti

Implementazione del gestore di eventi a pagamento

Ogni formato dell'annuncio ha una proprietà paidEventHandler di tipo GADPaidEventHandler. Durante il ciclo di vita di un evento relativo all'annuncio, l'SDK Google Mobile Ads monitora gli eventi relativi alle impressioni e richiama il gestore con un valore ottenuto.

Swift

class ViewController: UIViewController, GADFullScreenContentDelegate {
  var rewardedAd: GADRewardedAd?
  func requestRewardedAd() {
    GADRewardedAd.load(
      withAdUnitID: "AD_UNIT_ID", request: GADRequest()
    ) { (ad, error) in
      if let error = error {
        print("Rewarded ad failed to load with error: \(error.localizedDescription)")
        return
      }
      if let ad = ad {
        self.rewardedAd = ad
        self.rewardedAd?.paidEventHandler = { adValue in
          // TODO: Send the impression-level ad revenue information to your preferred analytics
          // server directly within this callback.

          // Extract the impression-level ad revenue data.
          let value = adValue.value
          let precision = adValue.precision
          let currencyCode = adValue.currencyCode

          // Get the ad unit ID.
          let adUnitId = ad.adUnitID

          let responseInfo = ad.responseInfo
          let loadedAdNetworkResponseInfo = responseInfo?.loadedAdNetworkResponseInfo
          let adSourceId = loadedAdNetworkResponseInfo?.adSourceID
          let adSourceInstanceId = loadedAdNetworkResponseInfo?.adSourceInstanceID
          let adSourceInstanceName = loadedAdNetworkResponseInfo?.adSourceInstanceName
          let adSourceName = loadedAdNetworkResponseInfo?.adSourceName
          let mediationGroupName = responseInfo?.extrasDictionary["mediation_group_name"]
          let mediationABTestName = responseInfo?.extrasDictionary["mediation_ab_test_name"]
          let mediationABTestVariant = responseInfo?.extrasDictionary["mediation_ab_test_variant"]
        }
      }
    }
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController ()
@property(nonatomic, strong) GADRewardedAd *rewardedAd;
@end

@implementation ViewController
- (void)requestRewardedAd {
  __weak ViewController *weakSelf = self;

  GADRequest *request = [GADRequest request];
  [GADRewardedAd
   loadWithAdUnitID:@"AD_UNIT_ID"
   request:request
   completionHandler:^(GADRewardedAd *ad, NSError *error) {
    if (error) {
      NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
      return;
    }
    self.rewardedAd = ad;
    self.rewardedAd.paidEventHandler = ^void(GADAdValue *_Nonnull value){
      ViewController *strongSelf = weakSelf;
      // TODO: Send the impression-level ad revenue information to your preferred analytics
      // server directly within this callback.

      // Extract the impression-level ad revenue data.
      NSDecimalNumber *value; = value.value;
      NSString *currencyCode = value.currencyCode;
      GADAdValuePrecision precision = value.precision;

      // Get the ad unit ID.
      NSString *adUnitId = strongSelf.rewardedAd.adUnitID;

      GADAdNetworkResponseInfo *loadedAdNetworkResponseInfo =
          strongSelf.rewardedAd.responseInfo.loadedAdNetworkResponseInfo;
      NSString *adSourceName = loadedAdNetworkResponseInfo.adSourceName;
      NSString *adSourceID = loadedAdNetworkResponseInfo.adSourceID;
      NSString *adSourceInstanceName = loadedAdNetworkResponseInfo.adSourceInstanceName;
      NSString *adSourceInstanceID = loadedAdNetworkResponseInfo.adSourceInstanceID;
      NSDictionary<NSString *, id> *extras = strongSelf.rewardedAd.responseInfo.extrasDictionary;
      NSString *mediationGroupName = extras["mediation_group_name"];
      NSString *mediationABTestName = extras["mediation_ab_test_name"];
      NSString *mediationABTestVariant = extras["mediation_ab_test_variant"];
    };
  ]};
}

Per saperne di più sull'origine annuncio vincente, consulta Recuperare informazioni sulla risposta dell'annuncio.

Integrazione con i partner di attribuzione app (AAP)

Per informazioni dettagliate sull'inoltro dei dati sulle entrate pubblicitarie alle piattaforme di analisi, consulta la guida per i partner:

SDK Partner
Regola
AppsFlyer
Singular
Tenjin

Best practice per l'implementazione

  • Imposta il gestore immediatamente dopo aver creato o ottenuto l'accesso all'oggetto annuncio e prima di mostrare l'annuncio. In questo modo non perderai alcun callback di eventi a pagamento.
  • Invia immediatamente le informazioni sull'evento a pagamento al tuo server di analisi preferito nel momento in cui viene chiamato il metodo paidEventHandler. In questo modo puoi evitare di eliminare accidentalmente callback ed evitare discrepanze nei dati.

GADAdValue

GADAdValue è una classe che rappresenta il valore monetario guadagnato per un annuncio, inclusi il codice valuta del valore e il tipo di precisione codificato come di seguito.

GADAdValuePrecision Descrizione
GADAdValuePrecisionUnknown Valore dell'annuncio sconosciuto. Viene restituito quando viene attivato il pingback LTV, ma non sono disponibili dati sufficienti.
GADAdValuePrecisionEstimated Un valore dell'annuncio stimato in base a dati aggregati.
GADAdValuePrecisionPublisherProvided Un publisher ha fornito un valore dell'annuncio, ad esempio i CPM manuali in un gruppo di mediazione.
GADAdValuePrecisionPrecise Il valore esatto pagato per questo annuncio.