Google Analytics Android Real Time - android

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.

Related

How can I track my android app users detailed statistics?

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.

Disable google analytics tracking during live run

According to the terms for Google analytics you need to provide the user with a option to opt out of the tracking. But I feel, documentation is not very clear on how to do that. This what I got so far.
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = analytics.newTracker(R.xml.tracker);
t.enableAdvertisingIdCollection(false);
t.enableAutoActivityTracking(false);
t.enableExceptionReporting(false);
Will this disable all tracking including events like this.
t.send(new HitBuilders.EventBuilder()
.setCategory("category")
.setAction("test")
.setLabel("label")
.build());
If not how do I completely disable tracking during run on user device?
You need to use GoogleAnalytics.getInstance(this).setAppOptOut(true);.
In Google Analytics documentation(1), there is simple example with shared preferences.
SharedPreferences userPrefs = PreferenceManager.getDefaultSharedPreferences(this);
userPrefs.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener () {
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(TRACKING_PREF_KEY)) {
GoogleAnalytics.getInstance(getApplicationContext()).setAppOptOut(sharedPreferences.getBoolean(key, false));
} else {
// Any additional changed preference handling.
}
}
});
Note: This is different from disabling Google Analytics during testing / development. If your aim is to disable during test/development, use (2)
GoogeAnalytics.getInstance(this).setDryRun(true);
You can set a SharedPreference setting and if the user opt-out Analytics tracking you don't send the Analytics update.

Android : Tracking service component using google-analyticsV3

I made an application showing a window while calling in certain case, using service component.
The window contains info of callee.
I wanna know how to track this window.
Few buttons would be added with functions - ex : sending sms.
And I just wanna count how many times this window has been shown.
I found this question - Android: can I use Google Analytics inside a Service?
But it seems it's about old version of GA.
And I failed to make that in my app.
(I tried :
public class view extends Service {
...
GoogleAnalytics mGA;
Tracker gat;
...
#Override
public void onCreate() {
super.onCreate();
mGA = GoogleAnalytics.getInstance(app);
gat = mGA.getTracker("UA-my-account");
Map<String, String> params = new HashMap<String, String>();
params.put("event", "test");
gat.send(params); )
Let me know how to make tracker work in my app with GA V3.
Thanks for any help.
I made it.
GA = GoogleAnalytics.getInstance(YourContext);
Tracker = GA.getTracker("Your UA-xxxxxxxxxxxxxxxxxxx");
1. Tracker.send(MapBuilder.createEvent("category","action","label",long type value).build());
2. Tracker.set(Fields.SCREEN_NAME, "SCREEN NAME");
Tracker.send(MapBuilder.createAppView().build());
now wait for a day for this to be shown.

google analytics doesn't show the active user in Real time overview

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

Using Google Analytics v2 without Activity / EasyTracker

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");

Categories

Resources