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

Unable to make v 2.0.0 working #62

Open
AleksNFedorov opened this issue Oct 2, 2019 · 6 comments
Open

Unable to make v 2.0.0 working #62

AleksNFedorov opened this issue Oct 2, 2019 · 6 comments

Comments

@AleksNFedorov
Copy link

AleksNFedorov commented Oct 2, 2019

I can`t get events to appear in google analytics. Everything works fine when I send requests from Postman.

Here is my configuration
No error logs nor exceptions

	ga = GoogleAnalytics.builder()
			.withTrackingId("UA-XXXXXXXX-1")
			.withAppName("S******r")
			.withAppVersion("0.1.1")
			.build();
ga.event()
	.eventAction(event.getAction().name())
	.eventCategory(event.getCategory().name())
	.eventLabel(event.getValue())
	.clientId(clientId)
	.send();

Maven dependency

<dependency>
  <groupId>com.brsanthu</groupId>
  <artifactId>google-analytics-java</artifactId>
  <version>2.0.0</version>
</dependency>
@DropSnorz
Copy link

Hi.
I had a similar problem. It was a missing parameter in the resquest that prevent the hit to be processed by GA.

To debug this, i logged all request parameters.

GoogleAnalyticsResponse response = ga.event().---.send();
Map<String, String> parameters = response.getRequestParams();

Then, i replayed the request with exact same parameters and values on GA debug endpoint https://www.google-analytics.com/debug/collect. This will show you a debug message with details of the problem. Validating hits on Measurement API

Work done on PR #61 will introduce new features to validate and debug hits.

@AleksNFedorov
Copy link
Author

That is exactly an issue. Request with the same parameters goes ok if send from the Postman.

Debug endpoint also returns no issues

@AleksNFedorov
Copy link
Author

User-Agent header is mandatory for the measurement protocol, must be set explicitly with config (.setUserAgent)

@nagyzsolthun
Copy link

Is there any documentation about the expected User-Agent header?

Adding the header solved the issue to me too, but I can't find documentation about it, not even the https://www.google-analytics.com/debug/collect endpoint provides this information.

@bkhablenko
Copy link

My observations so far:

  • User-Agent is required indeed.

  • The library will generate and include the header if its value was not specified explicitly in the configuration.

  • Requests made with the generated header (for me, it starts with java/1.8.0_212 and includes OS details) do not appear in Google Analytics.

  • Setting the header to something shorter (e.g., java/1.8.0_212) does not seem to help. In fact, requests didn't appear in Google Analytics until I removed the slash altogether.

  • Requests made from Postman (which sets User-Agent to PostmanRuntime/7.20.1) do work.

The following is the cURL command I used for testing:

curl -X POST \
  https://www.google-analytics.com/collect \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'User-Agent: PostmanRuntime/7.20.1' \
  -d 'de=UTF-8&t=event&v=1&ea=VERIFY_EMAIL&ec=Tests&tid=UA-XXXXXXXXX-1&cid=97b964f2-4a72-47cd-ad19-4ce7d8f24784'

@DerrylThomas
Copy link

It seems like GA filters events which it thinks is coming from bots. And for some reason, calls coming from this library is assumed to be from a bot.
There seems to be 2 ways to solve this:

  1. Uncheck this checkbox for your view in GA - Exclude all hits from known bots and spiders.
  2. Explicitly override the User Agent via the measurement protocol's ua option.

I did option 2 to get this to work for me. Something like this fixed it for me - ga.event().userAgent("custom").send().

Based on this SO question.

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

5 participants