Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending key-value pairs payload to Google Analytics

I'm trying to send N amount of custom key-value pairs attached to a single Hit. That hit will have its own key category/action/label, but I'm after defining my own keys.

I'm trying to integrate Google Analytics to my application. I've followed all configuration steps and it works, but I'm trying to understand how event reporting works, and how can I send my own custom events off predefined key-value pairs.

Map<String, String> myMap = new HashMap<>();
myMap.put("hello", "world");
myMap.put("liek", "turtles");
GoogleAnalytics analytics = GoogleAnalytics.getInstance(context);
analytics.setLocalDispatchPeriod(1800);
Tracker tracker = analytics.newTracker(token);
tracker.send(myMap);

which is unwelcomely received with a Logcat error.

W/GAv4﹕ Discarding hit. Missing hit type parameter: tid=world, a=504324093

I'm experimenting with other APIs like HitBuilders and set(), but none provides a clear key-value pair mapping.

like image 424
MLProgrammer-CiM Avatar asked Jun 18 '15 16:06

MLProgrammer-CiM


People also ask

What is Google Analytics payload?

There are 2 parts to send data to Google Analytics using the Measurement Protocol: The transport – to where and how you send data. The payload – the data you send.

What is a key-value Pair Braze?

Braze enables you to send extra data payloads to user devices via key-value pairs. This feature is available across push, in-app, and Content Card messaging channels.

What is https www Google Analytics com J collect?

It's a request for www.google-analytics.com/collect. It contains twenty-ish URL-encoded parameters. Each parameter stores a specific piece of information that is either used to populate reports or to keep things organized. Some parameters are only used in specific cases, others are required each time.

What is considered a hit in Google Analytics?

An interaction that results in data being sent to Analytics. Common hit types include page tracking hits, event tracking hits, and ecommerce hits. Each time the tracking code is triggered by a user's behavior (for example, user loads a page on a website or a screen in a mobile app), Analytics records that activity.


2 Answers

I think you are looking for Custom Dimensions. First you should create a custom dimension and then send it together with a screen/event hit.

Using your example, you should use it like this:

// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(TrackerName.APP_TRACKER);
t.setScreen("Home Screen");

// Send the custom dimension value with a screen view.
// Note that the value only needs to be sent once.
t.send(new HitBuilders.ScreenViewBuilder()
    .setCustomDimension(1, "world")
    .setCustomDimension(2, "turtles")
    .build()
);

Where dimension #1 would be configured as a "hello dimension" and dimension #2 would be a "liek dimension". This is an example on a screen view, but the same could be accomplished with an event.

like image 152
thiagolr Avatar answered Oct 01 '22 12:10

thiagolr


It seems you are using the old Analytics SDK, which I wouldn't recommend. Try to use the v4 and follow the Analytics SDK for Android manual.

I am not sure what you're trying to do exactly, but custom event can be send using the EventBuilder like this:

tracker.send(new HitBuilders.EventBuilder()
         .setCategory("your-category")
         .setAction("your-action")
         .setLabel("your-label")
         .build());
like image 38
vanekjar Avatar answered Oct 01 '22 13:10

vanekjar