Use FlurryAgent.onEvent(String eventId, Map<String, String> parameters)

三世轮回 提交于 2019-12-03 05:49:20

The simplest use of onEvent is without parameters.

Let's say we're writing a game and you want to track how many people start the game and how many complete it. You would then have:

FlurryAgent.onEvent("Started game");

and

FlurryAgent.onEvent("Won game");

at appropriate points in your code.

If you want to know more information about the state of the application when an event occurred, you can add parameters to track additional information like this:

HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put("Final score", String.valueOf(score));
parameters.put("Time taken", String.valueOf(secondsElapsed));
FlurryAgent.onEvent("Won game", parameters);

You can have up to 100 different event names, each with up to 10 parameters whose names and values are up to 255 characters long.

Notice you don't specify your Flurry ID when calling onEvent. Flurry derives the ID from the current session, so calls to onEvent must be made somewhere between calls to onStartSession and onEndSession - but if you follow their guidelines and put these in your Activity's onStart and onStop then you don't have to worry about that.

I show you a simple example. In this code i want to log simple events and other events with a category.

public void logAnalyticsEvent(final String versionName, final String strMsg, final String category){

        if (category==null){                
            FlurryAgent.logEvent(strMsg);           

        }else{              
            final HashMap<String, String> parameters = new HashMap<String, String>();
            parameters.put("Event",strMsg );
            FlurryAgent.logEvent(category, parameters);
        }


}

in the first part of the condition i'm logging the only the event, in the second part I put the name of the event inside de parameters (a hashmap with a key named "Event" and value the name of the event) and I log the name of the category with the parameters (events inside)

FlurryAgent.logEvent(category, parameters);

Hope this helps!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!