title: Android Google Analytics API v4 Real Time
body: <p>I have setup everthing in application for using google analytics V4 and I can see "Screens, Active Users,New Users and Top Device Models" but I don't see "Real-Time" data or active users on app.</p>
  
  <p>global_tracker.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
  &lt;string name="ga_trackingId"&gt;UA-XXXXXX-X&lt;/string&gt;
  &lt;integer name="ga_sessionTimeout"&gt;300&lt;/integer&gt;
  &lt;bool name="ga_autoActivityTracking"&gt;true&lt;/bool&gt;
  &lt;string name="ga_logLevel"&gt;verbose&lt;/string&gt;
  &lt;integer name="ga_dispatchPeriod"&gt;30&lt;/integer&gt;
  &lt;bool name="ga_dryRun"&gt;false&lt;/bool&gt;
  &lt;screenName name="com.sounds.MainActivity"&gt;MainActivity&lt;/screenName&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>app_tracker.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
  &lt;string name="ga_trackingId"&gt;UA-XXXXXX-X&lt;/string&gt;
  &lt;bool name="ga_autoActivityTracking"&gt;true&lt;/bool&gt;
  &lt;bool name="ga_reportUncaughtExceptions"&gt;true&lt;/bool&gt;
  &lt;string name="ga_appName"&gt;soundsapp&lt;/string&gt;
  &lt;string name="ga_appVersion"&gt;3.4&lt;/string&gt;
  &lt;bool name="ga_debug"&gt;true&lt;/bool&gt;
  &lt;item name="ga_dispatchPeriod" format="integer" type="integer"&gt;120&lt;/item&gt;
  &lt;string name="ga_sampleFrequency"&gt;90&lt;/string&gt;
  &lt;bool name="ga_anonymizeIp"&gt;true&lt;/bool&gt;
  &lt;bool name="ga_dryRun"&gt;false&lt;/bool&gt;
  &lt;string name="ga_sampleFrequency"&gt;100.0&lt;/string&gt;
  &lt;integer name="ga_sessionTimeout"&gt;10&lt;/integer&gt;
  &lt;string name="com.sounds.MainActivity"&gt;MainActivity&lt;/string&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" /&gt;
  meta-data
  android:name="com.google.android.gms.analytics.globalConfigResource"
  android:resource="@xml/global_tracker" /&gt;
  </code></pre>
  
  <p>Trackers.java</p>
  
  <pre><code>public class Trackers extends Application {
  
   private static final String PROPERTY_ID = "UA-XXXXXX-X";
   public static int GENERAL_TRACKER = 0;
   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.
       ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
   }
  
   public HashMap&lt;TrackerName, Tracker&gt; mTrackers = new HashMap&lt;TrackerName, Tracker&gt;();
  
   public Trackers() {
       super();
   }
  
   public synchronized Tracker getTracker(TrackerName trackerId) {
       if (!mTrackers.containsKey(trackerId)) {
           GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
           Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID): (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker): analytics.newTracker(R.xml.ecommerce_tracker);
           mTrackers.put(trackerId, t);
  
       }
       return mTrackers.get(trackerId);
     }
   }
  </code></pre>
  
  <p>Activity class</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  
  setContentView(R.layout.main);
  Tracker t = ((Trackers)this.getApplication()).getTracker(TrackerName.APP_TRACKER);
  t.setScreenName("HomePage");    
      .....
   @Override
    protected void onStart() {
    // TODO Auto-generated method stub
  
    super.onStart();
    GoogleAnalytics.getInstance(this).reportActivityStart(this);
    //Get an Analytics tracker to report app starts &amp; uncaught exceptions etc.  
    }
  
    @Override
    protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
    //Stop the analytics tracking
    GoogleAnalytics.getInstance(this).reportActivityStop(this);
    }       
  </code></pre>