UsageStatsManager seems to provide general statistics for all apps on your device, however, I am interested in tracking my own apps user detailed statistics.
For instance, how many seconds does a certain activity stay opened? how many times is it opened? how many times a button is clicked?
Google provides a nice way to report on your app statistics & reports here but this not what I am looking for!
What I am looking for is either an app that plugs in to my intents (which I doubt is viable) OR
another class/package that provides this functionality given that I plug it in my code (more like a usage calculator that attaches to my intent)
You can use
Google Analytics - http://www.google.co.in/analytics/
Parse.com - https://parse.com/products/analytics
Flurry Analytics - http://www.flurry.com/solutions/analytics
Integrate google analytics. So easy:
Add this code to MyApplication class (Consts is my private class where is defined property id):
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
public class MyApplication extends Application {
private static Context context;
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
public synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = analytics.newTracker(Consts.ANALYTICS_PROPERTY_ID);
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
public void onCreate(){
super.onCreate();
MyApplication.context = getApplicationContext();
}
public static Context getAppContext() {
return MyApplication.context;
}
}
And this code add to your fragment file:
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
Tracker t = ((MyApplication) getActivity().getApplication()).getTracker(TrackerName.APP_TRACKER);
t.setScreenName("My screen name");
t.send(new HitBuilders.AppViewBuilder().build());
Parse.com also have free analitycs tool. You can define your own events and then browse them in Web console.
There are no of logging libraries you can choose from as per your need and integrate it in your app. Like Google Analytics, Flurry etc. Search over internet or try below link...
https://android-arsenal.com/tag/57
Integrate Google Analytic for your android App.
Related
I'm trying to implement Analytics on my app. Actually I did it, but I'm not able to see interactivity in real time, it's takes some time, like 2~3 minutes to appear something. I tried to set Dispatch Period but it didn't take effect.
I followed the implementation of Google Analytics Developer, some code below:
public class AppController extends Application {
public enum TrackerName {
APP_TRACKER // Tracker used only in this app.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
public synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = analytics.newTracker(R.xml.global_tracker);
analytics.setLocalDispatchPeriod(2);
// Set the log level to verbose.
GoogleAnalytics.getInstance(this).getLogger()
.setLogLevel(LogLevel.VERBOSE);
// Tracker t = analytics.newTracker(R.xml.global_tracker);
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
}
The code to send:
private static void SendView(Activity act, String view) {
// Get tracker.
Tracker t = ((AppController) act.getApplication())
.getTracker(TrackerName.APP_TRACKER);
// Set screen name.
// Where path is a String representing the screen name.
t.setScreenName(BuildName(view));
// Send a screen view.
t.send(new HitBuilders.AppViewBuilder().build());
}
Thanks in advance.
Short answer: you can't do immediate dispatch with Google Play Services.
This is done to save traffic.
On devices with Google Play Services installed, by default, auto dispatching with 2 minute interval is enabled and manual dispatching is not available.
https://developers.google.com/analytics/devguides/collection/android/v4/dispatch
What it doesn't say is that these 2 minutes can only be increased programmatically. iOS has a similar system, but the time frame is a bit different. Either 1 minute or 30 seconds.
Generally, you don't want to look at the real time GA data to debug your
tracking implementation. Have a wrapper around your GA/Firebase library and have logging in that wrapper.
Additioanlly, the Real time data reports in GA are severely lacking dimensions and aggregation options. You want to wait for a day or two for the data to be made properly available.
I am using Google Analytics v4 in my app.I published my app now I can see users in real time analytics but other reports are empty.What can be cause this ? I started using analytics 2 days ago still there is no report.But as I said I can see users in real time analyics.
This is my tracker:
package com.impact.ribony;
import java.util.HashMap;
import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
public class Trackers extends Application
{
public enum TrackerName
{
APP_TRACKER, // Tracker used only in this
// app.
GLOBAL_TRACKER, // Tracker used by all the
// apps from a company.
// eg: roll-up tracking.
ECOMMERCE_TRACKER, // Tracker used by all
// ecommerce
// transactions from a
// company.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
public synchronized Tracker getTracker(TrackerName trackerId)
{
if (!mTrackers.containsKey(trackerId))
{
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
if( trackerId == TrackerName.GLOBAL_TRACKER )
{
mTrackers.put(trackerId, analytics.newTracker(R.xml.global_tracker));
}
}
return mTrackers.get(trackerId);
}
}
This is global_tracker.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyDashes">
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_reportUncaughtExceptions">true</bool>
<!-- The screen names that will appear in reports -->
<screenName name="com.impact.ribony.MainActivity">MainActivity</screenName>
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-42075172-2</string>
</resources>
And I am using following lines in onCreate() method:
Tracker t = ((Trackers) getApplication()).getTracker(Trackers.TrackerName.GLOBAL_TRACKER);
t.setScreenName("Main");
t.enableAdvertisingIdCollection(true);
t.send(new HitBuilders.AppViewBuilder().build());
And this one in onResume() method:
GoogleAnalytics.getInstance(this).reportActivityStart(this);
If the question is about why there is no crash reports, than it is a known bug, maybe it is someway linked with your problem, more here In general exceptions are not dispatched even with this line in V4-
<bool name="ga_reportUncaughtExceptions">true</bool>
Edit. Maybe change to ScreenViewBuilder, because AppViewBuilder is deprecated.
https://developer.android.com/reference/com/google/android/gms/analytics/HitBuilders.AppViewBuilder.html
i have setup every thing in my app for using google analytics V4
and i get every things working and i can see it but when i go to real time overview in my mobile view i didn't see any active user
this is my tracker
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyDashes">
<integer name="ga_sessionTimeout">300</integer>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- The screen names that will appear in reports -->
<screenName name="info.lifepast.MainActivity">MainActivity</screenName>
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-xxx-3</string>
</resources>
and the application class is
public class Analytics extends Application {
private static final String PROPERTY_ID = "UA-xxxxx-3";
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
: (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker)
: analytics.newTracker(R.xml.ecommerce_tracker);
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
}
and in my main activity on create i added this
Tracker t = ((Analytics) this.getApplication()).getTracker(
TrackerName.GLOBAL_TRACKER);
GoogleAnalytics.getInstance(this).getLogger().setLogLevel(LogLevel.VERBOSE);
// Set screen name.
// Where path is a String representing the screen name.
t.setScreenName(getString(R.string.app_name));
// Send a screen view.
t.send(new HitBuilders.AppViewBuilder().build());
and the manifest file
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.analytics.globalConfigResource"
android:resource="#xml/global_tracker"/>
any help?
I've been looking at the v4 analytics today, and have also had trouble getting screen views to post. Here are a couple things I've dug up during my investigations that may be helpful for you:
AppViewBuilder is deprecated in favor of ScreenViewBuilder (see the HitBuilders source code). This part of the documentation is, presumably, out of date. Edit Mar 6, 2015: it would appear that the linked documentation has now been updated to use ScreenViewBuilder.
If my interpretation of the documentation is correct, it should not be necessary to explicitly post screen views using a ScreenViewBuilder when the auto activity tracking feature is enabled (which I see is the case in your configuration file).
By default, the current date is not included in your Google Analytics stats. You can choose to include it by manually selecting a date range (see drop-down control at the top right of most GA pages).
Make sure you shorten the dispatch period for debug builds - by default, events are batched and sent every 30 minutes, but for testing it's ok to reduce this to a few seconds. See the answer from #vangoz for implementation details.
Hope some of that helps you.
Edit: related, but I see you've already posted there: Google Analytics API v4 for Android Does NOT Send Screen Views
For me it turns out Google Analytics only dispatch the data every 30 minutes by default. So changing the dispatch time for testing show the realtime data with some delay.
GoogleAnalytics.getInstance(this).setLocalDispatchPeriod(15);
Reference: https://developers.google.com/analytics/devguides/collection/android/v4/dispatch
In my android application, I have a search functionality. I would like to track the search keywords that my users search for. As far as I know, Google Analaytics could track events in my android app. I was wondering if it could do the same for search items.
If it is possible, a sample code or a link would be great!
That's mostly a question of how to segment your data in the Analytics web app, almost a science in itself.
Example:
EasyTracker.getTracker().sendEvent("Search", "Keywords", searchString, 1L);
Remember the basic usage of EasyTracker:
https://developers.google.com/analytics/devguides/collection/android/v2/
tracker = GoogleAnalyticsTracker.getInstance();
tracker.startNewSession("UA-YOUR-ACCOUNT-HERE", this);
After defining tracker, you should call the below method.
public static void trackEventGoogle(String category,String action,String label,int value)
{
try
{
GoogleAnalyticsTracker.getInstance().trackEvent(category,action,label,value);
}
catch (Exception e) {
exceptionLog(e);
}
}
I hope it helps. Don't forget to add analytics jar file to your project.
When using EasyTracker:
#Override
protected void onStart() {
super.onStart();
EasyTracker.getInstance().activityStart(this);
}
It work great, the problem that i am integrating from older version of analytics and i use it in a service and not in activity, so i cant use activityStart method.
I tried to use:
GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(getApplicationContext());
final Tracker tracker = googleAnalytics.getTracker("UA-xxxxxx-y");
tracker.setStartSession(true);
tracker.sendView("/page");
And i dont see anything in the analytics (even after GAServiceManager.getInstance().dispatch())....
Is there any way to use new version of analytics whitout the activity???
Thanks
Found a way to not use EasyTracker.
It was actually in the oficial site:
https://developers.google.com/analytics/devguides/collection/android/v2/advanced
Basically this what you need to do:
At first initial the tracker like this:
// Get the GoogleAnalytics singleton.
mGaInstance = GoogleAnalytics.getInstance(this);
// Use the GoogleAnalytics singleton to get two Trackers with
// unique property IDs.
mGaTracker = mGaInstance.getTracker("UA-XXXX-Y");
Then you can get the tracker like this:
mGoogleAnalytics.getDefaultTracker();
And use it like:
mGoogleAnalytics.sendEvent(.....);
mGaTracker.sendView(....);
In a service you need to set the Context before sending a view
Try this:
EasyTracker.getInstance().setContext(this);
EasyTracker.getTracker().sendView("/page");