Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android google analytics integration error

When i am trying to get tracker in my activity it show error that -this method is undefine "getactivity()" in google analytic v4

// Get tracker.
    Tracker t = ((AnalyticsSampleApp) getActivity().getApplication())
            .getTracker(TrackerName.APP_TRACKER);
like image 765
user3736720 Avatar asked Jul 25 '14 07:07

user3736720


People also ask

How does Android integrate with Google Analytics?

Get the project If this is your first time using a Google services sample, check out the google-services repository. Open Android Studio. Select File > Open, browse to where you cloned the google-services repository, and open google-services/android/analytics .

What is Google Analytic integration?

The Google Analytics Platform lets you measure user interactions with your business across various devices and environments. Google Analytics provides the resources to collect, store, process, and report on these user-interactions. You can collect analytics on the client side and on the server side.


1 Answers

If you haven't done so already, create a class MyApplication extends Application for your app, and make sure you add it to your manifest as below (the property that matters here is android:name, I've removed the other xml properties for clarity).

<application
    android:name="mypackagename.MyApplication"
    ... >

Then, in your MyApplication class, create a method getTracker as per Google Analytics v4 documentation https://developers.google.com/analytics/devguides/collection/android/v4/#tracking-methods

Then, use

Tracker t = ((MyApplication) getApplication())
        .getTracker(TrackerName.APP_TRACKER);
like image 187
FreewheelNat Avatar answered Oct 20 '22 11:10

FreewheelNat