First part was about how to integrate Google Analytics in your Android App. I will now explain how to get the most out of it by registrating visits from any view and any other events that may happen.
How to register a view
Initial configuration only allows to capture visits when they come from an activity. But nowadays most Apps are divided into fragments, and detecting when one of these fragments has been loaded may be quite helpful. That’s the coding required for it:
[java]
EasyTracker tracker = EasyTracker.getInstance(context);
tracker.set(Fields.SCREEN_NAME, name);
tracker.send(MapBuilder.createAppView().build());
[/java]
Set the name of the screen in the second line, which could be the name of the class for instance, or a more friendly name depending on the person how is going to check the analytics.
How to capture and event
Events functionality is inherited directly from web pages analytics. An event is any action performed by an user in our App, and it allows up to four parameters:
- Category: Our app may be divided into different categories depending on our needs. I tend to use a category for every sections in my App.
- Action: The kind of event: press, search, play, stop…
- Label (optional): The element that is involved in the action. It may be some specific UI component, such a press on a button, or any more dynamic capture, such a search. In this second case, the label may be the specific search performed by the user.
- Value (optional): this parameter is a Long value. It may be used to give a numeric value to the action. For instance, the amount of time a user has played some media.
The code for registering an event is:
[java]
EasyTracker tracker = EasyTracker.getInstance(context);
tracker.send(MapBuilder
.createEvent(category, action, label, value)
.build()
);
[/java]
The way you use any of these fields is up to your needs and the way you want to use the recorded information.
Conclusion
Google Analytics is a powerful tools that give us the ability to know the way the users use our App. All this information may be extremely useful to improve those functionalities we detect the user is having some problems, evolve the most used sections or activate some ads campaigns depending on the information our users consume. Get the most out of it to lead your Android App to success.
I have a calculator app in which user enters some input into a textBox, Can I get text/question he entered in textBox through Goggle Analytics ?
It just want to know what kind of questions are people solving with my app.
Also will have have to give users opt out for this ?
Thanks
Sure! You can pass it through label field. I’m not sure how much about statistics capture needs to be informed to the user. This kind of statistics are anonymous, because you have no way to know who is the person who entered that input. But anyway, If we compare it with a web page, every time you search something without login in almost any page, this search is logged by Analytics. Anyway, I’m not a lawyer and I think this depends on country laws, so these are only suppositions. If you find out anything else, please let me know.
Hi,
Tracking an event for Web page we use to put on click. For app also it will be the same? Or any other method should I follow plc help
Can you tell me where i need to insert this code into
EasyTracker tracker = EasyTracker.getInstance(context);
tracker.send(MapBuilder
.createEvent(category, action, label, value)
.build()
);
Whenever you need something to be tracked. It will probably be better in a specific function that receives the parameters of the event.