I have included Google analytics in my app.
But when i create an object of Tracker
the tracker does not work
Code in one of my activity
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
try{
tracker=((GoogleAnalyticsConfig)this.getApplication()).getTracker(GoogleAnalyticsConfig.TrackerName.APP_TRACKER);
tracker.setScreenName("HomeActivity");
tracker.send(new HitBuilders.AppViewBuilder().build());
}catch(Exception ex)
{
ex.printStackTrace();
}
}
Now with this code i don't see the app in Realtime tracking but if i change the above code with this
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
try{
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
analytics.reportActivityStart(this);
}catch(Exception ex)
{
ex.printStackTrace();
}
}
I can see that one user is active in Realtime
Code for GoogleAnalyticsConfig
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.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
// The following line should be changed to include the correct property id.
private static final String PROPERTY_ID ="UA-XXXXXXXX-1";
public synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = analytics.newTracker(PROPERTY_ID);
t.enableAutoActivityTracking(true);
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
Can any one tell me why tracker is not working?Also not only realtime but also in all the screens where i have included the tracker its not showing in App Overview section of Google Analytics ,even after 48 hrs.
in res folder create xml folder with below three xml file
app_tracker.xml
ecommerce_tracker.xml
global_tracker.xml
create java file with AnalyticsSampleApp.java and register this file in menifest like in application tag with android:name="com.example.ui.AnalyticsSampleApp"
in MainActivity onCreate put below