Unity analytics failing when running through apk(Quest Devices 2-3) but working fine in editor

Hi,
I am using 2022.3.30f1 and analytics 6.0.2(also tried to rollback to 5.1.1 which was installed on my older project and is working)
Using ENG US locale
i have attached a logcat screenshot of the error i am facing.
All the custom and default events are being recorded when played through the editor but nothing when building apk
Events in the screenshot are logged from bottom to top, with most recent being at top.

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Services.Analytics;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
using UnityEngine;

public class UGS_Analytics : MonoBehaviour
{

    [HideInInspector] public bool isInitialized = false;
    [HideInInspector] public double sceneTimer = 0;


    async void Start()
    {
        int retryCount = 6; // Number of retries
        int currentAttempt = 0;

        while (currentAttempt < retryCount)
        {
            try
            {
                Debug.LogError("Initializing Unity Services...");
                var options = new InitializationOptions();
                options.SetEnvironmentName("production");
                await UnityServices.InitializeAsync(options);
                Debug.LogError("Unity Services initialized successfully.");
                GiveConsent(); // Get user consent according to various legislations
                SetAquisitionSource();
                isInitialized = true;
                break; // Exit the loop if successful
            }
            catch (Exception e)
            {
                currentAttempt++;
                Debug.LogError($"Error during initialization (Attempt {currentAttempt}): {e.ToString()}");
                if (currentAttempt >= retryCount)
                {
                    Debug.LogError("Max retry attempts reached. Initialization failed.");
                }
                else
                {
                    Debug.LogError("Retrying initialization...");
                }
            }
        }
    }
    void Update()
    {

        if (isInitialized)
        {

            sceneTimer++;
            Debug.LogError($"Scene Timer updated: {sceneTimer}");
            CustomEvent phaseTimeEvent = new CustomEvent("timeSpentInPhase") {
        { "Scene_ID", 0 },
        { "demoPhaseID", 0 },
        { "phaseTime", sceneTimer} };
            Debug.LogError("Recording phase time event.");
            AnalyticsService.Instance.RecordEvent(phaseTimeEvent);
            AnalyticsService.Instance.Flush();
        }
    }

    private void SetAquisitionSource()
    {
        Debug.LogError("Setting acquisition source...");
        var acquisitionSource = new AcquisitionSourceEvent()
        {
            AcquisitionChannel = "SideQuest",
        };
        AnalyticsService.Instance.RecordEvent(acquisitionSource);
        AnalyticsService.Instance.Flush();
        Debug.LogError("Acquisition source recorded.");
    }

    public void GiveConsent()
    {
        Debug.LogError("Giving consent for data collection...");
        AnalyticsService.Instance.StartDataCollection();
        Debug.LogError("Consent has been provided. The SDK is now collecting data!");
    }
}

this is my code after trying a lot but still failing to log any analytics event through the .apk when installed on quest2,3 devices, Am i missing something?

Hi,

The error message indicates a Network error. Please double check that your device is online and your app has any necessary permissions to make network requests.

I notice that you are recording events in an Update function. This is a very bad idea, it will generate a ridiculous number of events and in this case, may be the cause of your problem. You are perhaps flooding the app with more network requests than it can handle.

Hey,
thanks alot just double checked there was a network issue, In my xml the permissions were there but due to a checkbox in the OpenXR setting it was getting removed while building the apk


working great now.
The update functionality was temporarily for debugging build, not using it in the actual build, thanks though :+1:

1 Like