firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
826 stars 428 forks source link

Google Analytics for Firebase has not been created #498

Closed amakh closed 4 years ago

amakh commented 4 years ago

Please fill in the following fields:

Unity editor version: 2019.3b Firebase Unity SDK version: 6.6.0 Firebase plugins in use (Auth, Database, etc.): Analytics Additional SDKs you are using (Facebook, AdMob, etc.): None Platform you are using the Unity editor on (Mac, Windows, or Linux): MacOS Catalina Platform you are targeting (iOS, Android, and/or desktop): iOS / Android Scripting Runtime (Mono, and/or IL2CPP):

Please describe the issue here:

I followed this setup : https://firebase.google.com/download/unity On my main scene in unity I added the following setup:

Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
    FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
    FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventLevelStart, new Parameter(FirebaseAnalytics.ParameterLevelName, "Start"));

    var 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.

        var app = Firebase.FirebaseApp.DefaultInstance;
    } else {
        UnityEngine.Debug.LogError(System.String.Format(
        "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
        // Firebase Unity SDK is not safe to use here.
    }
});

Building on my device with Xcode, I have those logs: Note that the first one is saying that Analytics is enabled right ? I did create the app in Firebase and Analytics with the correct bundle ID and I do have the config files in my project. It does actually work on my Android device.

<AppMeasurement>[I-ACS036002] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist

objc[6498]: Class FIRAnalyticsConfiguration is implemented in both /private/var/containers/Bundle/Application/2AD9CCAA-F023-4BFC-A147-12D2C0FF59B7/parlerducanceravectheo.app/parlerducanceravectheo (0x102a1e5e0) and /private/var/containers/Bundle/Application/2AD9CCAA-F023-4BFC-A147-12D2C0FF59B7/parlerducanceravectheo.app/Frameworks/UnityFramework.framework/UnityFramework (0x1064a6900). One of the two will be used. Which one is undefined.

objc[6498]: Class FIRApp is implemented in both /private/var/containers/Bundle/Application/2AD9CCAA-F023-4BFC-A147-12D2C0FF59B7/parlerducanceravectheo.app/parlerducanceravectheo (0x102a1e630) and /private/var/containers/Bundle/Application/2AD9CCAA-F023-4BFC-A147-12D2C0FF59B7/parlerducanceravectheo.app/Frameworks/UnityFramework.framework/UnityFramework (0x1064a6950). One of the two will be used. Which one is undefined.

[Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8.

<AppMeasurement>[I-ACS036000] Found unknown associated object: APMScreen

[Firebase/Analytics][I-ACS023007] Analytics v.60102000 started

<AppMeasurement>[I-ACS023147] Google Analytics for Firebase has not been created. Please, configure Firebase by calling [FIRApp configure]

[Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8.

[Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8.

<AppMeasurement>[I-ACS023147] Google Analytics for Firebase has not been created. Please, configure Firebase by calling [FIRApp configure]

No data are showing in Firebase (it's been 2 days). What do I miss here please? Looks like #101

patm1987 commented 4 years ago

Thanks for your report!

If you don't mind, I'd like you to help me try to work through some things. First, you can debug Analytics stuff in near real time. You can see this blog post about it, and if the iOS specific instructions are a little confusing (they were for me as a primarily Unity-based developer) I briefly go over it in the middle of this blog post (search for "And on iOS it’s a command line argument you pass to your application:"). You'll likely not need to wait any more than a minute or two to see new events coming in on stream view!

Second, your firebase init looks correct. You can try calling SetAnalyticsCollectionEnabled(true) as I do here, but you shouldn't have to if you're grabbing a reference to FirebaseApp as you are above. Let us know if that does fix it though.

Finally, if I could ask you to do a couple of things that will be a little time consuming but will help us immensely since you're in a known bad state: 1) Can you reproduce this in the test app with your current setup (Catalina, Unity 2019.3 beta, Firebase 6.6.0)? 2a) if you can reproduce it in the test app, can you reproduce it in the latest 2019.2 stable release (2019.2.10)? My goal would be to isolate the issue to Unity or the system (possibly Catalina, but we'll go from there). 2b) if you can't reproduce it in the test app, can you check to see if there are any garbage collection/cleanup events that might cause FirebaseAuth to get cleaned up in your current game? I think the best way to test this would be to mark whatever script you call CheckAndFixDependenciesAsync on DontDestroyOnLoad and cache FirebaseAuth in it. An example from a project I'm currently working on is this:

using Firebase;
using Firebase.Auth;
using Firebase.Extensions;
using UnityEngine;
using UnityEngine.Events;

public class FirebaseInit : MonoBehaviour
{
    public UnityEvent OnFirebaseInitialized = new UnityEvent();
    public FirebaseAuth Auth { get; private set; }

    private void Start()
    {
        DontDestroyOnLoad(gameObject);
        FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
        {
            if (task.Exception != null)
            {
                Debug.LogError($"Failed to initialize Firebase with {task.Exception}");
                return;
            }

            Auth = FirebaseAuth.DefaultInstance;

            OnFirebaseInitialized.Invoke();
        });
    }

    private void OnDestroy()
    {
        Auth = null;
    }
}

Historically there have been issues with the Firebase singletons getting cleaned up during scene transitions (or, when those get fixed, with the singletons remaining alive between run cycles in Unity). My goal of 2b is to try to determine if that may be happening.

Let me know if any of that helps, or if you're still in a buggy state! --Patrick

amakh commented 4 years ago

First, thanks for your support and your detailed answer.

I managed to try several things but unfortunately i'm still at the same point:

The same logs appeared in Xcode and still nothing in Firebase with debug mode on. In the testapp when I touch the Show Analytics Instance ID button, it does show me an ID and when I touch on Log I do have this message in Xcode:

[Firebase/Analytics] Event logged. Event name, event params: app_background (_ab), {
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = auto;
    ga_realtime (_r) = 1;
    ga_screen_class (_sc) = UnityDefaultViewController;
    ga_screen_id (_si) = 1305332228125746591;
}

I think this is coming from my setup and maybe from Xcode (v11.1) because again, everything's working with Android. For now I don't have another setup to try. I wanted to build the testapp with Unity 2019.2 but Catalina broke the compatibility with this version (the iOS build is broken).

Do you want me to try other things? I should be able to find another setup for building my app by the end of next week.

amakh commented 4 years ago

@patm1987 I just tried the same project with unity 2019.2 and it worked.

Some stuffs however :

Do you know what could have gone wrong from 2019.2 to 2019.3 and if I can try to change anything manually in the SDK because I really need to build my project with unity 2019.3?

muflub commented 4 years ago

Hi @amakh. Thanks for the extra info. The team will investigate the differences between .2 and .3 and see if we can work out whats going on.

stewartmiles commented 4 years ago

@amakh the "Firebase has not been created" message is spurious and caused by the way we initialize the iOS SDK from the C++ SDK since the initialization flow is pretty different in Unity / games vs. other iOS applications.

IS_ANALYTICS_ENABLED in GoogleService.plist is not used by the current Firebase Analytics iOS SDK. Build time configuration is described in https://firebase.google.com/docs/analytics/configure-data-collection?platform=ios

amakh commented 4 years ago

Hi, do we have any update on this? Actually in unity 2019.2.17f1 nor 2019.3.1 (latest), analytics doesn't show any data on iOS but does with Android. This time I used the latest SDK : 6.10.0 and Xcode 11.3.1

Xcode is showing me this error actually: [Firebase/Analytics][I-ACS901017] Encounter network error. Code, error: -1004, Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={_kCFStreamErrorCodeKey=61, NSUnderlyingError=0x2829505d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <A51C0EA8-F8E4-4CB8-8B14-29BA77F2EBF1>.<2>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <A51C0EA8-F8E4-4CB8-8B14-29BA77F2EBF1>.<2>" ), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=https://cdp.cloud.unity3d.com/v1/events, NSErrorFailingURLKey=https://cdp.cloud.unity3d.com/v1/events, _kCFStreamErrorDomainKey=1}

PS : Is there any release note for the SDK?

amakh commented 4 years ago

Update: Sorry, it looks like my connection was blocking the request to Firebase. I can tell that everything works fine actually!