Firebase Crashlytics is a lightweight, realtime crash reporter that makes it easy for you to manage stability issues in your app. Crashlytics saves you troubleshooting time by intelligently grouping crashes and highlighting the circumstances that lead up to them.
This guide describes how to integrate Crashlytics into your Unity project so that you can log ad response IDs. Later, when you troubleshoot crashes in your app, you can look up the ad response IDs and use the Ad Review Center in AdMob to find and block the ads.
Шаг 1: Добавьте Firebase в ваше приложение Unity.
Чтобы интегрировать Firebase Crashlytics в Unity, следуйте руководству по интеграции Firebase Unity .
Шаг 2: Зарегистрируйте идентификатор ответа на объявление.
Создайте скрипт MonoBehaviour и инициализируйте SDK AdMob и Firebase. Используйте логическую переменную
isCrashlyticsInitializedдля отслеживания момента инициализации Crashlytics.using GoogleMobileAds.Api; using Fabric.Crashlytics; ... public class GameObjectScript : MonoBehaviour { bool isCrashlyticsInitialized = false; public void Start() { .... // Initialize Google Mobile Ads Unity Plugin. MobileAds.Initialize(initStatus => { }); .... // Initialize Firebase Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => { Firebase.DependencyStatus dependencyStatus = task.Result; if (dependencyStatus == Firebase.DependencyStatus.Available) { Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance; isCrashlyticsInitialized = true; } else { UnityEngine.Debug.LogError(System.String.Format( "Could not resolve all Firebase dependencies: {0}",dependencyStatus)); // Firebase Unity SDK is not safe to use here. } } } }Запросить баннерную рекламу.
using GoogleMobileAds.Api; using Fabric.Crashlytics; ... public class GameObjectScript : MonoBehaviour { public void Start() { ... // Initialize Google Mobile Ads Unity Plugin. MobileAds.Initialize(initStatus => { }); // Initialize Firebase. Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => { Firebase.DependencyStatus dependencyStatus = task.Result; if (dependencyStatus == Firebase.DependencyStatus.Available) { // Create and hold a reference to your FirebaseApp, // where app is a Firebase.FirebaseApp property of your // application class. // Crashlytics will use the DefaultInstance, as well; // this ensures that Crashlytics is initialized. Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance; isCrashlyticsInitialized = true; } else { UnityEngine.Debug.LogError(System.String.Format( "Could not resolve all Firebase dependencies: {0}",dependencyStatus)); // Firebase Unity SDK is not safe to use here. } }); // Request Banner View. this.RequestBanner(); ... } public void RequestBanner() { #if UNITY_ANDROID string adUnitId = "ca-app-pub-3940256099942544/6300978111"; #elif UNITY_IPHONE string adUnitId = "ca-app-pub-1220882738324941/1255739139"; #else string adUnitId = "unexpected_platform"; #endif // Create a 320x50 banner at the top of the screen. this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom); AdRequest request = new AdRequest(); this.bannerView.LoadAd(request); // Called when an ad request has successfully loaded. this.bannerView.OnAdLoaded += this.HandleOnAdLoaded; } }Получите объект
ResponseInfoOnAdLoadedи запишите идентификатор ответа в Crashlytics.public void HandleOnAdLoaded(object sender, EventArgs args) { ResponseInfo responseInfo = this.bannerView.GetResponseInfo(); if (responseInfo != null) { String adResponseId = responseInfo.GetResponseId(); // Log to Crashlytics. if (isCrashlyticsInitialized) { Crashlytics.SetCustomKey("banner_ad_response_id", adResponseId); } } }
That's it! You can now see the most recent banner_ad_response_id in the key section of crash sessions on your Crashlytics dashboard. Note that some keys may take up to four hours to become visible on your dashboard.
