1

It's not showing real-time data since past one week. It was working before. Are you guys facing same issues these days or it's just me ? Here is the code

public class MyApplicationClass extends Application {

private static final String PROPERTY_ID = "UA-XXXXXXXX-X";

public MyApplicationClass(){
    super();
}

public enum TrackerName {
    APP_TRACKER,
    GLOBAL_TRACKER, 
}

HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();

public synchronized Tracker getTracker(TrackerName trackerId) {
    if (!mTrackers.containsKey(trackerId)) {

        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);

        GoogleAnalytics.getInstance(this).getLogger()
                .setLogLevel(Logger.LogLevel.VERBOSE);
        Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
                :  analytics.newTracker(R.xml.global_tracker);

    }
    return mTrackers.get(trackerId);
}

}

And I'm sending data by calling this static method

public class MyAnalyticsTracker {

public static void tracker(String screenName, String category, String action, String label, Activity activity) {
    GoogleAnalytics.getInstance(activity.getBaseContext()).dispatchLocalHits();
    GoogleAnalytics.getInstance(activity.getBaseContext()).reportActivityStart(activity);
    GoogleAnalytics.getInstance(activity.getBaseContext()).setLocalDispatchPeriod(3);
    GoogleAnalytics.getInstance(activity.getBaseContext()).setAppOptOut(false);
    Tracker t = ((MyApplicationClass) activity.getApplication()).getTracker(
            MyApplicationClass.TrackerName.APP_TRACKER);
    t.setScreenName(screenName);
    t.enableAutoActivityTracking(true);

    t.setSampleRate(50.0d);

    t.setAnonymizeIp(true);

    t.enableAdvertisingIdCollection(true);

    t.send(new HitBuilders.AppViewBuilder().build());
    t.send(new HitBuilders.EventBuilder()
            .setCategory(category)
            .setAction(action)
            .setLabel(label)
            .build());

}
}

Please help. Thanks in advance!

Harsh
  • 644
  • 3
  • 14
  • 27
  • If you have very few users (like you are developing your app) setting sampling rate to 50% will not report data from half of the users and it might happen that all of your users are sampled out. – djabi Jan 11 '15 at 17:26
  • It also seems that you will be reporting screen view 2 or 3 times with your code. reportActivityStart will send "screenview" each time you call the function (when enableAutoActivityTracking is not enabled). enableAutoActivityTracking will report on APP_TRACKER screen view on API 11+ devices automatically. Finally t.send(new HitBuilders.AppViewBuilder().build()) will report the screen view again (ScreenView were called AppView in earlier SDK versions and AppView is alias for ScreenView). – djabi Jan 11 '15 at 17:33
  • How should I correct my code @user1830483? – Harsh Jan 11 '15 at 18:21
  • 1
    I would start by removing the sampling or setting it to 100.0d. If you expect your app to run on devices API 11+ you can keep enableAutoActivityTracking(true) and remove the explicit calls to reportActivityStart and t.send(new HitBuilders.AppViewVuilder()). If your app needs to work on devices before API 11 (that's honeycomb I think) automatic screen view reporting is not supported by the SDK and you need to manually call reportActivtyStart(activity). GoogleAnalytics is a singleton. You can safely keep it in a filed and call GoogleAnalytics.getInstance(...) only once. – djabi Jan 12 '15 at 05:41
  • @user1830483, thanks for your explanation. What changes I should do for when I upload it on Play Store ? I've commented those lines what you said. Any good practice for working with Analytics ? Thanks again – Harsh Jan 13 '15 at 15:30

0 Answers0