Answer the question
In order to leave comments, you need to log in
Why does GoogleAnalytics freeze in an Android app?
Hello,
I'm trying to add google analytics to an app in android studio.
Added to gradle
compile 'com.google.android.gms:play-services:6.5.87'
private Tracker appTracker;
public Tracker getTracker() {
if (appTracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
appTracker = analytics.newTracker(R.xml.global_tracker);
}
return appTracker;
}
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyDashes">
<string name="ga_trackingId">UA-53398***-*</string>
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_reportUncaughtExceptions">true</bool>
<screenName name="......">
Так перечисляются различные активити....
</screenName>
</resources>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((App) getApplication()).getTracker();
}
@Override
protected void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
protected void onStop() {
GoogleAnalytics.getInstance(this).reportActivityStop(this);
super.onStop();
}
<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/global_tracker" />
Answer the question
In order to leave comments, you need to log in
Add in the manifest
Remove "Added to the application class:"
Stop is better done before super.onStop
A similar problem, I connected the Analyst to the application, I test it on a virtual machine, I see that the statistics appear (Analyst is in real time), I transfer my application to my real phone or tablet, it freezes on (of course when the application starts):
GoogleAnalytics.getInstance( this).reportActivityStart(this);
I tried to put this on the button press (while commenting on the line above in OnStart):
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(TrackerName.APP_TRACKER);
t.setScreenName("MainScreen");
t.send(new HitBuilders.AppViewBuilder().build());
the same trouble, it works on a virtual machine, on a real phone it hangs only when the button is pressed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question