Events fail to upload on Android, works in editor and Windows build

Hi,

I’m using Unity 2020.3.28f1 and Analytics 3.0.0-pre.3.

I thought my Analytics configuration and workflow was ok since everything was working fine in the editor (default events, custom event), however when building and testing on Android, no events are sent.

Serializing is fine, it’s just the sending that fails, as I could see after having activated logging via UNITY_ANALYTICS_EVENT_LOGS : Events failed to upload (code 400) – will retry at next heartbeat. It fails both on default and custom events.

Can I get some additional debugging information concerning this error? I’ve tried to check/uncheck Development Build but it has no effect, either on the problem or on the logging.

I’ve tried to build for Windows and everything works as it should. Maybe there is some obvious Android configuration pitfall I have missed?

Hey @Brice-Joly

I’ll look into getting some more information, but 400 (bad request) suggests something is going wrong with the serialization and perhaps we’re not sending valid info to the platform.
The desire response is a 204 - is it possible for you to intercept the content being sent up to the analytics platform?

We’ve noticed that some users with different localisations are recording floating point parameters with commans instead of full stops to mark where the decimal begins, that’s something we’re working towards correcting in subsequent package releases.

Happy to go dig up some instructions for you if getting that request payload isn’t something you’re familiar with.

Thanks for your answer. The localisation is FR_fr so that may be related, although my Windows OS is in FR_fr too and since it works in the editor and in the Windows build, that sounds unlikely. I haven’t seen floats in the default events and I don’t have any in my custom event anyway.

Please, that would help. I’ve tried to install Charles and use it as a proxy but I couldn’t get it to work.

1 Like

Please share your code. Did you initialize Analytics in your script? Ensure that you aren’t sending events in Update() for example, before your initialization code. And you mentioned Charles didn’t work, can you elaborate? Which step didn’t work for you? https://support.unity.com/hc/en-us/articles/115002917683-Using-Charles-Proxy-with-Unity

Unity Analytics beta initialization code example:

 async void Start()
    {
        string consentIdentifier = "";
        bool isOptInConsentRequired = false;

        try
            {

            var options = new InitializationOptions();
            options.SetAnalyticsUserId("my_test");

            await UnityServices.InitializeAsync();
                List<string> consentIdentifiers = await Events.CheckForRequiredConsents();
                if (consentIdentifiers.Count > 0)
                {
                    consentIdentifier = consentIdentifiers[0];
                    isOptInConsentRequired = consentIdentifier == "pipl";
                }
                if (isOptInConsentRequired)
                {
                    Events.ProvideOptInConsent(consentIdentifier, false);
                }
            }
            catch (ConsentCheckException e)
            {
                Debug.Log("Error reason = " + e.Reason.ToString());
            }

        Debug.Log("Done with Start!");
     }
2 Likes

Thanks for posting a more detailed example, which solved the problem.

Events.ProvideOptInConsent() is mandatory in EU where the GPRD is required, unfortunately it is not in the code of the official documentation and since there is not dedicated error message, it’s pretty much impossible to find out what is wrong and how to fix it.

Yes, we are working to improve the documentation.

1 Like

I am dealing with the same problem that @ -Joly described. I’m also using Unity 2020.3.28f and Analytics 3.0.0-pre.3. Here is my code for initializing Unity Analytics beta:

public async void Initialize() {
    var options = new InitializationOptions();
    string consentIdentifier = "";
    bool isOptInConsentRequired = false;

    #if DEBUG
        options.SetEnvironmentName("development");
     #else
        options.SetEnvironmentName("production");
    #endif

    try {
        await UnityServices.InitializeAsync();
        List<string> consentIdentifiers = await Events.CheckForRequiredConsents();
        if (consentIdentifiers.Count > 0) {
            consentIdentifier = consentIdentifiers[0];
            isOptInConsentRequired = consentIdentifier == "pipl";
        }
        if (isOptInConsentRequired) {
            Events.ProvideOptInConsent(consentIdentifier, false);
        }
    } catch (ConsentCheckException e) {
        Debug.Log("Error reason = " + e.Reason.ToString());
    }
}

@christopher_hof Can you describe your issue? Bryce described their solution.

Initialize() is called on Start() from my GameManager. I can see Events being recorded and uploaded successfully if I run the app in Unity Editor and on my iPad. Even the environment detection seems to be working fine. If I run the app on an Android device however, I can see Events being recorded, but as soon as they are uploaded it says Events failed to upload (code 400) – will retry at next heartbeat. I am not recording any custom events only the defaults events are recorded.

So you are running adb logcat to see this error?

I Build and Run the app from within Unity and Autoconnect Profiler to see the log messages in the Editor Console.

Got it. What Android device are you testing on? (as opposed to an emulator) And this device has internet access? I will test on my Samsung device here

I have tested the app on an Samsung Galaxy Tab A7 and an OnePlus Nord N100. They both have internet access. Same results.

@christopher_hof We think we may know the cause of the issue. Where are you located? Some locales (like Spain) use a comma as the decimal separator which confuses our JSON parser. We are working on a fix for this, if so.

I am located in Germany and use German and English locale. I have tried to set my device language to English as well, without success.

Got it. A Charles Proxy capture would confirm, but we should have an update available soon if you might want to wait. https://support.unity.com/hc/en-us/articles/115002917683-Using-Charles-Proxy-with-Unity

I will try to set up Charles Proxy, otherwise I am hoping for the update to fix it. Thank you for your assistance @JeffDUnity3D

1 Like

It may be a bit of a pain to get Charles Proxy working, you would likely need to directly edit the manifest in the project to obtain an unencrypted capture. There is a charlesproxy.unitypackage that is meant to do this, but it may be outdated.

I can confirm, after setting my device language to English one again and also setting the date format to 24-four format (not sure if thats really necessary), the events were uploaded successfully and are listed in the Event Browser.

1 Like

Hey Christopher,

That’s great to hear. The underlying issue is fixed in the next version of the Analytics package, due out very soon - after which issues with certain locales experiencing 400 upload errors should be fixed.

1 Like