简体   繁体   中英

Google Analytics v4 can't see live hits

I just started using GAV4.

I followed and read the getting started tutorial carefully. I have set all the permissions required and also put their getTracker code inside a class which resides in an Application class serving all my app fragments that needs global access to data.

Here's the code:

public static 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.
  }

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


 synchronized static public Tracker getTracker(Application thisApp) {
        if (!mTrackers.containsKey(TrackerName.APP_TRACKER)) {


          GoogleAnalytics analytics = GoogleAnalytics.getInstance(thisApp);
          GoogleAnalytics.getInstance(thisApp).getLogger().setLogLevel(LogLevel.VERBOSE);
          Tracker t =
                  analytics.newTracker(thisApp.getResources().getString(R.string.app_tracker_property_id));
          mTrackers.put(TrackerName.APP_TRACKER, t);

        }
        return mTrackers.get(TrackerName.APP_TRACKER);
      }

Note I only need an app tracker so I removed the sections regarding global tracker and ecommerce tracker. Also, the R.string.app_tracker_property_id is my correct property id and is of the form UA-XXXXXXXX-1.

Here's the code I put inside a fragment onCreate to count a screen hit:

    Tracker tracker = ((AppCore)getActivity().getApplication()).getTracker();
    tracker.setScreenName("settings");
    tracker.send(new HitBuilders.AppViewBuilder().build());

What happens when I enter this screen, I get a "no campaign data found" print to the logcat (which I understand is ok), and also the verbose messages from the logger which says that a client id is loaded from disk,successfully connect to Analytics service and later that a hit was sent to server:

10-17 13:22:52.093: V/GAV4(23153): Thread[client_id_fetcher,5,main]: Loaded client id from disk.
10-17 13:22:57.098: V/GAV4(23153): Thread[GAThread,5,main]: connecting to Analytics service
10-17 13:22:57.138: V/GAV4(23153): Thread[GAThread,5,main]: connect: bindService returned true for Intent { act=com.google.android.gms.analytics.service.START cmp=com.google.android.gms/.analytics.service.AnalyticsService (has extras) }
10-17 13:22:57.143: I/GAV4(23153): Thread[GAThread,5,main]: No campaign data found.
10-17 13:22:57.143: V/GAV4(23153): Thread[GAThread,5,main]: Initialized GA Thread
10-17 13:22:57.173: V/GAV4(23153): Thread[main,5,main]: service connected, binder: android.os.BinderProxy@414e2760
10-17 13:22:57.173: V/GAV4(23153): Thread[main,5,main]: bound to service
10-17 13:22:57.178: V/GAV4(23153): Thread[main,5,main]: Connected to service
10-17 13:22:57.208: V/GAV4(23153): Thread[GAThread,5,main]: Loaded clientId
10-17 13:22:57.213: V/GAV4(23153): Thread[GAThread,5,main]: Loaded clientId
10-17 13:22:57.213: V/GAV4(23153): Thread[GAThread,5,main]: putHit called
10-17 13:22:57.213: V/GAV4(23153): Thread[GAThread,5,main]: Sending hit to service   (ommited details)

But for some reason, I can't get any details on the RealTime view in the GA site. Checked whole tabs and all graphs are empty. Is it because my account is newly created (read in SO that I need to wait at least 1 day, but it already passed), or am I doing something wrong?

Problem fixed... just had to wait another day or two...

Yes, it may be frustrating, but I couldn't see results only after 2-3 days, so make sure you're doing it right (it's quite simple) and be patient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM