InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Android development tutorials

  • Android - Show top processes using adb
  • Android studio keyboard shortcuts
  • Disable sleep during android usb debugging
  • Download apk using AirDroid
  • Enable usb debugging
  • Exerciser monkey tutorial
  • Find top processes by memory/cpu on Android using Adb
  • Find used ports by an app on Android using Adb
  • Install Android 8 on Pixel 2
  • Root Android pixel 2 using Magisk and boot image patching
  • Transfer android apk using adb
  • Using Google analytics SDK v2 for android app real time tracking
  • View Desktop Site
  • adb tutorial
 
  • Home
  • > Tutorials
  • > Android Development

Using Google analytics SDK v2 for android app real time tracking

By admin | Last updated on Mar 20, 2016

When I used Google analytics SDK v2 for mobile android app, I was pretty impressed with it. With very little code I was able to implement it. I initially tried to make legacy API 1.5 work thinking that 2.0 is in beta and I had some existing open source code using 1.5. But After digging more into it, I decided to give 2.0 beta a try. I’m glad that I used 2.0 API as it turned out to be simpler implementation

Here is some code snippet.

// init code within onCreate
EasyTracker.getInstance().activityStart(activity);

// Code to track a pageview
EasyTracker.getTracker().trackView(path);

// track event
EasyTracker.getTracker().trackEvent(category, action, label, val);

// stop tracking. Should be part of onStop in Activity
EasyTracker.getInstance().activityStop(activity);

In addition you also need analytics.xml in res/values as shown below. You may want to experiment with various values. See official
doc for more parameters.

<?xml version="1.0" encoding="utf-8" ?>
<resources>
<string name="ga_trackingId">UA-xxxxxxxx-1</string>
<bool name="ga_autoActivityTracking">true</bool>
<integer name="ga_dispatchPeriod">10</integer>
<bool name="ga_reportUncaughtExceptions">true</bool>
</resources>

You may want to change ga_dispatchPeriod to higher value in case you want to dispatch less frequently. The trackingId can be obtained by creating a new account and mobile app in google analytics account as shown below.

android app google analytics new account

 

android app google analytics new app

The code is pretty simple and does lot of tracking like app version, devices, location, views, etc. And you also can view real time tracking when someone is using the app. That makes it pretty useful when you are running some ad campaign (e.g. admob). The results can be viewed immediately and you can know if everything is all right. Here are some screenshots of real time tracking:

  1. Real time active screen namesandroid app google analytics real time active screen names
  2. Real time countries
    android app google analytics real time countries
  3. Real time top screens
    android app google analytics real time top active screens

Suggested posts:

  1. www vs non-www domain which is better for your site?
  2. How to crop an image using imagemagick convert
  3. How to write custom php in wordpress
  4. Traceroute outcome from Bangalore to AWS Virginia and California
  5. Mac terminal – how to close shell on exit
  6. WordPress – exclude specific posts from archive pages
  7. How to view flash debug log using Firefox on Mac
  8. How to remove xmlrpc from wordpress headers
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Android Development, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress