JackPGreen
JackPGreen

Reputation: 1139

Pushing data to Google Analytics Measurement Protocol via Java - "no data received"

I'm trying to report data from an application to Google Analytics using the Measurement Protocol.

The application is a desktop application - not web or mobile app etc - I'm aware that Google Analytics isn't the optimal choice for this.

I've created a webstream Data Stream, and created a Measurement Protocol API secret.

But when I submit data, it's not recorded in Google Analytics - on the stream I see No data received in past 48 hours, and the real time dashboard is empty.

I've also tested submitting this using the Event Builder but even submitting there doesn't work.

Simple example of what I'm submitting - obviously the correct measurement_id and api_secret are being used:

    System.out.println(HttpClient.newHttpClient().send(HttpRequest.newBuilder(URI.create(
    "https://www.google-analytics.com/mp/collect?api_secret={API_SECRET}&measurement_id=G-{MEASUREMENT_ID}"))
    .header("Content-Type", "application/json").POST(BodyPublishers.ofString("""
        {
          "user_id" : "1116",
          "client_id" : "1116",
          "non_personalized_ads" : false,
          "events" : [ {
            "name" : "select_content",
            "params" : { }
          } ]
        }
                        """)).build(), BodyHandlers.ofInputStream()).statusCode());

This returns status code 204.

What am I missing?

Thanks.

Upvotes: 0

Views: 867

Answers (0)

Related Questions