V
V
Valery2014-12-15 09:32:08
Google
Valery, 2014-12-15 09:32:08

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'

Added to the application class:
private Tracker appTracker;

public Tracker getTracker() {
    if (appTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        appTracker = analytics.newTracker(R.xml.global_tracker);
    }

    return appTracker;
}

And, accordingly, global_tracker.xml:
<?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>

Added to activation:
@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();
    }

In the manifest, inside application:
<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/global_tracker" />

Come on, everything should work. And it seems even in the logs the lines of sending statistics are visible.
But, after a weekend, nothing appeared in the analytics (I walked around the application in the emulator and on a real device).
In addition, the application freezes at startup. No errors, no warnings. Just a white activity with a title and that's it.
Actually, what am I doing wrong? Or maybe there is an adequate guide to setting up analytics? In the off-documentation, everything is somehow incomprehensible and too confusing.
Before that, I connected ya.metrica - no problems, but the customer rebelled and wants Google Analytics.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
anyd3v, 2014-12-15
@anyd3v

Add in the manifest
Remove "Added to the application class:"
Stop is better done before super.onStop

B
Bady55, 2015-03-24
@Bady55

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 question

Ask a Question

731 491 924 answers to any question