liquid_firebase 0.2.0 copy "liquid_firebase: ^0.2.0" to clipboard
liquid_firebase: ^0.2.0 copied to clipboard

Firebase Analytics (Google Analytics for Firebase / GA4) destination for liquid_analytics.

example/main.dart

// Firebase Analytics (GA4) as a liquid destination.
//
// Note: call `Firebase.initializeApp(...)` from `firebase_core` before this
// runs. It is omitted here because `firebase_core` is your app's dependency,
// not this package's.
import 'package:liquid_analytics/liquid_analytics.dart';
import 'package:liquid_firebase/liquid_firebase.dart';

/// A typed event. Defining it once pins the `snake_case` naming that survives
/// Firebase's sanitizer, instead of relying on every call site.
class CheckoutStarted extends LiquidEvent {
  const CheckoutStarted({required this.cartValue, this.isGift = false});

  final double cartValue;
  final bool isGift;

  @override
  String get name => 'checkout_started'; // already Firebase-legal

  @override
  Map<String, Object?> get properties => {
        'cart_value': cartValue,
        'is_gift': isGift, // encoded as 1/0 by FirebaseEventMapper
      };
}

Future<void> main() async {
  // await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

  final firebase = FirebaseSink();

  final liquid = Liquid(
    sinks: [firebase],
    consent: const ConsentPolicy(
      requireOptIn: true,
      map: {
        ConsentCategory.analytics: ['firebase'],
      },
    ),
  );
  await liquid.init();

  // Mirror liquid's decision into Firebase Consent Mode so Firebase itself
  // honors the user's choice, not just liquid's gate.
  liquid.consent.addListener(() {
    firebase.applyConsent(
      analyticsGranted: liquid.consent.statusOf(ConsentCategory.analytics) ==
          ConsentStatus.granted,
      adsGranted: liquid.consent.statusOf(ConsentCategory.marketing) ==
          ConsentStatus.granted,
    );
  });

  // Held until the user opts in.
  liquid.log(const CheckoutStarted(cartValue: 42, isGift: true));
  liquid.consent.grant(ConsentCategory.analytics); // buffered events replay

  liquid.screen('Cart'); // -> logScreenView
  liquid.identify('user_123', {'plan': 'pro'}); // -> setUserId + user property

  // Firebase advertises no `group`/`alias` capability, so these cost nothing.
  liquid.group('acme_inc');

  await liquid.flush();
  await liquid.dispose();
}
0
likes
160
points
13
downloads

Documentation

API reference

Publisher

verified publisherketok.id

Weekly Downloads

Firebase Analytics (Google Analytics for Firebase / GA4) destination for liquid_analytics.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#analytics #firebase #flutter

License

MIT (license)

Dependencies

firebase_analytics, flutter, liquid_analytics, meta

More

Packages that depend on liquid_firebase