googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.38k stars 1.08k forks source link

Impression level Ad-Revenue improvements #2737

Closed snappedToGrid closed 1 year ago

snappedToGrid commented 1 year ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

Steps to reproduce:

This is a mix of a documentation and feature request for better testing options with OnAdPaid implementation. I'm trying to implement "Impression level Ad-Revenue" so I could send ad revenue data to Facebook and track how profitable my campaigns are for each campaign. I'm facing multiple problems:

  1. The AdValue object has a "CurrencyCode" field, but it doesn't say how this value is determined. Is this according to the account's currency? Or could this be a changing value depending on the publisher, viewer etc. and maybe I'd have to deal with converting it.
  2. I tried testing this by logging the values, and deploying it on a test device, and I did get "Ad Revenue: 1628146 Precision: Precise Currency: USD" which is somewhat helpful, but can I trust that USD will remain the currency with real ads on production, even though my account is set to NIS?
  3. This is more of a general code architectures request, but for AdRevenue I don't really need an instance level event, and would have preferred to have a static event to deal with tracking the AdRevenue. Having an instance event requires me to have lots of duplicate code in different classes all registering and unsubscribing to that event every time an ad needs to be loaded.

Imagine having this code across many different classes that create ads:

`private void StartLoadAd() { if (_ad != null) { _ad.OnAdPaid -= AdmobService.OnAdPaid; _ad.Destroy(); _ad = null; } AdmobService.Instance.LoadRewardedAd(AdPlacement.Mayor, AdLoadCallback); }

    private void AdLoadCallback(RewardedAd ad, LoadAdError error)
    {
        if (error != null || ad == null)
        {
            Debug.LogError("Rewarded ad failed to load an ad " +
                           "with error : " + error);
            return;
        }

        _ad = ad;
        _ad.OnAdPaid += AdmobService.OnAdPaid;
    }`

I would have submitted part of this as a review to the documentation, but unlike what the instructions here say, there's no "Send Feedback" button in the admob documentation website, only thumbs up/down which don't allow for more detailed feedback. Maybe that's a bug of its own?

Thank you.

NVentimiglia commented 1 year ago

Hi @snappedToGrid

public static class AdPaidHandler
{
    public static void OnAdPaid(AdValue value)
    {
        // Common logging logic.
    }
}

void Start()
{
    RewardedAd.Load((RewardedAd ad, LoadAdError error) =>
    {
        // {Sanity Here}
        ad.OnAdPaid += AdPaidHandler.OnAdPaid;
    });
}