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);
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 .
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With