Skip to content

Commit

Permalink
Firebase Analytics API
Browse files Browse the repository at this point in the history
  • Loading branch information
Khen Solomon Lethil committed Apr 3, 2021
1 parent 7c07989 commit ffbf71b
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions lib/util/analytics.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_analytics/observer.dart';

/// setup `FirebaseAnalytics`
///
/// Firebase Analytics API.
class UtilAnalytics {
static final FirebaseAnalytics _analytics = new FirebaseAnalytics();
static final FirebaseAnalyticsObserver _observer = FirebaseAnalyticsObserver(analytics: _analytics);

FirebaseAnalytics get send => _analytics;
get observer => _observer;

Future<void> search(String searchTerm) async {
if (searchTerm.isNotEmpty) await _analytics.logSearch(searchTerm:searchTerm);
}

Future<void> share(String contentType, String itemId) async {
await _analytics.logEvent(
name: 'share',
parameters: <String, dynamic>{
'content_type': contentType,
'item_id': itemId
}
);
}

Future<void> content(String contentType, String itemId) async {
// print('analyticsContent contentType:$contentType itemId: $itemId');
await _analytics.logEvent(
name: 'select_content',
parameters: <String, dynamic>{
'content_type': contentType,
'item_id': itemId
}
);
}

Future<void> book(String bibleName, String bookName, String chapterId) async {
await _analytics.logEvent(
name: 'select_book',
parameters: <String, dynamic>{
'content_name': bibleName,
'book_name': bookName,
'chapter_id': chapterId,
// 'item_id': itemId
}
);
}

Future<void> screen(String name, String classes) async {
// await new FirebaseAnalytics().setCurrentScreen(creenName: 'home',screenClassOverride: 'HomeState');
// print('analyticsScreen $name $classes');
await _analytics.setCurrentScreen(screenName: name,screenClassOverride: classes);
}

// Future<void> analyticsSetUserId() async {
// await new FirebaseAnalytics().setUserId('some-user');
// await this.analytics.then((FirebaseAnalytics e){
// e..setUserId('some-user');
// });
// }

// Future<Analytics> get googleAnalytics async{
// return appDirectory.then((FileSystemEntity e){
// return new AnalyticsIO(this.appAnalytics, join(e.path, 'analytics'), this.appVersion);
// });
// }
}

0 comments on commit ffbf71b

Please sign in to comment.