From 8df37a858b6affa2a7e5fd7bd2fd1fdc586a08f0 Mon Sep 17 00:00:00 2001 From: kishan06 Date: Wed, 17 Apr 2024 11:48:40 +0530 Subject: [PATCH] google analytics added --- gsf/android/app/google-services.json | 24 ++----- gsf/firebase.json | 1 + gsf/ios/Runner.xcodeproj/project.pbxproj | 23 ++++++- .../xcshareddata/swiftpm/Package.resolved | 15 ---- gsf/ios/Runner/GoogleService-Info.plist | 16 ++--- gsf/lib/firebase_options.dart | 69 +++++++++++++++++++ gsf/lib/views/pages/home/home_page.dart | 42 +++++------ gsf/lib/views/pages/sidebar.dart | 34 +++++---- .../views/short_video_player/svp_main.dart | 37 +++++----- gsf/pubspec.lock | 24 +++++++ gsf/pubspec.yaml | 1 + 11 files changed, 183 insertions(+), 103 deletions(-) create mode 100644 gsf/firebase.json delete mode 100644 gsf/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved create mode 100644 gsf/lib/firebase_options.dart diff --git a/gsf/android/app/google-services.json b/gsf/android/app/google-services.json index 919ef07..a918776 100644 --- a/gsf/android/app/google-services.json +++ b/gsf/android/app/google-services.json @@ -1,36 +1,26 @@ { "project_info": { - "project_number": "751933368781", - "project_id": "gsf-live", - "storage_bucket": "gsf-live.appspot.com" + "project_number": "385912853035", + "project_id": "getsetfit-629ab", + "storage_bucket": "getsetfit-629ab.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:751933368781:android:020c5f5f7ec8ea880dfc84", + "mobilesdk_app_id": "1:385912853035:android:6aea48ea205d49ba8d906e", "android_client_info": { "package_name": "com.getsetfit.gsf" } }, - "oauth_client": [ - { - "client_id": "751933368781-v8k9ajguhps61ged7eis0ol1olflhfhv.apps.googleusercontent.com", - "client_type": 3 - } - ], + "oauth_client": [], "api_key": [ { - "current_key": "AIzaSyDd4MVv-SL6rw3t7aYtCW74_lA_GBMwJ_g" + "current_key": "AIzaSyDsuNF5SCgl9WbURv8FASws2d3dtBD-TIc" } ], "services": { "appinvite_service": { - "other_platform_oauth_client": [ - { - "client_id": "751933368781-v8k9ajguhps61ged7eis0ol1olflhfhv.apps.googleusercontent.com", - "client_type": 3 - } - ] + "other_platform_oauth_client": [] } } } diff --git a/gsf/firebase.json b/gsf/firebase.json new file mode 100644 index 0000000..6628f6a --- /dev/null +++ b/gsf/firebase.json @@ -0,0 +1 @@ +{"flutter":{"platforms":{"android":{"default":{"projectId":"getsetfit-629ab","appId":"1:385912853035:android:6aea48ea205d49ba8d906e","fileOutput":"android/app/google-services.json"}},"ios":{"default":{"projectId":"getsetfit-629ab","appId":"1:385912853035:ios:3c8d40e9b8cd8cc78d906e","uploadDebugSymbols":true,"fileOutput":"ios/Runner/GoogleService-Info.plist"}},"dart":{"lib/firebase_options.dart":{"projectId":"getsetfit-629ab","configurations":{"android":"1:385912853035:android:6aea48ea205d49ba8d906e","ios":"1:385912853035:ios:3c8d40e9b8cd8cc78d906e"}}}}}} \ No newline at end of file diff --git a/gsf/ios/Runner.xcodeproj/project.pbxproj b/gsf/ios/Runner.xcodeproj/project.pbxproj index edd0bb4..1792bca 100644 --- a/gsf/ios/Runner.xcodeproj/project.pbxproj +++ b/gsf/ios/Runner.xcodeproj/project.pbxproj @@ -27,7 +27,7 @@ 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; - EAC2B08A5EF3DB337047B851 /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + EAC2B08A5EF3DB337047B851 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; F28142B6420A67828003E26E /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 559CD4C37425C2E8E38C2D7D /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ @@ -118,7 +118,7 @@ 529068A72A8E5864004ABCB1 /* CoreServices.framework in Frameworks */, 529068A52A8E5706004ABCB1 /* BranchSDK in Frameworks */, 529068B82A8F4849004ABCB1 /* WebKit.framework in Frameworks */, - EAC2B08A5EF3DB337047B851 /* (null) in Frameworks */, + EAC2B08A5EF3DB337047B851 /* BuildFile in Frameworks */, F28142B6420A67828003E26E /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -250,6 +250,7 @@ 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 226DE2242AA76AB30069AF32 /* Embed Foundation Extensions */, C9D58640702688400651DCCA /* [CP] Embed Pods Frameworks */, + 0566BE68C33393A00546891A /* FlutterFire: "flutterfire upload-crashlytics-symbols" */, ); buildRules = ( ); @@ -329,6 +330,24 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 0566BE68C33393A00546891A /* FlutterFire: "flutterfire upload-crashlytics-symbols" */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "FlutterFire: \"flutterfire upload-crashlytics-symbols\""; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\n#!/bin/bash\nPATH=${PATH}:$FLUTTER_ROOT/bin:$HOME/.pub-cache/bin\nflutterfire upload-crashlytics-symbols --upload-symbols-script-path=$PODS_ROOT/FirebaseCrashlytics/upload-symbols --platform=ios --apple-project-path=${SRCROOT} --env-platform-name=${PLATFORM_NAME} --env-configuration=${CONFIGURATION} --env-project-dir=${PROJECT_DIR} --env-built-products-dir=${BUILT_PRODUCTS_DIR} --env-dwarf-dsym-folder-path=${DWARF_DSYM_FOLDER_PATH} --env-dwarf-dsym-file-name=${DWARF_DSYM_FILE_NAME} --env-infoplist-path=${INFOPLIST_PATH} --default-config=default\n"; + }; 13EB04CF12534CDD59BBA288 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/gsf/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved b/gsf/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index 5bf1daa..0000000 --- a/gsf/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -1,15 +0,0 @@ -{ - "originHash" : "da338c7d827a9f8b10177e484783685675c8dff84a9dc59a904db0c53122e9f5", - "pins" : [ - { - "identity" : "ios-branch-sdk-spm", - "kind" : "remoteSourceControl", - "location" : "https://github.com/BranchMetrics/ios-branch-sdk-spm", - "state" : { - "revision" : "7fbe3085821c8e60241a2037098c6eed76fd2798", - "version" : "2.2.0" - } - } - ], - "version" : 3 -} diff --git a/gsf/ios/Runner/GoogleService-Info.plist b/gsf/ios/Runner/GoogleService-Info.plist index ce9584e..996c499 100644 --- a/gsf/ios/Runner/GoogleService-Info.plist +++ b/gsf/ios/Runner/GoogleService-Info.plist @@ -2,22 +2,18 @@ - CLIENT_ID - 751933368781-0cgjotkpv6o238qrm9g9u1cgcq5pkf91.apps.googleusercontent.com - REVERSED_CLIENT_ID - com.googleusercontent.apps.751933368781-0cgjotkpv6o238qrm9g9u1cgcq5pkf91 API_KEY - AIzaSyAEz8aya-EsS6ebSSVgDxc4X6vlU3Lh5EY + AIzaSyCSbLj_8QTuCyJlZ_e4jLSxTs-Qj-lG60k GCM_SENDER_ID - 751933368781 + 385912853035 PLIST_VERSION 1 BUNDLE_ID - com.getsetfit + com.getsetfit.OneSignalNotificationServiceExtension PROJECT_ID - gsf-live + getsetfit-629ab STORAGE_BUCKET - gsf-live.appspot.com + getsetfit-629ab.appspot.com IS_ADS_ENABLED IS_ANALYTICS_ENABLED @@ -29,6 +25,6 @@ IS_SIGNIN_ENABLED GOOGLE_APP_ID - 1:751933368781:ios:1b07754b53887f3d0dfc84 + 1:385912853035:ios:3c8d40e9b8cd8cc78d906e \ No newline at end of file diff --git a/gsf/lib/firebase_options.dart b/gsf/lib/firebase_options.dart new file mode 100644 index 0000000..a0c8964 --- /dev/null +++ b/gsf/lib/firebase_options.dart @@ -0,0 +1,69 @@ +// File generated by FlutterFire CLI. +// ignore_for_file: type=lint +import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; +import 'package:flutter/foundation.dart' + show defaultTargetPlatform, kIsWeb, TargetPlatform; + +/// Default [FirebaseOptions] for use with your Firebase apps. +/// +/// Example: +/// ```dart +/// import 'firebase_options.dart'; +/// // ... +/// await Firebase.initializeApp( +/// options: DefaultFirebaseOptions.currentPlatform, +/// ); +/// ``` +class DefaultFirebaseOptions { + static FirebaseOptions get currentPlatform { + if (kIsWeb) { + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for web - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + return android; + case TargetPlatform.iOS: + return ios; + case TargetPlatform.macOS: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for macos - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.windows: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for windows - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.linux: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for linux - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + default: + throw UnsupportedError( + 'DefaultFirebaseOptions are not supported for this platform.', + ); + } + } + + static const FirebaseOptions android = FirebaseOptions( + apiKey: 'AIzaSyDsuNF5SCgl9WbURv8FASws2d3dtBD-TIc', + appId: '1:385912853035:android:6aea48ea205d49ba8d906e', + messagingSenderId: '385912853035', + projectId: 'getsetfit-629ab', + storageBucket: 'getsetfit-629ab.appspot.com', + ); + + static const FirebaseOptions ios = FirebaseOptions( + apiKey: 'AIzaSyCSbLj_8QTuCyJlZ_e4jLSxTs-Qj-lG60k', + appId: '1:385912853035:ios:3c8d40e9b8cd8cc78d906e', + messagingSenderId: '385912853035', + projectId: 'getsetfit-629ab', + storageBucket: 'getsetfit-629ab.appspot.com', + iosBundleId: 'com.getsetfit.OneSignalNotificationServiceExtension', + ); + +} \ No newline at end of file diff --git a/gsf/lib/views/pages/home/home_page.dart b/gsf/lib/views/pages/home/home_page.dart index e962df3..6efb7e3 100644 --- a/gsf/lib/views/pages/home/home_page.dart +++ b/gsf/lib/views/pages/home/home_page.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:math'; +import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:flutter/material.dart'; import 'package:flutter_branch_sdk/flutter_branch_sdk.dart'; import 'package:get/get.dart'; @@ -37,39 +38,27 @@ class _HomePageState extends State { StreamSubscription? streamSubscription; StreamController controllerData = StreamController(); AppDataController appDataController = Get.find(); + static List pageNames = [ + "Home", + "Workout", + "Bioscale", + "Leaderboard", + "Bites" + ]; + //Analytics start--- + final FirebaseAnalytics analytics = FirebaseAnalytics.instance; + + //Analytics end--- @override void initState() { listenDynamicLinks(); callingBannerApiForHomeScreen(); - + analytics.setAnalyticsCollectionEnabled(true); + super.initState(); } - // bool apicalled = false; - // @override - // void initState() { - // // TODO: implement initState - // super.initState(); - // // moodOMeter(); - // // var moodResult = await MoodOMeterService().getMoodOMeter(); - // // // if() - // // if(moodResult.responseStatus != ResponseStatus.success ){ - // // return const HomePageSkeleton(); - // // } - // } - - // moodOMeter() async { - // var moodResult = await MoodOMeterService().getMoodOMeter(); - // // if() - // if(moodResult.responseStatus != ResponseStatus.success ){ - // // return const HomePageSkeleton(); - // setState(() { - // apicalled = true; - // }); - // } - // } - //DeepLinkingSetup -by Kishan void listenDynamicLinks() async { @@ -212,6 +201,9 @@ class _HomePageState extends State { backgroundColor: Colors.black, body: Obx( () { + analytics.logScreenView( + screenName: pageNames[homePageController.bottomNavIndex.value], + ); switch (homePageController.bottomNavIndex.value) { case 0: return const Home(); diff --git a/gsf/lib/views/pages/sidebar.dart b/gsf/lib/views/pages/sidebar.dart index 39885b5..09e949d 100644 --- a/gsf/lib/views/pages/sidebar.dart +++ b/gsf/lib/views/pages/sidebar.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; @@ -136,6 +137,8 @@ class _AppDrawerState extends State { children: [ headTitel('The Podium'), menuWidget('quiz', 'Quiz Section', () { + FirebaseAnalytics.instance + .logScreenView(screenName: "Quiz"); Get.back(); Get.to( () => const QuizHome(), @@ -144,6 +147,8 @@ class _AppDrawerState extends State { const SizedBox(height: 15), menuWidget('quiz', 'Menstrual cycle tracker', () { + FirebaseAnalytics.instance.logScreenView( + screenName: "Menstrual cycle tracker"); final isFilled = StorageService().readinitialSetup(); if (isFilled) { Get.back(); @@ -169,7 +174,7 @@ class _AppDrawerState extends State { // 2; // if (homePageController.bottomNavIndex.value == // 1) { - // homePageController.updateBottomNavIndex(0); + // homePageController.updateBottomNavIndex(0); // homePageController.updateBottomNavIndex(1); // Get.back(); // } else { @@ -184,22 +189,21 @@ class _AppDrawerState extends State { // ), // const SizedBox(height: 40), headTitel('External Motivation'), - menuWidget( - 'podcast', - 'Podcasts', - () => Get.to( - () => const PodcastMain(), - ), - false), + menuWidget('podcast', 'Podcasts', () { + FirebaseAnalytics.instance + .logScreenView(screenName: "Podcasts"); + Get.to( + () => const PodcastMain(), + ); + }, false), const SizedBox(height: 15), - menuWidget( - 'news_articles', - 'News & Articles', - () => Get.to( + menuWidget('news_articles', 'News & Articles', () { + FirebaseAnalytics.instance + .logScreenView(screenName: "News & Articles"); + Get.to( () => const BlogMain(), - ), - false - ), + ); + }, false), const SizedBox(height: 15), // menuWidget( // 'instagram', diff --git a/gsf/lib/views/short_video_player/svp_main.dart b/gsf/lib/views/short_video_player/svp_main.dart index 7697ad4..6989735 100644 --- a/gsf/lib/views/short_video_player/svp_main.dart +++ b/gsf/lib/views/short_video_player/svp_main.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:math'; import 'package:another_flushbar/flushbar.dart'; +import 'package:firebase_analytics/firebase_analytics.dart'; // import 'package:firebase_dynamic_links/firebase_dynamic_links.dart'; import 'package:flutter/material.dart'; import 'package:flutter_branch_sdk/flutter_branch_sdk.dart'; @@ -279,7 +280,8 @@ class _SvpMain extends State { } List videoPlayerControllers = []; - + int secondsVideoWatched = 0; + Timer? timercounter; @override void initState() { videoPlayerControllers = ShortClipTemp.tempClips @@ -299,6 +301,11 @@ class _SvpMain extends State { ..initialize() ..setLooping(true); } + //Logging video duration + timercounter = Timer.periodic(const Duration(seconds: 1), (timer) { + secondsVideoWatched++; + }); + super.initState(); } @@ -309,6 +316,7 @@ class _SvpMain extends State { for (final ctrl in videoPlayerControllers) { ctrl.dispose(); } + timercounter?.cancel(); super.dispose(); } @@ -351,12 +359,6 @@ class _SvpMain extends State { .add(ShortClipLikesModel(shortClipId: clip.id, isLiked: false)); } - // return VideoPage( - // fetchedClips: fetchedClips, - // fetchedLikes: myLikes, - // index: widget.index, - // ); - return SafeArea( child: Theme( data: ThemeData( @@ -375,6 +377,15 @@ class _SvpMain extends State { onPageChanged: (index) { //on swipe up (NEXT) if (index > prevPgIndex) { + int prevVideoDuration = secondsVideoWatched; + secondsVideoWatched = 0; + print("video ran for $prevVideoDuration"); + print("video ran for ${fetchedClips[index - 1].title}"); + FirebaseAnalytics.instance + .logEvent(name: "video_views", parameters: { + "video_title": fetchedClips[index - 1].title, + "video_duration": prevVideoDuration + }); if (index - 2 >= 0) { videoPlayerControllers[index - 2].dispose(); } @@ -419,11 +430,6 @@ class _SvpMain extends State { prevPgIndex = index; }, - - // itemBuilder: (context, index) { - // return VideoPlayer(videoPlayerControllers[index]); - // } - itemBuilder: (context, index) { ShortClipModel shortClipModel = fetchedClips[index]; sortLikes(shortClipModel, fetchedLikes); @@ -432,13 +438,6 @@ class _SvpMain extends State { return Stack( alignment: AlignmentDirectional.bottomCenter, children: [ - // SvPlayer( - // //podPlayerController: podPlayerController, - // pageController: pageController, - // videoUrl: shortClipModel.videoUrl, - // currentPageIndex: index, - // pagesCount: fetchedClips.length, - // ), VideoPlayer(videoPlayerControllers[index]), //like & share diff --git a/gsf/pubspec.lock b/gsf/pubspec.lock index 7759843..a9dce35 100644 --- a/gsf/pubspec.lock +++ b/gsf/pubspec.lock @@ -457,6 +457,30 @@ packages: url: "https://pub.dev" source: hosted version: "6.1.4" + firebase_analytics: + dependency: "direct main" + description: + name: firebase_analytics + sha256: "624f234b0cb27c4d1c983d03489570471d85d5720159512c8e080cb6917a0a2b" + url: "https://pub.dev" + source: hosted + version: "10.7.0" + firebase_analytics_platform_interface: + dependency: transitive + description: + name: firebase_analytics_platform_interface + sha256: "7e6cae535f3f2ab19ddb183ed48010f852baa20999a473b764c3db4e73d3fa0b" + url: "https://pub.dev" + source: hosted + version: "3.8.0" + firebase_analytics_web: + dependency: transitive + description: + name: firebase_analytics_web + sha256: ff080e7793ab71f73fb4cb5223922638024144c1deecb3ec71c81e69f64409df + url: "https://pub.dev" + source: hosted + version: "0.5.5+7" firebase_core: dependency: "direct main" description: diff --git a/gsf/pubspec.yaml b/gsf/pubspec.yaml index 7066fe1..f1859d3 100644 --- a/gsf/pubspec.yaml +++ b/gsf/pubspec.yaml @@ -108,6 +108,7 @@ dependencies: animated_horizontal_calendar: ^0.0.3 firebase_crashlytics: any firebase_core: ^2.4.1 + firebase_analytics: any flutter_background: ^1.2.0 package_info_plus: any circular_countdown_timer: ^0.2.3