Skip to main content

herald_firebase 1.2.0 copy "herald_firebase: ^1.2.0" to clipboard
herald_firebase: ^1.2.0 copied to clipboard

A Herald vendor adapter that sends to Firebase Analytics (GA4).

example/herald_firebase_example.dart

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/widgets.dart';
import 'package:herald/herald.dart';
import 'package:herald_firebase/herald_firebase.dart';

final class const CheckoutStarted(final String plan, final int seats) extends Event {
  @override
  String get name => 'checkout_started';

  @override
  Map<String, AnalyticsValue> get parameters => {'plan': .string(plan), 'seats': .int(seats)};
}

HeraldProvider firebaseProvider(FirebaseAnalytics analytics) {
  final tracker = FirebaseAnalyticsTrackerService(
    eventTrackerFactory: CompositeFirebaseEventTrackerFactory([
      ScreenViewFirebaseEventTrackerFactory(analytics), // GA4's reserved screen_view
      GenericFirebaseEventTrackerFactory(analytics), // everything else, as-is
    ]),
    propertySetterFactory: CompositeFirebasePropertySetterFactory([
      GenericFirebasePropertySetterFactory(analytics),
    ]),
  );
  final service = FirebaseAnalyticsService(analytics);
  return HeraldProvider(
    name: 'firebase',
    events: tracker,
    properties: tracker,
    identity: service,
    lifecycle: service,
    consent: service,
  );
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // Call Firebase.initializeApp() here, as Firebase's setup guide shows.
  final herald = Herald(providers: [firebaseProvider(FirebaseAnalytics.instance)]);

  await herald.start();
  await herald.track(const CheckoutStarted('pro', 3));
}
0
likes
160
points
565
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

A Herald vendor adapter that sends to Firebase Analytics (GA4).

Repository (GitHub)
View/report issues
Contributing

Topics

#analytics #firebase #google-analytics #tracking

License

Apache-2.0 (license)

Dependencies

firebase_analytics, flutter, herald

More

Packages that depend on herald_firebase