From 598820295f956df93e3f0c64ddd94109e70e2aa7 Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Mon, 18 Aug 2025 15:29:01 +0200 Subject: [PATCH] Android in Google Analytics (#3685) * android GA * test for now * removed test android * formatting and pangea comments --------- Co-authored-by: ggurdin <46800240+ggurdin@users.noreply.github.com> Co-authored-by: ggurdin --- android/app/build.gradle | 7 +++++-- android/app/google-services.json | 3 ++- android/build.gradle | 10 ++++++++++ android/settings.gradle | 2 +- lib/config/firebase_options.dart | 8 ++++---- .../common/utils/firebase_analytics.dart | 10 ++++++++++ lib/utils/background_push.dart | 18 ++++++++++++++---- 7 files changed, 46 insertions(+), 12 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 8ceb49f16..ce52c7683 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -2,7 +2,7 @@ plugins { id "com.android.application" id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" - //id "com.google.gms.google-services" + id "com.google.gms.google-services" } def localProperties = new Properties() @@ -100,7 +100,10 @@ flutter { } dependencies { - //implementation 'com.google.firebase:firebase-messaging:19.0.1' // Workaround for https://github.com/microg/android_packages_apps_GmsCore/issues/313#issuecomment-617651698 + implementation platform('com.google.firebase:firebase-bom:32.8.0') + implementation 'com.google.firebase:firebase-analytics' + implementation 'com.google.firebase:firebase-database' + implementation 'androidx.multidex:multidex:2.0.1' coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4") } diff --git a/android/app/google-services.json b/android/app/google-services.json index 565c634cb..03944c342 100644 --- a/android/app/google-services.json +++ b/android/app/google-services.json @@ -1,8 +1,9 @@ { "project_info": { "project_number": "545984292675", + "firebase_url": "https://pangea-chat-936ee-default-rtdb.firebaseio.com", "project_id": "pangea-chat-936ee", - "storage_bucket": "pangea-chat-936ee.appspot.com" + "storage_bucket": "pangea-chat-936ee.firebasestorage.app" }, "client": [ { diff --git a/android/build.gradle b/android/build.gradle index ff96015b6..25753ab39 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -14,4 +14,14 @@ subprojects { tasks.register("clean", Delete) { delete rootProject.buildDir +} + +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath 'com.google.gms:google-services:4.4.1' + } } \ No newline at end of file diff --git a/android/settings.gradle b/android/settings.gradle index 6ec443ee3..7f011b163 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -32,7 +32,7 @@ plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "8.7.3" apply false id "org.jetbrains.kotlin.android" version "2.1.10" apply false - // id "com.google.gms.google-services" version "4.3.8" apply false + id "com.google.gms.google-services" version "4.3.8" apply false } include ":app" \ No newline at end of file diff --git a/lib/config/firebase_options.dart b/lib/config/firebase_options.dart index a66f312bc..a0405c81b 100644 --- a/lib/config/firebase_options.dart +++ b/lib/config/firebase_options.dart @@ -52,7 +52,7 @@ class DefaultFirebaseOptions { projectId: 'pangea-chat-936ee', authDomain: 'pangea-chat-936ee.firebaseapp.com', databaseURL: 'https://pangea-chat-936ee-default-rtdb.firebaseio.com', - storageBucket: 'pangea-chat-936ee.appspot.com', + storageBucket: 'pangea-chat-936ee.firebasestorage.com', measurementId: 'G-FKP13VDEBX', ); @@ -62,7 +62,7 @@ class DefaultFirebaseOptions { messagingSenderId: '545984292675', projectId: 'pangea-chat-936ee', databaseURL: 'https://pangea-chat-936ee-default-rtdb.firebaseio.com', - storageBucket: 'pangea-chat-936ee.appspot.com', + storageBucket: 'pangea-chat-936ee.firebasestorage.com', androidClientId: '545984292675-2amsnoan1mt6lec1fld1a7eagu6gej7o.apps.googleusercontent.com', ); @@ -73,7 +73,7 @@ class DefaultFirebaseOptions { messagingSenderId: '545984292675', projectId: 'pangea-chat-936ee', databaseURL: 'https://pangea-chat-936ee-default-rtdb.firebaseio.com', - storageBucket: 'pangea-chat-936ee.appspot.com', + storageBucket: 'pangea-chat-936ee.firebasestorage.com', iosClientId: '545984292675-f5p76l3h9sibsonrct7a8l9ca3c69at0.apps.googleusercontent.com', iosBundleId: 'com.talktolearn.chat', @@ -85,7 +85,7 @@ class DefaultFirebaseOptions { messagingSenderId: '545984292675', projectId: 'pangea-chat-936ee', databaseURL: 'https://pangea-chat-936ee-default-rtdb.firebaseio.com', - storageBucket: 'pangea-chat-936ee.appspot.com', + storageBucket: 'pangea-chat-936ee.firebasestorage.com', iosClientId: '545984292675-f5p76l3h9sibsonrct7a8l9ca3c69at0.apps.googleusercontent.com', iosBundleId: 'com.talktolearn.chat', diff --git a/lib/pangea/common/utils/firebase_analytics.dart b/lib/pangea/common/utils/firebase_analytics.dart index c6c9397b1..fefe6308a 100644 --- a/lib/pangea/common/utils/firebase_analytics.dart +++ b/lib/pangea/common/utils/firebase_analytics.dart @@ -24,10 +24,20 @@ class GoogleAnalytics { options: DefaultFirebaseOptions.currentPlatform, ); } on Exception { + // Android initialises using gradle plugin + // So we just get the one they added app = Firebase.app(); } analytics = FirebaseAnalytics.instanceFor(app: app); + + debugPrint("Firebase App Name: ${app.name}"); + debugPrint("Firebase App Options:"); + debugPrint(" App ID: ${app.options.appId}"); + debugPrint(" Project ID: ${app.options.projectId}"); + debugPrint(" Database URL: ${app.options.databaseURL}"); + debugPrint(" Messaging Sender ID: ${app.options.messagingSenderId}"); + debugPrint(" Storage Bucket: ${app.options.storageBucket}"); } static analyticsUserUpdate(String? userID) { diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 4b3231fe8..64e6ab54e 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -25,7 +25,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:fcm_shared_isolate/fcm_shared_isolate.dart'; -import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_new_badger/flutter_new_badger.dart'; @@ -92,6 +91,19 @@ class BackgroundPush { ), onDidReceiveNotificationResponse: goToRoom, ); + + // #Pangea + FirebaseMessaging.onMessage.listen((RemoteMessage message) { + pushHelper( + PushNotification.fromJson(message.data), + client: client, + l10n: l10n, + activeRoomId: matrix?.activeRoomId, + flutterLocalNotificationsPlugin: _flutterLocalNotificationsPlugin, + ); + }); + // Pangea# + Logs().v('Flutter Local Notifications initialized'); firebase?.setListeners( onMessage: (message) => pushHelper( @@ -107,6 +119,7 @@ class BackgroundPush { onNewToken: _newFcmToken, // Pangea# ); + if (Platform.isAndroid) { await UnifiedPush.initialize( onNewEndpoint: _newUpEndpoint, @@ -547,9 +560,6 @@ class BackgroundPush { // #Pangea Future _getToken() async { if (Platform.isAndroid) { - await Firebase.initializeApp( - // options: DefaultFirebaseOptions.currentPlatform, - ); return (await FirebaseMessaging.instance.getToken()); } return await firebase?.getToken();