firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.71k stars 3.97k forks source link

πŸ› [firebase_analytics] Events are not showing up on google analytics (ANDROID ONLY) FLUTTER APP #12178

Closed Alex-web0 closed 9 months ago

Alex-web0 commented 9 months ago

Bug report

Describe the bug Firebase google analytics package not logging any events on the dashboard. The app will not change anything in the realtime panel and only when I uninstall the app entirely does the logs show up

Steps to reproduce

Steps to reproduce the behavior:

  1. create a new flutter project
  2. install packages firebase_core, firebase_analytics of the latest versions
  3. create a firebase project with google analytics enabled and run flutterfire to link the project to the flutter app
  4. run the code below in your main (this is literally just the default counter app with the increment button dispatching a screen event to google analytics)
    
    import 'package:dio/dio.dart';
    import 'package:firebase_analytics/firebase_analytics.dart';
    import 'package:firebase_core/firebase_core.dart';
    import 'package:flutter/material.dart';

import 'firebase_options.dart';

void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, );

FirebaseAnalytics.instance;

runApp(MyApp(firebaseAnalytics: FirebaseAnalytics.instance)); }

class MyApp extends StatelessWidget { const MyApp({super.key, required this.firebaseAnalytics});

final FirebaseAnalytics firebaseAnalytics;

@override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', navigatorObservers: [ FirebaseAnalyticsObserver(analytics: FirebaseAnalytics.instance), ], theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: MyHomePage(title: 'Flutter Demo Home Page', firebaseAnalytics: firebaseAnalytics), ); } }

class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title, required this.firebaseAnalytics});

final FirebaseAnalytics firebaseAnalytics;

final String title;

@override State createState() => _MyHomePageState(); }

class _MyHomePageState extends State { int _counter = 0;

void _incrementCounter() async { try { FirebaseAnalytics.instance.setCurrentScreen(screenName: "ssss20832us8028$_counter"); await FirebaseAnalytics.instance.logEvent( name: 'first_open2', callOptions: AnalyticsCallOptions(global: true), parameters: { 'ss': "SCREEN${DateTime.timestamp().millisecondsSinceEpoch}", 'ss2': "FLUTTER_${DateTime.timestamp().millisecondsSinceEpoch}", }, ); } catch (e) { print(e); } setState(() {

  _counter++;
});

}

@override Widget build(BuildContext context) {

return Scaffold(
  appBar: AppBar(

    backgroundColor: Theme.of(context).colorScheme.inversePrimary,

    title: Text(widget.title),
  ),
  body: Center(

    child: Column(

      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        const Text(
          'You have pushed the button this many times:',
        ),
        Text(
          '$_counter',
          style: Theme.of(context).textTheme.headlineMedium,
        ),
      ],
    ),
  ),
  floatingActionButton: FloatingActionButton(
    onPressed: _incrementCounter,
    tooltip: 'Increment',
    child: const Icon(Icons.add),
  ), // This trailing comma makes auto-formatting nicer for build methods.
);

} }

5. (OPTIONAL) Change gradle as needed and add google services if gotten the error 
` google_app_id not found. Firebase Analytics Disabled`

- in build.gradle (project level):
```gradle
buildscript {
    // ! changed this version
    ext.kotlin_version = '1.9.20'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {

  // ! Changed this version
        classpath 'com.android.tools.build:gradle:7.4.1'
  // ! Added this dependency

        classpath 'com.google.gms:google-services:4.3.14'

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

In app/build.gradle:

dependencies {
     // added thsi line
    implementation 'com.google.firebase:firebase-analytics:21.5.0'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

in android object changed sdk versions to:

    defaultConfig {

        applicationId "com.example.shit_2"

        minSdkVersion 23 // ! added this
        targetSdkVersion 34 // ! added this
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

Add this to initial apply plugin statements:
apply plugin: 'com.google.gms.google-services' // added this

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

After applying this solution and then running

cd android

./gradlew clean

./gradlew build
  1. Run the app, and make sure no errors are logged in the console by flutter

Expected behavior

It is expected for logs to show up in this tab after I click the increment button which will dispatch an event of type screen_view just like in this screen, it only shows the user and no matter how many times I dispatch an event id doesn't work image

Sample project

sample_project_google_analytics_bug.zip


Additional context

I tried to : β€’ change the firebase_core and firebase_analytics versions to the lowest I could β€’ I tried flutter clean β€’ I tried to refresh, wait and debug the actual web console of google analytics β€’ connected and disconnected to the internet

I believe it has to do with the android implementation of the firebase_analytics plugin


Flutter doctor

``` Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.10.4, on Microsoft Windows [Version 10.0.19045.3930], locale en-US) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) [√] Chrome - develop for the web [√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.3) [√] Android Studio (version 2021.1) [√] Android Studio (version 2021.3) [√] Android Studio (version 2022.1) [√] IntelliJ IDEA Community Edition (version 2022.2) [√] VS Code (version 1.85.1) [√] Connected device (3 available) [√] Network resources β€’ No issues found! ```

Flutter dependencies

Click To Expand ``` Dart SDK 3.0.3 Flutter SDK 3.10.4 shit_2 1.0.0+1 dependencies: - cupertino_icons 1.0.6 - dio 5.4.0 [async http_parser meta path] - firebase_analytics 9.3.8 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_core 1.24.0 [firebase_core_platform_interface firebase_core_web flutter meta] - flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine] dev dependencies: - flutter_lints 2.0.3 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js matcher material_color_utilities me ta source_span stream_channel string_scanner term_glyph] dependency overrides: - firebase_core_platform_interface 4.5.1 [collection flutter flutter_test meta plugin_platform_interface] transitive dependencies: - _flutterfire_internals 1.0.2 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - async 2.11.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - characters 1.3.0 - clock 1.1.1 - cloud_firestore_platform_interface 5.7.7 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 2.8.10 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.17.1 - fake_async 1.3.1 [clock collection] - firebase_analytics_platform_interface 3.3.7 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.4.2+7 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_core_web 1.7.3 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - js 0.6.7 [meta] - lints 2.1.1 - matcher 0.12.15 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.2.0 - meta 1.9.1 - path 1.8.3 - plugin_platform_interface 2.1.8 [meta] - sky_engine 0.0.99 - source_span 1.9.1 [collection path term_glyph] - stack_trace 1.11.0 [path] - stream_channel 2.1.1 [async] - string_scanner 1.2.0 [source_span] - term_glyph 1.2.1 - test_api 0.5.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.3.2 [collection] - vector_math 2.1.4 ```

darshankawar commented 9 months ago

Thanks for the report. I ran the plugin example and will wait until tomorrow to see if the events were captured are not. Meantime, can you confirm if the events are being printed locally in the console ? ie, events are indeed being fired from plugin side ? This is just to confirm that the issue is with plugin or with firebase console that it is not able to receive the events.

Alex-web0 commented 9 months ago

Thanks for the report. I ran the plugin example and will wait until tomorrow to see if the events were captured are not. Meantime, can you confirm if the events are being printed locally in the console ? ie, events are indeed being fired from plugin side ? This is just to confirm that the issue is with plugin or with firebase console that it is not able to receive the events.

I have confirmed that actually, the events are not sent to the server, if you fire them they will not be sent until the app uninstalls

darshankawar commented 9 months ago

@Alex-web0 I verified in firebase console analytics dashboard and observed that the test_event was captured properly as shown below:

Screenshot 2024-01-23 at 3 43 08 PM Screenshot 2024-01-23 at 3 43 16 PM

https://github.com/firebase/flutterfire/blob/ed8c7c51d28398b1f68af404bdd855b75a1b1f56/packages/firebase_analytics/firebase_analytics/example/lib/main.dart#L95

Alex-web0 commented 9 months ago

@darshankawar Thank you so much, can you provide me with some more details

1) Did you run the example project only without changing any params other than firebase options 2) How much did the event take to appear on the dashboard, you mentioned in another reply that you would "wait for tomorrow" Is that related? 3) Can you please use the real-time tab on Google Analytics, I used it to produce the error in my example and the use case needs the realtime feature to work. Also if it doesn't log the events in real-time, try after logging some events to uninstall the app, they will all appear in one go.

darshankawar commented 9 months ago
  1. Did you run the example project only without changing any params other than firebase options

Yes.

2. How much did the event take to appear on the dashboard, you mentioned in another reply that you would "wait for tomorrow" Is that related?

Somewhat. It usually updates throughout the day periodically. You can read about it here.

3. Can you please use the real-time tab on Google Analytics,

This probably will be beyond the plugin's control, as the data is passed via firebase console to GA.

If you want to confirm really whether the events are indeed being triggered locally or not, you can try to use the adb command like this and see if it helps in your case or not.

google-oss-bot commented 9 months ago

Hey @Alex-web0. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 9 months ago

Since there haven't been any recent updates here, I am going to close this issue.

@Alex-web0 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.