Skip to content

[🐛] 🔥 Analytics not working on release APK #8713

@elozino-eryk

Description

@elozino-eryk

Issue

Describe your issue here


Analytics events are not being logged on release builds. However, there are being logged on debug events in real time.

Project Files

Javascript

Click To Expand

package.json:

    "@react-native-firebase/analytics": "^23.3.1",
    "@react-native-firebase/app": "^23.3.1",
    "@react-native-firebase/messaging": "^23.3.1",
    "react-native": "0.77.0",
    "react": "18.3.1",
import {
  FirebaseAnalyticsTypes,
  getAnalytics,
  getAppInstanceId as firebaseGetAppInstanceId,
  logEvent as firebaseLogEvent,
  setAnalyticsCollectionEnabled as firebaseSetAnalyticsCollectionEnabled,
} from '@react-native-firebase/analytics';

export class FirebaseAnalyticsService {
  private static analytics: FirebaseAnalyticsTypes.Module = getAnalytics();

  public static async setCollectionEnabled(enabled: boolean): Promise<void> {
    try {
      await firebaseSetAnalyticsCollectionEnabled(this.analytics, enabled);

      if (__DEV__) {
        console.log(
          `[FirebaseAnalyticsService] Analytics collection ${
            enabled ? 'enabled' : 'disabled'
          }`,
        );
      }
    } catch (error) {
      if (__DEV__) {
        console.error(
          '[FirebaseAnalyticsService] Failed to set analytics collection:',
          error,
        );
      }
    }
  }

  public static async getAppInstanceId(): Promise<string | null> {
    try {
      return await firebaseGetAppInstanceId(this.analytics);
    } catch (error) {
      if (__DEV__) {
        console.error(
          '[FirebaseAnalyticsService] Failed to get App Instance ID:',
          error,
        );
      }
      return null;
    }
  }

  public static async logEvent(
    event:
      | ReservedFirebaseAnalyticsEvent
      | CustomFirebaseAnalyticsEvent
      | string,
    params?: Record<string, unknown>,
  ): Promise<void> {
    try {
      await firebaseLogEvent(this.analytics, event.toString(), params);

      if (__DEV__) {
        console.log(
          `[FirebaseAnalyticsService] Event logged: ${event}`,
          params,
        );
      }
    } catch (error) {
      if (__DEV__) {
        console.error(
          `[FirebaseAnalyticsService] Failed to log event: ${event}`,
          error,
        );
      }
    }
  }

  /**
   * Convenience wrapper for select_content
   */
  public static async logSelectContent(
    contentType: string,
    itemId: string,
  ): Promise<void> {
    return this.logEvent(ReservedFirebaseAnalyticsEvent.SelectContent, {
      content_type: contentType,
      item_id: itemId,
    });
  }
}


// In my root navigator
  useEffect(() => {
    (async () => {
      const appInstanceId = await FirebaseAnalyticsService.getAppInstanceId();
      await FirebaseAnalyticsService.logEvent(
        CustomFirebaseAnalyticsEvent.AppInstanceId,
        {appInstanceId},
      );
    })();
  }, []);

firebase.json for react-native-firebase v6:

{
  "react-native": {
    "analytics_auto_collection_enabled": true,
    "messaging_auto_init_enabled": true,
    "messaging_ios_auto_register_for_remote_messages": true,
    "messaging_android_notification_channel_id": "high-priority",
    "messaging_android_headless_task_timeout": 30000,
    "google_analytics_automatic_screen_reporting_enabled": true,
    "messaging_ios_foreground_presentation_options": []
  }
}

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
  config = use_native_modules!
  $RNFirebaseAnalyticsWithoutAdIdSupport = true

  use_react_native!(
    :path => config[:reactNativePath],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )
  
  pod 'FirebaseCore', :modular_headers => true
  pod 'FirebaseCoreInternal', :modular_headers => true
  pod 'FirebaseInstallations', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

buildscript {
    ext {
        buildToolsVersion = "35.0.0"
        minSdkVersion = 24
        compileSdkVersion = 35
        targetSdkVersion = 35
        ndkVersion = "27.1.12297006"
        kotlinVersion = "2.0.21"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
        classpath("com.google.gms:google-services:4.4.2")
    }
}

apply plugin: "com.facebook.react.rootproject"

android/app/build.gradle:

apply plugin: 'com.google.gms.google-services'


dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")
    implementation project(':react-native-splash-screen')
    implementation 'androidx.core:core:1.13.1'
    implementation 'androidx.appcompat:appcompat:1.5.0'  // or the latest version
    implementation("androidx.activity:activity:1.9.+")  // or the latest version


    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools">

  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.CALL_PHONE" />

  <uses-feature android:name="android.hardware.telephony" android:required="false" />

  <application
    android:name=".MainApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher"
    android:roundIcon="@mipmap/ic_launcher"
    android:allowBackup="false"
    android:theme="@style/AppTheme"
    android:supportsRtl="true">
    <activity
      android:name=".MainActivity"
      android:label="@string/app_name"
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
      android:launchMode="singleTask"
      android:screenOrientation="portrait"
      android:windowSoftInputMode="adjustResize"
      android: exported="true">
    </activity>
  </application>
</manifest>


Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE

System:
  OS: macOS 15.6.1
  CPU: (11) arm64 Apple M3 Pro
  Memory: 138.27 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.16.0
    path: /var/folders/px/ws4dqjkn063gwsm5_mvxhl5w0000gn/T/yarn--1758879086801-0.47891096171310377/node
  Yarn:
    version: 1.22.22
    path: /var/folders/px/ws4dqjkn063gwsm5_mvxhl5w0000gn/T/yarn--1758879086801-0.47891096171310377/yarn
  npm:
    version: 10.9.2
    path: /usr/local/bin/npm
  Watchman:
    version: 2025.05.26.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/eryk/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.0
      - iOS 26.0
      - macOS 26.0
      - tvOS 26.0
      - visionOS 26.0
      - watchOS 26.0
  Android SDK:
    API Levels:
      - "34"
      - "35"
      - "36"
    Build Tools:
      - 34.0.0
      - 35.0.0
    System Images:
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
      - android-34 | ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | Google APIs ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
      - android-36 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.26094.121.2513.14007798
  Xcode:
    version: 26.0.1/17A400
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 3.2.0
    path: /Users/eryk/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.77.0
    wanted: 0.77.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • e.g. 5.4.3
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y/N & VERSION
      "typescript": "5.0.4"


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions