/* * Copyright (C) 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.dinnerapp; import android.app.Application; import com.google.android.gms.analytics.GoogleAnalytics; import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Logger; import com.google.android.gms.tagmanager.TagManager; import com.google.android.gms.tagmanager.ContainerHolder; public class MyApplication extends Application { public Tracker mTracker; public ContainerHolder mContainerHolder; public TagManager mTagManager; // Get the Tag Manager public TagManager getTagManager () { if (mTagManager == null) { // create the TagManager, save it in mTagManager mTagManager = TagManager.getInstance(this); } return mTagManager; } // Set the ContainerHolder public void setContainerHolder (ContainerHolder containerHolder) { mContainerHolder = containerHolder; } // Get the ContainerHolder public ContainerHolder getContainerHolder() { return mContainerHolder; } // Get the tracker associated with this app public void startTracking() { // Initialize an Analytics tracker using a Google Analytics property ID. // Does the Tracker already exist? // If not, create it if (mTracker == null) { GoogleAnalytics ga = GoogleAnalytics.getInstance(this); // Get the config data for the tracker mTracker = ga.newTracker(R.xml.track_app); // Enable tracking of activities ga.enableAutoActivityReports(this); // Set the log level to verbose. ga.getLogger().setLogLevel(Logger.LogLevel.VERBOSE); } } public Tracker getTracker() { // Make sure the tracker exists startTracking(); // Then return the tracker return mTracker; } }