How does Google Analytics calculate the Browser Size metric that it reports for user sessions?
Another thing that would be helpful would be a way to modify a browser to replicate the "(not set)" reporting in Google Analytics.
There is no documentation on the logic they are using that we can find.
This is roughly their algorithm as far as we can tell:
- Get the window.innerWidth or the document.body.clientWidth or the window.outerWidth...
- Round that to the nearest 10.
- Do basically the same for height.
- If either can't be calculated for whatever reason, return "(not set)".
- But if we can get both values, return "widthxheight" i.e. "680x800".
The thing is, step 1 could be done in a variety of ways, and so far in our attempts to equally replicate, we have been unsuccessful.
Background: Long story short, we have a lot of bot traffic, and we've been able to filter them out with GA's Browser Size metric.
These bots all report in GA a Browser Size of "(not set)".
We intend to block all of these bots on our caching service (which can't run any client-side js).
So to do this, we are setting a cookie in a user's session when they visit if they have that browser size and then the caching service can see that cookie and block.
But our attempts to create this cookie have created too many false positives, so we're missing something from GA's algorithm.