Use FlurryAgent.onEvent(String eventId, Map<String, String> parameters)
Please anybody tell how to use
FlurryAgent.onEvent(String eventId, Map<String, String> parameters)
in an android activity to track events with flurry ?
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!
链接地址: http://www.djcxy.com/p/23980.html下一篇: 使用FlurryAgent.onEvent(String eventId,Map <String,String>参数)