Unity 2021.3.14f1 Stop Analytics Service from initializing when unused?

Hoping to find a way to stop some automatic start-up behavior by Unity Analytics service.

We're on Unity 2021.3.14f1 and have Unity IAP, which requires the new Unity Analytics service package.

We're not using this service, but it keeps spawning an error in console during early development.

"No cloud project ID was found by the Analytics SDK. This means Analytics events will not be sent. Please make sure to link your cloud project in the Unity editor to fix this problem."

We do AnalyticsService.Instance.SetAnalyticsEnabled(false) in [RuntimeInitializeOnLoadMethod], but AnalyticsService.Instance will lead to a call to AnalyticsServiceInstance(), which spawns that error message.

Also, AnalyticsLifetime.cs static ContainerObject still creates a DontDestroyOnLoad GameObject named AnalyticsContainer (with intended AnalyticsLifetime component), which also calls AnalyticsService.internalInstance during Awake().

Any call to AnalyticsService will also create the internal instance which will print out this error message.

    public static class AnalyticsService
    {
        internal static AnalyticsServiceInstance internalInstance = new AnalyticsServiceInstance();

        public static IAnalyticsService Instance => internalInstance;
    }

AnalyticsLifetime's Awake() also incurs a FindObjectsOfType call on the first scene (with an interesting comment), and all the while we're not using the Analytics service.

        void Awake()
        {
            Instance = this;
            hideFlags = HideFlags.NotEditable | HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild;

#if !UNITY_ANALYTICS_DEVELOPMENT
            hideFlags |= HideFlags.HideInInspector;
#endif

            DontDestroyOnLoad(gameObject);

            // i hate this, but i don't know of a better way to know if we're running in a test..
            var mbs = FindObjectsOfType<MonoBehaviour>();
            foreach (var mb in mbs)
            {
                if (mb.GetType().FullName == "UnityEngine.TestTools.TestRunner.PlaymodeTestsController")
                {
                    return;
                }
            }

            AnalyticsService.internalInstance.Startup();
        }

Is there any way to remove all of these unwanted start-up activities and still use Unity IAP?

Thank you.

Hey monstronauts,

Thanks for reaching out! The error you're receiving is because you haven't linked your project with your Unity account in the Editor. You can find out how to do that Here. Once that's done, you shouldn't have the start-up activities that come with Unity Analytics (due to the SetAnalyticsEnabled(false) snippet).

In order to use the Unity In-App Purchasing package, Unity Gaming Services needs to be initialized first followed by the initialization of Unity In-App Purchasing.

Best,
Randy