// Set a sample device ID of 2077ef9a63d2b398840261c8221a0c9bfirebase::gma::RequestConfigurationrequest_configuration=firebase::gma::GetRequestConfiguration();request_configuration.test_device_ids.push_back("2077ef9a63d2b398840261c8221a0c9b");firebase::gma::SetRequestConfiguration(request_configuration);
重新运行您的应用。如果植入的广告是 Google 广告,则您会在广告(横幅广告、插页式广告或激励广告)顶部的中间部分看到一个测试模式标签:
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Google Mobile Ads C++ SDK is deprecated and will be end-of-maintenance on June 17, 2025; consider using the iOS or Android SDKs instead.\u003c/p\u003e\n"],["\u003cp\u003eDuring development, utilize test ads by using Google's demo ad units or enabling test mode to prevent invalid activity flags on your account.\u003c/p\u003e\n"],["\u003cp\u003eReplace demo ad unit IDs with your own before publishing and remember that Android and iOS simulators are automatically configured as test devices.\u003c/p\u003e\n"],["\u003cp\u003eWhen enabling test mode programmatically, ensure to remove the test device ID code before releasing your app.\u003c/p\u003e\n"],["\u003cp\u003eMediated ads do not display a "Test mode" label; consult each network's mediation guide to ensure test mode is enabled and avoid clicking ads from networks without a confirmed test mode during development.\u003c/p\u003e\n"]]],["The Google Mobile Ads C++ SDK is deprecated as of June 17, 2024, with maintenance ending June 17, 2025; AdMob's iOS and Android SDKs are recommended replacements. To test ads, use Google's demo ad units or enable test mode with your own. Demo units prevent invalid traffic, while test mode lets you configure your device, either in the AdMob UI or programmatically via the SDK, and use your own ad unit IDs. If using mediated ads, ensure each network is in test mode.\n"],null,["# Enabling test ads\n\n| **DEPRECATED:** The Google Mobile Ads C++ SDK is *deprecated* as of June 17, 2024 and should not be adopted in projects that don't already use it. It will enter *End-of-Maintenance (EoM)* on June 17, 2025. Note that versions of the SDK released before the EoM date will continue to function, but no further bug fixes or changes will be released after the EoM date.\n|\n| Instead of the Google Mobile Ads C++ SDK, consider using the\n| [iOS](/admob/ios/quick-start) and\n| [Android](/admob/android/quick-start) SDKs from AdMob.\n| For support, reach out to the\n| [Google Mobile Ads SDK Technical Forum](https://groups.google.com/g/google-admob-ads-sdk).\n\n\u003cbr /\u003e\n\nThis guide explains how to receive test ads in your ads integration. It is\nimportant to use test ads during development so that you can click on them\nwithout charging Google advertisers. If you click on too many ads without being\nin test mode, you risk your account being flagged for invalid activity.\n\nThere are two ways to get test ads:\n\n1. Use one of Google's [demo ad units](#demo_ad_units).\n\n2. Use your own ad unit and [enable test mode](#enable_test_devices).\n\nDemo ad units\n-------------\n\nThe quickest way to enable testing is to use Google-provided demo ad units.\nThese ad units are not associated with your AdMob account, so there's no risk of\nyour account generating invalid traffic when using these ad units.\n| **Key Point:** Make sure you replace these IDs with your own ad unit ID before publishing your app.\n\nHere are demo ad units that point to specific test creatives for each format: \n\n### Android\n\n| Ad format | Sample ad unit ID |\n|-----------------------------------------|------------------------------------------|\n| [Banner](/admob/cpp/banner) | `ca-app-pub-3940256099942544/6300978111` |\n| [Interstitial](/admob/cpp/interstitial) | `ca-app-pub-3940256099942544/1033173712` |\n| [Rewarded](/admob/cpp/rewarded) | `ca-app-pub-3940256099942544/5224354917` |\n\n### iOS\n\n| Ad format | Sample ad unit ID |\n|-----------------------------------------|------------------------------------------|\n| [Banner](/admob/cpp/banner) | `ca-app-pub-3940256099942544/2934735716` |\n| [Interstitial](/admob/cpp/interstitial) | `ca-app-pub-3940256099942544/4411468910` |\n| [Rewarded](/admob/cpp/rewarded) | `ca-app-pub-3940256099942544/1712485313` |\n\nEnable test devices (Test mode)\n-------------------------------\n\nIf you want to do more rigorous testing with production-looking ads, you can now\nconfigure your device as a test device and use your own ad unit IDs that you've\ncreated in the AdMob UI. Test devices can either be added in the AdMob UI or\nprogrammatically using the Google Mobile Ads SDK.\n\nFollow the steps below to add your device as a test device.\n| **Key Point:** Android and iOS simulators are automatically configured as test devices.\n\n### Add your test device in the AdMob UI\n\nFor a simple, non-programmatic way to add a test device and test new or existing\napp builds, use the AdMob UI.\n[Learn how](//support.google.com/admob/answer/9691433).\n| **Key Point:** New test devices typically start serving test ads in your app within 15 minutes, but it can also take up to 24 hours.\n\n### Add your test device programmatically\n\nIf you want to test ads in your app as you're developing, follow the steps below\nto programmatically register your test device.\n\n1. Load your ads-integrated app and make an ad request.\n\n2. Check the console for a message that looks like this:\n\n ### Android\n\n ```c++\n I/Ads: Use RequestConfiguration.Builder.setTestDeviceIds(Arrays.asList(\"33BE2250B43518CCDA7DE426D04EE231\"))\n to get test ads on this device.\"\n \n ```\n\n ### iOS\n\n ```c++\n \u003cGoogle\u003e To get test ads on this device, set:\n GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = @[ @\"2077ef9a63d2b398840261c8221a0c9b\" ];\n \n ```\n\n Copy your test device ID to your clipboard.\n | **Note:** Be sure to remove the code that sets these test device IDs before you release your app.\n3. Modify your code to set the test device ID through `SetRequestConfiguration`:\n\n ```c++\n // Set a sample device ID of 2077ef9a63d2b398840261c8221a0c9b\n firebase::gma::RequestConfiguration request_configuration =\n firebase::gma::GetRequestConfiguration();\n request_configuration.test_device_ids.push_back(\"2077ef9a63d2b398840261c8221a0c9b\");\n firebase::gma::SetRequestConfiguration(request_configuration);\n ```\n4. Re-run your app. If the ad is a Google ad, you'll see a **Test mode** label\n centered at the top of the ad (banner, interstitial, or rewarded ad):\n\nAds with this **Test mode** label are safe to click. Requests, impressions, and\nclicks on ads in test mode will not show up in your account's reports.\n| **Key Point:** Mediated ads do NOT render a **Test mode** label. See the section below for details.\n\nTesting with mediation\n----------------------\n\nGoogle's demo ad units only show Google ads. To test your mediation\nconfiguration, you must use the [enable test devices](#enable_test_devices)\napproach.\n\nMediated ads do not render a **Test mode** label. You are responsible for ensuring\nthat test mode is enabled for each of your mediation networks so that these\nnetworks don't flag your account for invalid activity. See each network's\nrespective [mediation guide](/admob/cpp/mediation) for more\ninformation.\n\nIf you aren't sure whether a mediation ad network adapter provides a test mode,\nit is safest to avoid clicking on ads from that network during development. You\ncan use the `ResponseInfo::mediation_adapter_class_name()` method on any of the\nad formats to figure out which ad network served the current ad."]]