googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
335 stars 272 forks source link

The new setServerSideOptions is not working #703

Closed chinloyal closed 1 year ago

chinloyal commented 1 year ago

I've upgraded to the latest version of this plugin (v2.3.0) and used the new setServerSideOptions setter, it does not seem to be triggering my cloud function for verifying rewards, it worked before on versions that didn't have setServerSideOptions.

I've also tried v2.1.0 none of them work.

This is the snippet of me trying to do so:

RewardedAd.load(
        adUnitId: AppAdmob.getRewardAdUnitId(unitId),
        request: AdRequest(),
        rewardedAdLoadCallback: RewardedAdLoadCallback(
          onAdLoaded: (ad) {
            final options = ServerSideVerificationOptions(
              userId: _authService.user!.uid,
            );

            ad.setServerSideOptions(options).then((value) {
              ad.show(onUserEarnedReward: (adWithoutView, reward) {
                log("Reward: ${reward.amount}");
              });
            });
          },
          onAdFailedToLoad: (loadAdError) {
            errorMessage = loadAdError.message;
          },
        ),
      );

Also there is no documentation on how to do this on the official docs https://developers.google.com/admob/flutter/quick-start. There's mo SSV section under advanced topics like for the Android/iOS SDKs

Flutter doctor:

[✓] Flutter (Channel stable, 3.3.8, on macOS 12.3 21E230 darwin-x64, locale en-WS)
    • Flutter version 3.3.8 on channel stable at /Users/chinloyal/fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 52b3dc25f6 (2 weeks ago), 2022-11-09 12:09:26 +0800
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /usr/local/share/android-sdk
    • Platform android-33, build-tools 30.0.3
    • ANDROID_SDK_ROOT = /usr/local/share/android-sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13E113
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.70.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (4 available)
    • SM A207M (mobile)                   • R9AMB21AQZJ                          • android-arm64  • Android 11 (API
      30)
    • iPhone SE (3rd generation) (mobile) • 7186C399-D8F4-4C91-8A7C-154D2B3D86B8 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
    • macOS (desktop)                     • macos                                • darwin-x64     • macOS 12.3 21E230
      darwin-x64
    • Chrome (web)                        • chrome                               • web-javascript • Google Chrome
      107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
huycozy commented 1 year ago

@chinloyal Can you describe more clearly how it doesn't work? From my end, I can see the reward info from callback after ads is shown:

I/flutter (14306): Reward: 10 - coins

Using sample code at https://github.com/googleads/googleads-mobile-flutter/tree/main/packages/google_mobile_ads/example and update snippet code as below:

Snippet sample code ```dart void _createRewardedAd() { RewardedAd.load( adUnitId: Platform.isAndroid ? 'ca-app-pub-3940256099942544/5224354917' : 'ca-app-pub-3940256099942544/1712485313', request: request, rewardedAdLoadCallback: RewardedAdLoadCallback( onAdLoaded: (RewardedAd ad) { print('$ad loaded.'); _rewardedAd = ad; _numRewardedLoadAttempts = 0; final options = ServerSideVerificationOptions( userId: '_authService.user!.uid', ); ad.setServerSideOptions(options).then((value) { ad.show(onUserEarnedReward: (adWithoutView, reward) { print("Reward: ${reward.amount} - ${reward.type}"); }); }); }, onAdFailedToLoad: (LoadAdError error) { print('RewardedAd failed to load: $error'); _rewardedAd = null; _numRewardedLoadAttempts += 1; if (_numRewardedLoadAttempts < maxFailedLoadAttempts) { _createRewardedAd(); } }, )); } ```
chinloyal commented 1 year ago

@huycozy Yes the onUserEarnedReward callback gets fired but my firebase cloud function is not being triggered to verify the ad view.

You can see below I've verified that it works on the admob portal:

Screen Shot 2022-11-23 at 6 32 25 AM
chinloyal commented 1 year ago

Also for more context I reward the users using the firebase function in firestore not from the client. But that firebase function is no longer being triggered when I call setServerSideOptions, and so the user doesn't receive a reward after watching the ad

chinloyal commented 1 year ago

I've figured out why it's not working. In debug mode I was using the testRewardAdUnitId, instead of the production one. I tested using the production id, and it worked.