| package ${packageName}; |
| |
| import android.content.Context; |
| |
| import com.google.android.gms.analytics.GoogleAnalytics; |
| import com.google.android.gms.analytics.Tracker; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| /** |
| * A collection of Google Analytics trackers. Fetch the tracker you need using |
| * {@code AnalyticsTrackers.getInstance().get(...)} |
| * <p/> |
| * This code was generated by Android Studio but can be safely modified by |
| * hand at this point. |
| * <p/> |
| * TODO: Call {@link #initialize(Context)} from an entry point in your app |
| * before using this! |
| */ |
| public final class AnalyticsTrackers { |
| |
| public enum Target { |
| APP, |
| // Add more trackers here if you need, and update the code in #get(Target) below |
| } |
| |
| private static AnalyticsTrackers sInstance; |
| |
| public static synchronized void initialize(Context context) { |
| if (sInstance != null) { |
| throw new IllegalStateException("Extra call to initialize analytics trackers"); |
| } |
| |
| sInstance = new AnalyticsTrackers(context); |
| } |
| |
| public static synchronized AnalyticsTrackers getInstance() { |
| if (sInstance == null) { |
| throw new IllegalStateException("Call initialize() before getInstance()"); |
| } |
| |
| return sInstance; |
| } |
| |
| private final Map<Target, Tracker> mTrackers = new HashMap<Target, Tracker>(); |
| private final Context mContext; |
| |
| /** |
| * Don't instantiate directly - use {@link #getInstance()} instead. |
| */ |
| private AnalyticsTrackers(Context context) { |
| mContext = context.getApplicationContext(); |
| } |
| |
| public synchronized Tracker get(Target target) { |
| if (!mTrackers.containsKey(target)) { |
| Tracker tracker; |
| switch (target) { |
| case APP: |
| tracker = GoogleAnalytics.getInstance(mContext).newTracker(R.xml.app_tracker); |
| <#if google.analytics.adsEnabled> |
| tracker.enableAdvertisingIdCollection(true); |
| </#if> |
| break; |
| default: |
| throw new IllegalArgumentException("Unhandled analytics target " + target); |
| } |
| mTrackers.put(target, tracker); |
| } |
| |
| return mTrackers.get(target); |
| } |
| } |