mikehardy / google-analytics-java

Open Source license compatible Java API for Google Analytics
8 stars 3 forks source link

Google seems to ignore the requests sent via this library #303

Open marco-brandizi opened 1 year ago

marco-brandizi commented 1 year ago

Hi all,

I've been banging my head for hours trying to make this to work.

I'm reasonably sure the API is invoked, since I see "invoked successfully with ID XXX" in the logs. Yet, the GA's real-time view doesn't show anything, apparently, Google is entirely and silently ignoring my requests.

The code at issue is an API for an application that also has an UI on top of the API. The UI invokes GA as well (we offer both the UI and programmatic access via API, and we want to track both), using the Javascript code provided by Google instructions here, and using the same GA ID that instead doesn't work when used with google-analytics-java.

I've tried all combinations I can imagine:

I'm embedding your library in my Maven project with:

<dependency>
  <groupId>net.mikehardy</groupId>
  <artifactId>google-analytics-java</artifactId>
  <version>2.0.11</version>
</dependency>           

I'm not sure if the latest release works with the current GA API, or if at least a rebuild from sources might work.

Any help very appreciated, many thanks.

marco-brandizi commented 1 year ago

OK, I've found out what the problem is: GA now demands that the user agent parameter is set to a sensible value, this is now working for me. I would recommend that google-analytics-java sets this by default.

mikehardy commented 1 year ago

Interesting! That probably explains why I haven't see this. We set user-agent in AnkiDroid (the user of this library that I personally support) so it never failed.

I'd welcome a PR to set a default user agent and add a note saying it is required now and if you don't set it the default is now "<whatever you propose)>"

marco-brandizi commented 1 year ago

Thanks for your reply, @mikehardy. I might try crafting a PR, how do you think it's best to introduce that? In DefaultRequest?

mikehardy commented 1 year ago

Yeah, that seems right. And thanks!

It will be a breaking change / major version bump so people can get a warning that the module will generate different hits by default now, but I'm okay with that as long as there's a good release note (very easy to do in this case)