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
Related
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.
From Application onCreate(), to test event/screen logging:
public static void logUserAction(String eventName) {
Timber.i("Logging to Google Analytics");
Tracker t = getTracker();
t.setScreenName(eventName);
t.send(new HitBuilders.ScreenViewBuilder().build());
t.send(new HitBuilders.EventBuilder()
.setCategory("Event")
.setAction(eventName)
.setLabel(eventName)
.setValue(1)
.build());
}
synchronized static Tracker getTracker() {
if (googleAnalyticsTracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(application);
googleAnalyticsTracker = analytics.newTracker(R.xml.global_tracker);
}
return googleAnalyticsTracker;
}
Config file, global_tracker.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="ga_sessionTimeout">300</integer>
<string name="ga_trackingId">UA-ACTUAL_VALUE_USED_HERE</string>
</resources>
Manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
...
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Build file
compile 'com.google.android.gms:play-services-analytics:7.0.0'
The UA tracking code I'm using is definitely correct. The project builds and executes, however although the log message is shown to confirm the code is called, absolutely nothing happens in debug or release builds. No data is showing in Analytics, and there is nothing in Logcat to guide me.
What did I miss?
Like my comment said, you have to wait some times after the "Google Analytics ID" creation, before you can view any reports.
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'm having a really hard times using Google Analytics in my android application.
I don't need anything complicated, all I want to do is to receive general information about my users, and to receive reports whenever the application crushes.
I performed the following steps:
I created an Application class which contains a private Tracker object.
inside the onCreate function I initialized it.
public class MyApplication extends Application{
private Tracker googleAnalyticsTracker;
#Override
public void onCreate() {
super.onCreate();
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
googleAnalyticsTracker = analytics.newTracker(R.xml.google_analytics_tracker);
googleAnalyticsTracker.enableAutoActivityTracking(true);
googleAnalyticsTracker.enableExceptionReporting(true);
}
}
I created an xml file in order to generate the tracker (google_analytics_tracker.xml), as you can see here:
<integer name="ga_sessionTimeout">300</integer>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_reportUncaughtExceptions">true</bool>
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-*THE ID WHICH I RECIVED*</string>
nevertheless - whenever I execute the application I can't see anything in my google analytics dashboard. Whenever the program crushes - I can't see anything in the google analytics Behavior/'crashes and exceptions' as wel.(I'm looking
does someone have a clue what could be the problem?
Thanks a lot
Try the instructions on this page. You are missing a few things such as sending a screen view event as well as any activity code to getting the global tracker
https://developers.google.com/analytics/devguides/collection/android/v4/
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