Java 无法解析Google Analytics导入
我试图用Google Analytics跟踪页面浏览量,但在导入过程中不断出现错误。我在下面的代码中列出了错误所在的位置 我还将jar文件放在java构建路径中,并在Android清单中添加了两行 我的问题是如何正确编译下面的代码Java 无法解析Google Analytics导入,java,android,import,google-analytics,Java,Android,Import,Google Analytics,我试图用Google Analytics跟踪页面浏览量,但在导入过程中不断出现错误。我在下面的代码中列出了错误所在的位置 我还将jar文件放在java构建路径中,并在Android清单中添加了两行 我的问题是如何正确编译下面的代码 import com.google.android.apps.analytics.GoogleAnalyticsTracker; //Error: "The import com.google.android.apps cannot be resolved" p
import com.google.android.apps.analytics.GoogleAnalyticsTracker; //Error: "The import com.google.android.apps cannot be resolved"
public class MainMenu extends Activity {
GoogleAnalyticsTracker tracker; //Error: "The import com.google.android.apps cannot be resolved to a type"
final Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.mainmenumain);
tracker = GoogleAnalytics.getInstance();
tracker.startSession("UA-38788135-1", this);
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
tracker.trackPageView("/Categories"); //Error: "The import com.google.android.apps cannot be resolved to a type"
Intent intent = new Intent(MainMenu.this, Categories.class);
startActivity(intent);
}
});
btn2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
tracker.trackPageView("/Highscores"); //Error: "The import com.google.android.apps cannot be resolved to a type"
Intent intent = new Intent(MainMenu.this, Highscores.class);
startActivity(intent);
}
});
btn3.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
tracker.trackPageView("/About"); //Error: "The import com.google.android.apps cannot be resolved to a type"
Intent intent = new Intent(MainMenu.this, About.class);
startActivity(intent);
}
});
btn4.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
tracker.trackPageView("/ComingSoon"); //Error: "The import com.google.android.apps cannot be resolved to a type"
Intent intent = new Intent(MainMenu.this, ComingSoon.class);
startActivity(intent);
}
});
}
libGoogleAnalyticsV1.jar中使用了GoogleAnalyticsTracker,但您使用的是最新版本的libGoogleAnalyticsV2.jar。要在libGoogleAnalyticsV2中跟踪页面视图,请使用以下代码 申报 内部onCreate方法
GaInstance = GoogleAnalytics.getInstance(this);
GaTracker = GaInstance.getTracker("YOUR UA-Here");
GaTracker.sendView("/YourActivity");
libGoogleAnalyticsV1.jar中使用了GoogleAnalyticsTracker,但您使用的是最新版本的libGoogleAnalyticsV2.jar。要在libGoogleAnalyticsV2中跟踪页面视图,请使用以下代码 申报 内部onCreate方法
GaInstance = GoogleAnalytics.getInstance(this);
GaTracker = GaInstance.getTracker("YOUR UA-Here");
GaTracker.sendView("/YourActivity");
您试图在google analytics中跟踪按钮点击,但不要在onClick中使用trackPageView跟踪按钮事件
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
tracker.trackPageView("/Categories"); //Error: "The import com.google.android.apps cannot be resolved to a type"
Intent intent = new Intent(MainMenu.this, Categories.class);
startActivity(intent);
}
});
使用此代码跟踪onClick内部的按钮事件,而不是上面的onClick代码
GaTracker.trackEvent("Your Buttons Category", "Your event name", "", 0L);
GAServiceManager.getInstance().dispatch();
申报
private Tracker GaTracker;
private GoogleAnalytics GaInstance;
内部onCreate方法使用
GaInstance = GoogleAnalytics.getInstance(this);
GaTracker = GaInstance.getTracker("YOUR UA-Here");
GaTracker.sendView("/YourActivity"); // Include this line if you want to track page view
您试图在google analytics中跟踪按钮点击,但不要在onClick中使用trackPageView跟踪按钮事件
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
tracker.trackPageView("/Categories"); //Error: "The import com.google.android.apps cannot be resolved to a type"
Intent intent = new Intent(MainMenu.this, Categories.class);
startActivity(intent);
}
});
使用此代码跟踪onClick内部的按钮事件,而不是上面的onClick代码
GaTracker.trackEvent("Your Buttons Category", "Your event name", "", 0L);
GAServiceManager.getInstance().dispatch();
申报
private Tracker GaTracker;
private GoogleAnalytics GaInstance;
内部onCreate方法使用
GaInstance = GoogleAnalytics.getInstance(this);
GaTracker = GaInstance.getTracker("YOUR UA-Here");
GaTracker.sendView("/YourActivity"); // Include this line if you want to track page view
@Eric-我之前发现这个话题,但解决方案不起作用。在提出问题之前,你应该分享你尝试过的东西;了解这种情况会对我们有所帮助。分析jar必须位于libs文件夹中。不要把罐子放在libs/GoogleAnalyticsAndroid中,把它放在/libs中。查看文件系统上的实际文件或Eclipse中的navigator视图。ADT和GA要求路径本身不要弄乱Eclipse设置,只需将其放在libs和clean中,这样就可以了。如果您不想这样做,也没关系,但您可能使用的另一个类是Tracker,而不是GoogleAnalyticsTracker。没有名为GoogleAnalyticsTracker的类,因此出现错误。请参阅我之前链接的入门文档,这应该会有所帮助。顺便说一句,这个问题与链接到此处已关闭项目的其他问题不同。我投票决定重新开张。这可能是其他问题的重复,但不是这里结尾提到的问题。在GoogleAnalytics V1中,有一个名为GoogleAnalyticsTracker的类,这是遗留的:。在V2中,该类不存在!V2有用于上下文的GoogleAnalytics和用于跟踪视图和事件等的跟踪器。@Eric-我之前发现了该主题,但解决方案不起作用。在提问之前,您应该始终分享您尝试过的内容;了解这种情况会对我们有所帮助。分析jar必须位于libs文件夹中。不要把罐子放在libs/GoogleAnalyticsAndroid中,把它放在/libs中。查看文件系统上的实际文件或Eclipse中的navigator视图。ADT和GA要求路径本身不要弄乱Eclipse设置,只需将其放在libs和clean中,这样就可以了。如果您不想这样做,也没关系,但您可能使用的另一个类是Tracker,而不是GoogleAnalyticsTracker。没有名为GoogleAnalyticsTracker的类,因此出现错误。请参阅我之前链接的入门文档,这应该会有所帮助。顺便说一句,这个问题与链接到此处已关闭项目的其他问题不同。我投票决定重新开张。这可能是其他问题的重复,但不是这里结尾提到的问题。在GoogleAnalytics V1中,有一个名为GoogleAnalyticsTracker的类,这是遗留的:。在V2中,该类不存在!V2具有用于上下文的GoogleAnalytics和用于跟踪视图和事件等的跟踪器。