Reputation: 309
I'm trying to use google analytics in my project. and the newTracker method cannot be found. Also, I have no need for the ecommerce tracker so I took it out. But now i can't close the statement with getting the error
: is expected here''
I commented where the error shows up below.
import android.app.Application;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;
import java.util.HashMap;
public class AnalyticsTracker1 extends Application {
private static final String PROPERTY_ID = "UA-xxxxxxx-1";
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, 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); //: expected here
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
}
Upvotes: 0
Views: 2025
Reputation: 1372
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
: (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker) : null;
Modify your code like this , if trackerID is not equal to any of enum then it should return null. Error is coming as you have not completed second ternary operator. For second problem I assume that you have imported google analytics jar into your project. If it is than it wont work. Solution in that case :
4 . add
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
to application tag of your manifest.
and it will work.
I have checked its working now.
Upvotes: 1