Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operating System on User Agent #43

Open
IvanRF opened this issue Sep 1, 2017 · 12 comments
Open

Operating System on User Agent #43

IvanRF opened this issue Sep 1, 2017 · 12 comments

Comments

@IvanRF
Copy link

IvanRF commented Sep 1, 2017

I started testing the stable version (v1.1.2) but I think this issue is still present on 2.0.

When sending a post to GA the userAgent in my case is:

java/1.8.0_112-b15/Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/Windows 10/10.0/amd64

It includes the OS data but I guess the format is not correct or at least is not the one that GA expects.

User Agent Override

Example value: Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14
Example usage: ua=Opera%2F9.80%20%28Windows%20NT%206.0%29%20Presto%2F2.12.388%20Version%2F12.14

The first part is correctly gathered by GA:
Browser: java
Browser Version: 1.8.0_112-b15

but then the rest is empty:
Operating System: (not set)

I just made a test overriding the user agent:

defaultRequest.userAgent("Java/1.8.0_112-b15 (Windows NT 10.0; Win64; x64)");

Now I have to wait until GA audience reports are available, but I will share if that format works.

@brsanthu
Copy link
Owner

brsanthu commented Sep 1, 2017

thank you. Please check if that new format works and we can make that as default. Btw, are you using version2? Version 1 is not going to be updated going forward.

@IvanRF
Copy link
Author

IvanRF commented Sep 1, 2017

I can confirm it works:
Operating System: Windows
Operating System Version: 10

To test it faster I used the version on Central Repository. Do you plan to upload v2.0?

@IvanRF
Copy link
Author

IvanRF commented Sep 1, 2017

In order to dynamically build the user agent string, I'm testing this code now:

OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
defaultRequest.userAgent("Java/" + System.getProperty("java.version") + " (" + os.getName() + "; " + os.getArch()+ ")");

which in my case sets Java/1.8.0_112 (Windows 10; amd64), not equal but similar 😃

@brsanthu
Copy link
Owner

brsanthu commented Sep 1, 2017

I will try to upload v2 with beta label over the weekend.

@IvanRF
Copy link
Author

IvanRF commented Sep 1, 2017

Excelent! another question: why screenResolution is not set by default?
I'm currently using config.setRequestParameterDiscoverer(new AwtRequestParameterDiscoverer()); but the JavaScript library for GA always send that info and the screenColors.

By the way, comparing with the Google's library, screenColors sends '32, 32' but it should be '32-bit'. screenResolution sends '1366x768, 96 dpi' and should be '1366x768' (although dpi info could be useful).
Screen Resolution
Screen Colors

@brsanthu
Copy link
Owner

brsanthu commented Sep 1, 2017

Since many times, the env where this library is used may not have access to display to get the stats and that's why it is not set by default.

I will look into the screen resolution and colors info.

@IvanRF
Copy link
Author

IvanRF commented Sep 1, 2017

oh, you're right, I was thinking only on desktop apps but the library could be used on a server.

@IvanRF
Copy link
Author

IvanRF commented Sep 1, 2017

Finally, the second report is available. The OS value didn't worked.
I sent Windows 10 and apparently they expect Windows NT 10.0 (since that value worked).

So, a simple logic could be applied there to replace Java property value to a valid value.

@IvanRF
Copy link
Author

IvanRF commented Sep 1, 2017

Yes, that change worked (I don't know if there is any correlation but when the OS is valid the pageview appears faster on the audience report).

I applied this simple logic, but more work is needed to support other OS:

OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
String osVersion = (isWindows()) ? "Windows NT " + os.getVersion() : os.getName();
config.setUserAgent("Java/" + System.getProperty("java.version") + " (" + osVersion + "; " + os.getArch()+ ")");

@nicolabeghin
Copy link

Any news on this? I'm experiencing the same issue, will experiment with your previous suggestions!

@nicolabeghin
Copy link

Using like this at the moment:

public class WMRequestParameterDiscoverer extends AwtRequestParameterDiscoverer {
    protected String getUserAgentString() {
        return String.format("Java/%s (%s %s; %s)", System.getProperty("java.version"), System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"));
    }
}

@kaikun213
Copy link

Yes ran into the same issue, took me quite a while to find out why my requests are not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants