I am trying to split my Google Analytics code into a separate module (package com.abc) from my main app (package com.xyz). I am facing these issues :
What I have tried (and failed) :
Go to Analytics and select the Analytics account you registered the app with. If you're unsure, look for the Analytics tracking ID in the google-services. json file you added to your project earlier. Copy that ID to the Analytics account search in the report drop-down.
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest.
Google Analytics collects usage and behavior data for your web app. The SDK logs two primary types of information: Events: What is happening in your app, such as user actions, system events, or errors.
Instead of using R.xml.global_tracker.You can use this code in your Application class.
/**
* @return tracker
*/
synchronized public Tracker getDefaultTracker() {
if (mTracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
// To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
analytics.setLocalDispatchPeriod(1800);
mTracker = analytics.newTracker("Tracker code");
analytics.setLocalDispatchPeriod(1);
mTracker.enableExceptionReporting(true);
mTracker.enableAdvertisingIdCollection(true);
mTracker.enableAutoActivityTracking(false);
}
return mTracker;
}
And use it in the activity/fragment like this:
MyApplication application = (MyApplication ) context.getApplication();
Tracker mTracker = application.getDefaultTracker();
mTracker.setScreenName(name);
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
This might resolve your problem, not tested for your case though.
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