liquid_posthog 0.2.0
liquid_posthog: ^0.2.0 copied to clipboard
PostHog (product analytics, session replay, feature flags) destination for liquid_analytics.
// PostHog as a liquid destination — product analytics, session replay and
// feature flags, cloud or self-hosted.
import 'package:liquid_analytics/liquid_analytics.dart';
import 'package:liquid_posthog/liquid_posthog.dart';
/// PostHog preserves the nested shapes a typed event naturally produces.
class CheckoutStarted extends LiquidEvent {
const CheckoutStarted({required this.cartValue, required this.items});
final double cartValue;
final List<String> items;
@override
String get name => 'checkout_started';
@override
Map<String, Object?> get properties => {
'cart_value': cartValue,
'items': items, // lists and nested maps arrive intact
};
}
Future<void> main() async {
final liquid = Liquid(
sinks: [
PostHogSink(
apiKey: 'phc_xxx',
host: 'https://eu.i.posthog.com', // or your self-hosted instance
configure: (config) => config.captureApplicationLifecycleEvents = true,
defaultGroupType: 'organization',
),
],
consent: const ConsentPolicy(
requireOptIn: true,
map: {
ConsentCategory.analytics: ['posthog'],
},
),
);
await liquid.init();
// Held until the user opts in, then replayed.
liquid.log(const CheckoutStarted(cartValue: 42, items: ['sku_1', 'sku_2']));
liquid.consent.grant(ConsentCategory.analytics);
// PostHog models liquid's full surface natively.
liquid.screen('Cart');
liquid.identify('user_123', {'plan': 'pro'});
liquid.group('acme_inc', {'seats': 40});
liquid.alias('user_123');
await liquid.flush();
await liquid.reset();
await liquid.dispose();
}