Jeremy
Jeremy

Reputation: 251

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 the Android SDK 4. I have went through multiple stack overflow posts, but others seem to be having other issues. I have followed the steps of initializing the tracker, creating a class that extends application to setup the tracker, as well as my ecommerce, and global trackers.

On my application class, everything follows through from the example, but the "newTracker" method is undefined. I have the libGoogleAnalyticsServices.jar in my library and below is my class. Thank you for taking a look, i'm 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);
    }

}

Upvotes: 3

Views: 877

Answers (1)

EL45
EL45

Reputation: 469

I just ran into this problem,

Try removing libGoogleAnalyticsServices.jar from your project. I believe this is the old way of including Google analytics to your app.

Next 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 item to your application declaration in your manifest.

Upvotes: 3

Related Questions