Fire the call inside your add-to-cart action handler — after the cart state is updated locally. Don't pass the SKU, price, quantity, or variant; your commerce backend has all of them.
▸Install the Flutter SDK
# pubspec.yaml
dependencies:
flutter:
sdk: flutter
respectlytics_flutter: ^3.0.0
Pure Dart — no platform channels for analytics. Same code on every platform Flutter compiles to (iOS, Android, web, macOS, Windows, Linux). On web, events are sent via the REST API; mobile platforms use the same path.
▸Initialize Respectlytics in Flutter
import 'package:flutter/material.dart';
import 'package:respectlytics_flutter/respectlytics_flutter.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Respectlytics.configure(appKey: '<YOUR_APP_KEY>');
runApp(const MyApp());
}
Initialize in main() after WidgetsFlutterBinding.ensureInitialized() and before runApp(). The future completes immediately on configuration; events queued before completion are flushed once the network is available.
▸Track the event in Flutter
import 'package:respectlytics_flutter/respectlytics_flutter.dart';
Future<void> addToCart(String productId, {int quantity = 1}) async {
await cartApi.add(productId, quantity);
Respectlytics.track('add_to_cart');
}
Future<void> removeFromCart(String productId) async {
await cartApi.remove(productId);
Respectlytics.track('remove_from_cart');
}
Same discipline as other frameworks — productId / qty stay in your cart API, not in the analytics call.
✦Privacy & implementation notes
Your commerce platform (Shopify, BigCommerce, your own service) is the authoritative cart system — it has SKU, price, quantity, variant, with proper retention and access policies. Mirroring cart contents into product analytics duplicates a system of record and produces drift the moment products are renamed or repriced.
Most product decisions about add-to-cart are about rate changes — "did the new product detail page move our DE iOS add-to-cart rate?". That question doesn't require knowing what specific items got added; it requires knowing the count of add_to_cart events relative to product_detail_view.
The Flutter SDK is pure Dart. No MethodChannel, no platform-specific iOS or Android plugin code. The same code runs on every platform Flutter supports — including web and desktop targets. This eliminates one common audit surface ("what's the Android implementation doing?").
Always initialize after WidgetsFlutterBinding.ensureInitialized() and before runApp(). If you skip the binding step, the configure call will throw on platforms that need a binding for asynchronous I/O. The SDK documentation example uses this pattern by default.
⇋How this compares to other analytics SDKs
| Add-to-cart event | Firebase Analytics | Mixpanel | Respectlytics |
|---|---|---|---|
| SKU / variant ID | Recommended | Recommended | Out of scope |
| Price / currency / quantity | Recommended | Recommended | Rejected by API |
| Cart total at this step | Recommended | Recommended | Out of scope |
| Per-user cart abandonment recovery | Yes | Yes | Out of scope (use cart backend) |
| Add-to-cart *rate* by country / platform | Yes | Yes | Yes |
❓Frequently asked questions
How do we know what's in users' carts without storing items?
Your commerce backend already has authoritative cart state per user. Respectlytics tells you the add-to-cart rate and how it correlates with checkout completion at the session level. Per-user abandoned-cart recovery is a marketing-automation use case, handled by your cart backend's webhooks (Shopify Plus, Klaviyo, etc.).
What about category-level adds (apparel vs electronics)?
If you have a small fixed set of top-level categories (under 8), distinct event names: add_to_cart_apparel, add_to_cart_electronics. Past that, skip the breakdown — your commerce backend has the granular data.
Should we instrument every cart-line edit (quantity changes, removals)?
Removals: yes, distinct event name remove_from_cart — the rate of removals near checkout is a UX signal. Quantity changes: not usually; they don't carry much product signal at the aggregate.
What if the same user adds and removes the same item rapidly?
Both events fire — Respectlytics doesn't dedupe. The rate of remove_from_cart shortly after add_to_cart is itself a UX signal (price reveal, shipping shock, etc.). Bucketing rates over country / platform makes those patterns visible without per-user tracking.