liquid_segment 0.2.0
liquid_segment: ^0.2.0 copied to clipboard
Segment destination for liquid_analytics — Segment as one sink among many, not as a hub. Full Spec surface (track/screen/identify/group/alias/reset).
// Segment as ONE liquid destination among many — not as the hub.
//
// liquid already owns fan-out and consent, so Segment sits alongside your
// other adapters as a peer rather than routing all traffic through it.
import 'package:liquid_analytics/liquid_analytics.dart';
import 'package:liquid_segment/liquid_segment.dart';
class CheckoutStarted extends LiquidEvent {
const CheckoutStarted({required this.cartValue, this.isGift = false});
final double cartValue;
final bool isGift;
@override
String get name => 'checkout_started';
@override
Map<String, Object?> get properties => {
'cart_value': cartValue,
'is_gift': isGift,
};
}
Future<void> main() async {
final liquid = Liquid(
sinks: [
SegmentSink(writeKey: 'YOUR_WRITE_KEY'),
// Peers, not Segment plugins — add FirebaseSink(), PostHogSink(...), etc.
DebugSink(),
],
consent: const ConsentPolicy(
requireOptIn: true,
map: {
ConsentCategory.analytics: ['segment', 'debug'],
},
),
);
await liquid.init();
// One call reaches Segment and every peer sink.
liquid.log(const CheckoutStarted(cartValue: 42, isGift: true));
liquid.consent.grant(ConsentCategory.analytics); // buffered events replay
// Segment's full Spec surface is mapped 1:1.
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();
}