Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable auto-activity tracking in Firebase

I'm wondering, are there any way to disable analytics auto activity tracking? I have view hierarchy based on fragments and there are few cases:

  1. Activity that have one fragment always.
  2. Activity that can have different fragments as root.
  3. Activity with root fragment, that contains ViewPager with other fragments.

I use such a code in fragments from Firebase docs to track custom screens:

mFirebaseAnalytics.setCurrentScreen(getActivity(), "some_fragment_1", null);

In first case, I want to track only root fragment. In second case, I want to track only each fragment that becomes root. In third case, I want to track only each fragment that becomes visible in ViewPager.

And, the problem is, that I don't want to track Activities at all, but unfortunately, Firebase do it on its own - as a result of that, my statistics looks weird, like:

SomeActivity 50%

some_fragment_1 30%

some_fragment_2 20%

I dont't need activity in this statistics, because, fragment statistics already includes it.

So, is there any way to disable activity tracking?

like image 711
Boris Rozhkovsky Avatar asked Sep 06 '25 07:09

Boris Rozhkovsky


1 Answers

Now it's possible with new API to manually track screens.

Can disable auto-tracking

On iOS, set FirebaseAutomaticScreenReportingEnabled to NO in your info.plist. On Android, set google_analytics_automatic_screen_reporting_enabled to false in your manifest.

Manual Tracking

iOS

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    // After enough time has passed to make this screen view significant.
    Analytics.logEvent(AnalyticsEventScreenView, parameters: [
        AnalyticsParameterScreenName: screenName!,
        AnalyticsParameterScreenClass: screenClass!,
        MyAppAnalyticsParameterFitnessCategory: category!
    ])
}

Android

@Override
public void onResume() {
    super.onResume();

    // After enough time has passed to make this screen view significant.
    Bundle bundle = new Bundle();
    bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, screenName);
    bundle.putString(FirebaseAnalytics.Param.SCREEN_CLASS, screenClass);
    bundle.putString(MyAppAnalyticsConstants.Param.TOPIC, topic);
    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle);
}

https://firebase.googleblog.com/2020/08/google-analytics-manual-screen-view.html

like image 54
iori24 Avatar answered Sep 07 '25 20:09

iori24