简体   繁体   中英

HitBuilder method setAll() not working in Google Analytics

I have created a Hitbuilder instance and passed HashMap<String, String> params = new HashMap<String, String> params info. into the HitBuilder but could not find any info. of the Keys and values of HashMap on Dashboard.

Although I can see screenName, category, eventName and label.

Below is the snippet I'm doing.

     Tracker t = getTracker(TrackerName.APP_TRACKER);
                t.setScreenName(screenName);
                t.send(new HitBuilders.EventBuilder()
                            .setCategory(category)
                            .setAction(action)
                            .setLabel(label)
                            .setValue(value)
                        .setAll(params) // cannot find params information
                        .build());

Also passing like below also don't show me the values:

     Tracker t = getTracker(TrackerName.APP_TRACKER);
                t.setScreenName(screenName);
                t.send(new HitBuilders.EventBuilder()
                            .setCategory(category)
                            .setAction(action)
                            .setLabel(label)
                            .setValue(value)
                            .set("param1", "test1")
                            .set("param2", "test2")
                        .setAll(params) 
                        .build());

Any answer or comment is highly appreciated.

What keys are you passing? For those curious here is the reference docs for the method. Only valid Measurement Protocol parameters will show up in the results. And the parameter must start with an & . For example if for some reason I wanted to set the geoId of a particular event I could do that as follows:

 Tracker t = getTracker(TrackerName.APP_TRACKER);
            t.setScreenName(screenName);
            t.send(new HitBuilders.EventBuilder()
                        .setCategory(category)
                        .setAction(action)
                        .setLabel(label)
                        .setValue(value)
                        .set("&geoid", "21137")
                        .build());

Before sending random combinations of hit parameters I would encourage you to verify that the hits are valid using the Hit Builder Tool .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM