Unity 2018 hits don't show in Google Analytics

Since moving to Unity 2017/2018 from Unity 5.6, suddenly analytic data to Google Analytics does not arrive anymore.
The server says 200 (ok) and there are no errors whatsoever. If the same url is used in the browser, the hit shows as expected.
When comparing the traffic between a working 5.6 version and a non-working 2018 version, there is almost no difference:

GET
https://www.google-analytics.com/collect?v=1&ul=en&sr=1
>>	blablathequery
HTTP/1.1

Host: www.google-analytics.com
Accept: */*
Accept-Encoding: identity
User-Agent: UnityPlayer/
>>	5.6.6f2 (http://unity3d.com)

X-Unity-Version: 
>>	5.6.6f2

vs

GET
https://www.google-analytics.com/collect?v=1&ul=en&sr=1
>>	blablatheexactsamequery
HTTP/1.1

Host: www.google-analytics.com
Accept: */*
Accept-Encoding: identity
User-Agent: UnityPlayer/
>>	2018.2.19f1 (UnityWebRequest/1.0, libcurl/7.52.0-DEV)

X-Unity-Version: 
>>	2018.2.19f1

Content-Type: application/x-www-form-urlencoded

So what gives?

Okay, I actually already know the answer, but I want to help people with the same issue (including future me). Here it comes:

Unity 2018 is registered as a known bot or spider in the IAB/ABC International Spiders & Bots List!


What the flying f*? That’s what I spent the last four days rebuilding my analytics code in all possible configurations for?

Well. Turns out there is a little checkbox in Google Analytics > Admin > View Settings > “Exclude all hits from known bots and spiders”.

When checked, if the user-agent is 5.6, it tracks just fine. If it’s 2018, it gets ignored.

Apparently, the user-agent and X-Unity-Version of UnityWebRequest can not be changed. Which means I have to disable the checkbox in order to still be able to receive hits. Goddarnit.

I’m not filing a bug report since Google doesn’t care (it’s not their list) and neither will Unity since they have their own analytics solution to sell.


So there, future self. Don’t you ever tick that box.


Edit: thank you @SimonBVolume for suggestion this solution. You can modify the HTTP request’s client data and then GA will not treat it as a bot (in GoogleAnalyticsMPV3.HandleWWW)

myUnityWebRequest.SetRequestHeader( "User-Agent", "UnityPlayer/2019.2.9f1" );

For anyone else who finds this and doesn’t want to open their Analytics up to bots, I contacted IAB after reading this post. They were able to explain that the issue is with Unity’s User Agent as it’s non standard and had bot flags in it. The solution is very simple, override the user agent with something sensible. The following worked for me and I can now keep bot protection on.

myUnityWebRequest.SetRequestHeader( “User-Agent”, “UnityPlayer/2019.2.9f1” );