Manikandan
Manikandan

Reputation: 1519

GoogleAnalyticsTracker cannot be resolved to a type in android

I tried to use Google Analytics in my app. I created a account, registered for an app and got the reg number. Added the libGoogleAnalyticsV2.jar to my app build path. I tried to use the following code.

GoogleAnalyticsTracker tracker = GoogleAnalyticsTracker.getInstance();
tracker.setDebug(true);
tracker.startNewSession("UA code",10, this);

But I can't import GoogleAnalyticsTracker. It says

"GoogleAnalyticsTracker cannot be resolved to a type"

Update1

I used version1 of Google analytics. And used the following code. From P.T's answer, I waited for more than 24 hours. Still I can't see the user in RealTime overview. I used the following code in my class file.

GoogleAnalyticsTracker tracker;
tracker = GoogleAnalyticsTracker.getInstance();    
        tracker.startNewSession("UA code", 20,this);
        tracker.trackPageView("/BS_Splash");

Update 2

I tired with V2. Used the following code.

Context mCtx = this; // Get current context.
        GoogleAnalytics myInstance = GoogleAnalytics.getInstance(mCtx.getApplicationContext());
        myInstance.setDebug(true);
        Tracker myNewTracker = myInstance.getTracker("UA code");
        myInstance.setDefaultTracker(myNewTracker);

In log cat I got the following, connection to service failed 1

12-08 13:40:20.423: I/GAV2(22947): Thread[Service Reconnect,5,main]: connecting to Analytics service
12-08 13:40:20.423: I/GAV2(22947): Thread[Service Reconnect,5,main]: connect: bindService returned false for Intent { act=com.google.android.gms.analytics.service.START (has extras) }
12-08 13:40:20.423: W/GAV2(22947): Thread[Service Reconnect,5,main]: Connection to service failed 1
12-08 13:40:20.423: I/GAV2(22947): Thread[Service Reconnect,5,main]: falling back to local store
12-08 13:40:20.433: V/GAV2(22947): Thread[GAThread,5,main]: dispatch running...
12-08 13:40:20.623: V/GAV2(22947): Thread[GAThread,5,main]: ...nothing to dispatch
12-08 13:40:20.633: I/GAV2(22947): Thread[GAThread,5,main]: PowerSaveMode initiated.

Upvotes: 2

Views: 5237

Answers (2)

P.T.
P.T.

Reputation: 25177

Try downloading and installing the "legacy" (v1) GA library, or use the new V2 "Advanced" APIs.

The code you've got is assuming the V1 APIs, so its probably easiest to install the V1 library instead. See:

https://developers.google.com/analytics/devguides/collection/android/resources

Alternatively, you can find an equivalent snippet (that doesn't use EasyTracker) in the "Advanced" section of the V2 API documentation. See:

https://developers.google.com/analytics/devguides/collection/android/v2/advanced

Specifically, it looks like the global instance lookup now takes an Android Context argument, and its just GoogleAnalytics not GoogleAnalyticsTracker:

Context mCtx = this; // Get current context.
GoogleAnalytics myInstance = GoogleAnalytics.getInstance(mCtx.getApplicationContext());
myInstance.setDebug(true);

The tracker is now separate as the Tracker class:

Tracker myNewTracker = myInstance.getTracker("UA-XXXX-2") // A new tracking ID.

Upvotes: 3

Pavlos
Pavlos

Reputation: 2181

Try tracking using EasyTracker.getInstance().startActivity(this);

If it doesnt work either recheck the .jar file you added to your libs folder!

Upvotes: 0

Related Questions