title: How to Implement Google TagManager in Android Application
body: <p>I want to implement Google Tag Manager and Google Analytics in my android application. </p>
  
  <p>I am totally new to analytics and google tagmanager. I am following these link 
  <a href="https://developers.google.com/analytics/devguides/collection/android/v4/" rel="nofollow">link1</a>, , <a href="http://www.smashingmagazine.com/2013/12/09/mobile-google-analytics-tag-manager/" rel="nofollow">link2</a> 
  through this I got some basic idea about Google Tag Manager and Google Analytics. </p>
  
  <p>What I did is:<br>
  I created both Google TagManager account and Analytics account.
  Created all the basic step in TagManager and in Analytics account.
  Also I added libGoogleAnalyticsServices this file to project lib and gtm container in project file asset.</p>
  
  <p>Now what I need is. What are all the codes I need to add in my application? And where I need to add this. I created one seperated java file in the src and I added these code</p>
  
  <pre><code>import com.google.android.gms.analytics.Logger;
  import com.google.android.gms.analytics.Tracker;
  import com.google.android.gms.analytics.GoogleAnalytics;
  
  import android.app.Application;
  
  import java.util.HashMap;
  
  public class AnalyticsSampleApp extends Application {
  
  // The following line should be changed to include the correct property id.
  private static final String PROPERTY_ID = "UA-XXXXX-Y";
  
  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.
  }
  
  HashMap&lt;TrackerName, Tracker&gt; mTrackers = new HashMap&lt;TrackerName, Tracker&gt;();
  
  public AnalyticsSampleApp() {
      super();
  }
  
  synchronized Tracker getTracker(TrackerName trackerId) {
      if (!mTrackers.containsKey(trackerId)) {
  
          GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
          analytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
          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);
          t.enableAdvertisingIdCollection(true);
          mTrackers.put(trackerId, t);
      }
      return mTrackers.get(trackerId);
  }
  }
  </code></pre>
  
  <p>Just tell me what are remaining codes I need to add and what I need to change in this. If my question is not understandable kindly comment below. Let me ask it clearly again.</p>
  
  <p>Thanks a lot.</p>