googleads / googleads-mobile-flutter

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

Rewarded Ads are no longer calling Server Side Callback with user_id included despite being logged in; Happened after switching to the new package #180

Closed courtneypresto closed 3 years ago

courtneypresto commented 3 years ago

Bug report

Describe the bug

When logged in as an AUTHENTICATED USER, Rewarded Ads are no longer calling the Server Side callback with an included user_id after switching from the "firebase_admob" package to the "google_mobile_ads" package.

Steps to reproduce

  1. Log in to the client Firebase App
  2. Watch Rewarded Ad
  3. Examine Firebase Function Logs for the Server Side Callback function The function log says: REQUEST:
    {"ad_network":"5450213213286189855",
    "ad_unit":"9495183932",
    "reward_amount":"50",
    "reward_item":"Reward",
    "timestamp":"1618703780685",
    "transaction_id":"3ed476fae24d994c07e4d240dfbc11e3",
    "signature":"MEUCIQDF6u4pLZyCxR7ygZAN9XhAIUTG8EtOv1R3yAz4VwTedQIgHqwN9FyZNRYKo558ImTj3YyRAwiT-8Ib3YrRn2jfQYw",
    "key_id":"3335741209"} 

Everything is correct here except the user_id is missing now.

Expected behavior

The above log should have user_id included. The ad request is definitely happening when a logged in and authenticated user is initiating the request.

Additional context

Server Side Callback:

export const onAdComplete = functions.https.onRequest(async (request, response) => {
    console.log(`REQUEST: ${JSON.stringify(request.query)}`);
    const userWhoEarnedVibe = request.query.user_id;
    const rewardAmount = request.query.reward_amount;
    console.log(`USER ID is: ${userWhoEarnedVibe}`);
    if (userWhoEarnedVibe !== undefined && rewardAmount !== undefined) {
        console.log(`updating vibes...`);
        const rewardAmountInt: number = +rewardAmount;
        //add a vibe to the user who earned the reward    
        await db.doc(`users/${userWhoEarnedVibe}/bank/${userWhoEarnedVibe}`)
            .update({
                "numberOfVibesEarnedByWatchingAds": admin.firestore.FieldValue.increment(rewardAmountInt),
            });
    }
    response.send("complete!");
});

This line: console.log('USER ID is: ${userWhoEarnedVibe}'); ... always outputs: USER ID is: undefined

Note that ONLY thing I changed is migrating to the new package name and updating the client-side code according to the package documentation for calling Rewarded Ads.

I'm DEFINITELY logged in as an authenticated user while calling the Rewarded Ads.

I should also note that I logged into my AdMob portal and verified (again) that the Server Side Callback function IS valid. When I put a dummy user_id in the AdMob portal to test the Callback function, it DOES come in correctly in the log -- so it's not an issue with the Callback function. It seems the user_id is no longer being passed through the ad request.

Code used to call the ad:

myRewarded = RewardedAd(
      adUnitId: rewardedAdID,
      request: AdRequest(
        keywords: <String>[
          'pictures',
          'social',
          'friends',
          'photos',
          'beautiful',
          'video',
          'chat',
          'emojis',
          'magic',
          'funny'
        ],
        testDevices: [
          '4a6f3b42-0664-4aa9-8112-e112cf50f63c',
          '8146eb97fe468821fa02f5cca98649fa'
        ],
      ),
      listener: AdListener(
        // Called when an ad is successfully received.
        onAdLoaded: (Ad ad) {
          numberOfAdsLoaded++;
          print('Ad loaded.');
          print(
              "ad requests: $numberOfAdRequests, ad completes: $numberOfAdCompletes");
          if (numberOfAdRequests > numberOfAdCompletes) {
            print("should show ads");
            showAdsHelper(abortOnFail: true);
          }
        },
        // Called when an ad request failed.
        onAdFailedToLoad: (Ad ad, LoadAdError error) {
          ad.dispose();
          print('Ad failed to load: $error');
          dismissLoadingScreen(); //dismiss loading screen because it finished

          //if we requested an ad...
          if (numberOfAdRequests > numberOfAdCompletes) {
            onAdFail(); //show popup saying the request was denied :(
          }

          //reset everything back to zero because...
          //there is NO ad loading
          //there is no new request and no new complete (these are safe to go back to 0)
          // and no ads loaded
          numberOfAdRequests = 0;
          numberOfAdCompletes = 0;
          numberOfAdsLoading = 0;
          numberOfAdsLoaded = 0;
        },

        // Called when an ad opens an overlay that covers the screen.
        onAdOpened: (Ad ad) {
          numberOfAdCompletes++;
          print('Ad opened.');
        },
        // Called when an ad removes an overlay that covers the screen.
        onAdClosed: (Ad ad) {
          ad.dispose();
          print('Ad closed.');
        },
        // Called when an ad is in the process of leaving the application.
        onApplicationExit: (Ad ad) {
          print('Left application.');
        },
        // Called when a RewardedAd triggers a reward.
        onRewardedAdUserEarnedReward: (RewardedAd ad, RewardItem reward) {
          print('Reward earned: $reward');
          onAdComplete();
        },
      ),
    );

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` ✓] Flutter (Channel stable, 1.22.6, on macOS 11.2.3 20D91 darwin-x64, locale en-US) • Flutter version 1.22.6 at /Users/owner/Developer/flutter/flutter • Framework revision 9b2d32b605 (3 months ago), 2021-01-22 14:36:39 -0800 • Engine revision 2f0af37152 • Dart version 2.10.5 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/owner/Library/Android/sdk • Platform android-30, build-tools 30.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 12.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.4, Build version 12D4e • CocoaPods version 1.10.1 [✓] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin installed • Dart plugin version 201.9245 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) [✓] VS Code (version 1.55.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (2 available) • Droyce Pharxiaggia Dangerfield (mobile) • 00008030-000528C83A0A802E • ios • iOS 13.3 • iPhone 11 Pro Max (mobile) • CF9B76F4-843A-44F4-8A15-A1179CA79C69 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator) • No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` Dart SDK 2.10.5 Flutter SDK 1.22.6 voyce_re_do 1.0.0+1 dependencies: - after_layout 1.0.7+2 [flutter] - auto_size_text 2.1.0 [flutter] - basic_utils 2.7.1 [http logging json_annotation pointycastle convert crypto] - cached_network_image 2.5.1 [flutter flutter_cache_manager octo_image] - cached_video_player 1.0.3 [flutter] - cloud_firestore 0.16.0+1 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web] - cloud_functions 0.9.0 [meta flutter firebase_core firebase_core_platform_interface cloud_functions_platform_interface cloud_functions_web] - csv 4.1.0 - cupertino_icons 0.1.3 - dots_indicator 1.2.0 [flutter] - export_video_frame 0.0.5+4 [flutter] - file_picker 2.1.7 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface] - firebase_analytics 7.0.1 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface] - firebase_auth 0.20.1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter] - firebase_core 0.7.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - firebase_storage 7.0.0 [flutter firebase_core firebase_core_platform_interface firebase_storage_web firebase_storage_platform_interface quiver] - flappy_search_bar 1.7.2 [flutter async flutter_staggered_grid_view] - flushbar 1.10.4 [flutter] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_colorpicker 0.3.5 [flutter] - flutter_datetime_picker 1.5.0 [flutter] - flutter_ffmpeg 0.3.1 [flutter] - flutter_pagination_helper 1.0.1+2 [flutter cupertino_icons] - flutter_slidable 0.5.7 [flutter] - font_awesome_flutter 8.12.0 [flutter] - get 3.26.0 [flutter] - google_fonts 1.1.2 [flutter http path_provider crypto] - google_mobile_ads 0.11.0+4 [meta flutter] - google_sign_in 4.5.9 [google_sign_in_platform_interface flutter meta google_sign_in_web] - http 0.12.2 [http_parser path pedantic] - image_cropper 1.3.1 [flutter] - image_picker 0.6.7+22 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - infinite_listview 1.0.1+1 [flutter] - intl 0.16.1 [path] - like_button 1.0.4 [flutter] - loadmore 1.0.4 [flutter] - palette_generator 0.2.3 [flutter collection path] - path_provider 1.6.28 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows] - provider 4.3.3 [collection flutter nested] - rxdart 0.24.1 - sticky_infinite_list 1.3.0 [flutter] - swipedetector 1.2.0 [flutter] - timeago 2.0.30 - uuid 2.2.2 [crypto convert] - validators 2.0.1 [vin_decoder] - video_thumbnail 0.2.5+1 [flutter] - video_trimmer 0.3.5 [flutter file_picker video_player flutter_ffmpeg video_thumbnail path_provider intl path] - visibility_detector 0.1.5 [flutter] dev dependencies: - flutter_launcher_icons 0.7.5 [image args yaml] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] transitive dependencies: - archive 2.0.13 [crypto args path] - args 1.6.0 - async 2.5.0-nullsafety.1 [collection] - boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner] - characters 1.1.0-nullsafety.3 - charcode 1.2.0-nullsafety.1 - clock 1.1.0-nullsafety.1 - cloud_firestore_platform_interface 3.0.2 [flutter meta collection firebase_core plugin_platform_interface] - cloud_firestore_web 0.3.0+2 [flutter flutter_web_plugins http_parser meta firebase_core firebase_core_web cloud_firestore_platform_interface js] - cloud_functions_platform_interface 4.0.1 [flutter meta firebase_core plugin_platform_interface] - cloud_functions_web 3.1.3 [firebase_core firebase_core_web cloud_functions_platform_interface flutter flutter_web_plugins http_parser meta js] - collection 1.15.0-nullsafety.3 - convert 2.1.1 [charcode typed_data] - crypto 2.1.5 [collection convert typed_data] - fake_async 1.2.0-nullsafety.1 [clock collection] - ffi 0.1.3 - file 5.2.1 [intl meta path] - firebase 7.3.3 [http http_parser js] - firebase_analytics_platform_interface 1.0.3 [flutter meta] - firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta] - firebase_auth_platform_interface 3.1.0 [flutter meta firebase_core plugin_platform_interface] - firebase_auth_web 0.3.3 [flutter flutter_web_plugins meta http_parser intl firebase_core firebase_core_web firebase_auth_platform_interface js] - firebase_core_platform_interface 3.0.1 [flutter meta plugin_platform_interface quiver] - firebase_core_web 0.2.1+3 [firebase_core_platform_interface flutter flutter_web_plugins meta js] - firebase_storage_platform_interface 1.0.4 [flutter meta collection firebase_core plugin_platform_interface] - firebase_storage_web 0.1.1+3 [async crypto firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - flutter_blurhash 0.5.0 [flutter meta] - flutter_cache_manager 2.1.2 [flutter path_provider uuid http path sqflite pedantic clock file rxdart image] - flutter_plugin_android_lifecycle 1.0.11 [flutter] - flutter_staggered_grid_view 0.3.4 [flutter] - flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math] - google_sign_in_platform_interface 1.1.2 [flutter meta quiver] - google_sign_in_web 0.9.2 [google_sign_in_platform_interface flutter flutter_web_plugins meta js] - http_parser 3.1.4 [charcode collection source_span string_scanner typed_data] - image 2.1.19 [archive xml meta] - image_picker_platform_interface 1.1.6 [flutter meta http plugin_platform_interface] - js 0.6.2 - json_annotation 3.1.1 - logging 0.11.4 - matcher 0.12.10-nullsafety.1 [stack_trace] - meta 1.3.0-nullsafety.3 - nested 0.0.4 [flutter] - octo_image 0.3.0 [flutter flutter_blurhash] - path 1.8.0-nullsafety.1 - path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 0.0.4+8 [flutter] - path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface] - path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32] - pedantic 1.9.2 [meta] - petitparser 3.1.0 [meta] - platform 2.2.1 - plugin_platform_interface 1.0.3 [meta] - pointycastle 2.0.1 - process 3.0.13 [file intl meta path platform] - quiver 2.1.5 [matcher meta] - random_string 2.1.0 - sky_engine 0.0.99 - source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph] - sqflite 1.3.2+4 [flutter sqflite_common path] - sqflite_common 1.0.3+3 [synchronized path meta] - stack_trace 1.10.0-nullsafety.1 [path] - stream_channel 2.1.0-nullsafety.1 [async] - string_scanner 1.1.0-nullsafety.1 [charcode source_span] - synchronized 2.2.0+2 - term_glyph 1.2.0-nullsafety.1 - test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.3.0-nullsafety.3 [collection] - vector_math 2.1.0-nullsafety.3 - video_player 1.0.1 [meta video_player_platform_interface video_player_web flutter] - video_player_platform_interface 2.2.0 [flutter meta] - video_player_web 0.1.4+1 [flutter flutter_web_plugins meta video_player_platform_interface] - vin_decoder 0.1.3 [meta basic_utils http random_string] - win32 1.7.4+1 [ffi] - xdg_directories 0.1.2 [meta path process] - xml 4.5.1 [collection convert meta petitparser] - yaml 2.2.1 [charcode collection string_scanner source_span] ```

courtneypresto commented 3 years ago

Update in case anyone stumbles on this in the future...

If you migrated from: firebase_admob: ^0.11.0+2

to: google_mobile_ads: ^0.11.0

Then you'll notice that Google REMOVED the functionality to allow you to pass in a user id to a rewarded ad.

If you still need that functionality then you need to upgrade to version: google_mobile_ads: ^0.12.1

..which requires you to upgrade to Dart 2.

This is annoying if you are using third-party plug ins that haven't migrated yet to Dart 2 (Null Safety).

In my case, I had to:

to be able to continue using Rewarded Ads with Server-Side callbacks.