Google analytics android sdk 4 newTracker undefined

I've been looking through the documentation and resources on the Google Analytics site to implement it with Android SDK 4. I've gone through a few Stack Overflow posts, but others seem to have other issues. I followed the steps to initialize the tracker by creating a class that extends the application to configure the tracker as well as my e-commerce and global trackers.

In my application class, everything follows from the example, but the "newTracker" method is undefined. I have libGoogleAnalyticsServices.jar in my library and below is my class. Thanks for watching, I am very confused.

import java.util.HashMap;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;

import android.app.Application;

public class GlobalState extends Application {
    private static final String PROPERTY_ID = "myNumber";
    private Tracker tracker;
    HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();

    public enum TrackerName {
        APP_TRACKER,
        GLOBAL_TRACKER,
        E_COMMERCE_TRACKER,
    }


    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);
    }

      

}

+3


source to share


1 answer


I faced this problem,

Try to remove libGoogleAnalyticsServices.jar from your project. I believe this is the old way of incorporating Google Analytics into your application.

Follow the instructions at http://developer.android.com/google/play-services/setup.html

In short, Google Analytics is now included in the Google Play Services Library project.



To summarize the instructions in the link, import the project located at   <android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/

Include Google Play Services as a library project in your application.

Add:    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

as a child of your app's statement in your manifest.

+3


source







All Articles