简体   繁体   中英

Google Analytics android dispatch

I wanted to try Google Analytics in my Android App. Everything worked properly, but on my Analytics page there is no visitor shown. I can see in the LogCat that it sent the data, I copied the 4 labels from the samples.

tracker.trackEvent(
        "Clicks",  // Category
        "Button",  // Action
        "clicked", // Label
        77);       // Value

And I added also the dispatch after it. I waited now 3-4 Hours but still no visitor, tried it out in the emulator which has internet enabled.

Double check that you've entered you're unique key correctly.

GoogleAnalyticsTracker tracker = GoogleAnalyticsTracker.getInstance();
tracker.start("UA-12345678-1", this);
tracker.trackPageView("/HomeScreen");
tracker.dispatch();

You may want to retry after deleting the GoogleAnalytics database on the phone. There may be bad entries in the database, which will cause even your good data to fail to be uploaded.

To delete the database on the Android emulator or device, you can do this

  • adb shell ,
  • then cd to the directory that has the potentially bad data base, cd /data/data/com.roblabs.m.dailypaper/databases
  • of course, use your own package name after /data/data
  • ls to show the contents of the databases directory
  • then remove, rm google_analytics.db

Google Analytics, at least on Android, does not accept spaces in the trackEvent() or trackPageView() methods. One of the Google samples for Android for trackEvent() had a space in it, so it's possible that's where the space was introduced. It's probably true for all white space.

Google Analytics for Android throws a debug warning when a space is detected, but that only goes to logcat. I've had to intercept strings and remove white space before it gets to Google Analytics.

I had the same issue of no data being shown. I thought the LogCat was showing the data being sent but I actually wasn't getting the HTTP 200 code that confirmed it.

My issue was Lint for eclipse broke my Web Data ID!

I've explained it here: http://blog.blundell-apps.com/google-analytics-common-problems-and-fixes/

I have met the same case as yours, then I change to use the lib v2 and it works. Have a look at google's site: https://developers.google.com/analytics/devguides/collection/android/v2/ . Remember to download the lib from that site, not from Android SDK Manager.

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