Hi I am trying to integrate the Google Analytics but I am not able to find any analytics data that shows on the Google Analytics Account of mine. I am using the link mention below:-
But I am not able to get the result, nor the correct path/way or proper and Detailed Tutorial for how to integrate the Google Analytics in android app.
My code is as follows:-
public class MainActivity extends Activity {
GoogleAnalytics tracker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get tracker.
Tracker t = ((AnalyticsHelper) MainActivity.this.getApplication()).getTracker(
TrackerName.APP_TRACKER);
// Set the dispatch period in seconds.
GAServiceManager.getInstance().setLocalDispatchPeriod(8);
}
@Override
protected void onStart() {
super.onStart();
EasyTracker.getInstance(this).activityStart(this);
// Set the dispatch period in seconds.
GAServiceManager.getInstance().setLocalDispatchPeriod(8);
}
@Override
protected void onStop() {
super.onStop();
EasyTracker.getInstance(this).activityStop(this);
}
}
My Analytics Helper class is as follows:-
public class AnalyticsHelper extends Application {
// The following line should be changed to include the correct property id.
private static final String PROPERTY_ID = "UA-xxxxxxxx-x"; // My Property id.
public static int GENERAL_TRACKER = 0;
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 AnalyticsHelper()
{
super();
}
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
analytics.getLogger().setLogLevel(LogLevel.VERBOSE);
Tracker t = null;
if(trackerId==TrackerName.APP_TRACKER){
t= analytics.getTracker(PROPERTY_ID);
}
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
}
And my analytics xml file in xml directory is as follows:-
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyDashes">
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-xxxxxxxx-X</string>
<!--Enable automatic activity tracking-->
<bool name="ga_autoActivityTracking">true</bool>
<!--Enable automatic exception tracking-->
<bool name="ga_reportUncaughtExceptions">true</bool>
</resources>
Any help will be heart-fully welcomed. Thanks in advance.