Respectlytics Respect lytics
Menu
Flutter Content shared Privacy-first

How to track content share events in Flutter without personal data

Content share — "share to Messages", "share to Twitter", "copy link" — is a viral-loop signal in social and content apps. Most analytics SDKs default to logging the destination app, the shared content ID, and sometimes the recipient. Respectlytics helps developers avoid collecting personal data in the first place: in Flutter, share is one named event per channel, with no payload. Below: the Flutter share-sheet integration, why channel goes in the event name, and what stays out.

Fire the call inside the share-sheet completion callback when the user has actually completed the share (not when they open the sheet — abandonment is common). Encode the chosen channel into the event name.

Install the Flutter SDK

yaml Respectlytics
# 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

dart Respectlytics
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

dart Respectlytics
import 'package:respectlytics_flutter/respectlytics_flutter.dart';
import 'package:share_plus/share_plus.dart';

Future<void> shareContent(String text) async {
  final result = await Share.share(text);
  if (result.status == ShareResultStatus.success) {
    final channel = result.raw.isEmpty ? 'other' : result.raw.toLowerCase();
    Respectlytics.track('share_$channel');
  } else if (result.status == ShareResultStatus.dismissed) {
    Respectlytics.track('share_cancelled');
  }
}

share_plus's result.raw is set on iOS but typically empty on Android. Treat the empty-string case as share_other.

Privacy & implementation notes

Putting the channel as a parameter ({ channel: 'twitter' }) is the natural first instinct and is exactly what Respectlytics's API rejects. Encode it as the event name — share_twitter — and you get the same downstream queryability without storing parameters.

Fire on share completion, not on share-sheet presentation. Share-sheet presentation is fairly common (the user is just exploring); actual completion is much rarer and is the meaningful signal. The two rates differ by 5–10× in most apps.

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

Share eventFirebase AnalyticsMixpanelRespectlytics
Share channel as parameterRecommendedRecommendedUse distinct event_name
Shared content IDRecommendedRecommendedOut of scope (use content backend)
Recipient data (when accessible)PossiblePossibleForbidden (PII)
Per-user share countYesYesOut of scope
Share rate by content / channelPer-userPer-userUse distinct event_names + content backend

Frequently asked questions

How do we know which channels are most popular?

Distinct event names per channel: share_imessage, share_email, share_twitter, share_copy_link. Aggregation gives per-channel rate. iOS's UIActivityViewController and Android's Intent chooser deliver the selected channel in the completion callback — encode it into the event name.

What about shared content metadata?

Stays in your content backend. The CMS or content database knows what was shared. Respectlytics tells you that a share happened in this session — the join to specific content is a backend concern.

Can we measure share-induced installs?

Server-side via deferred deep links and install attribution. App Store Connect / Play Console deliver the attribution; your backend correlates the shared link's tracking parameter with the resulting install. Respectlytics doesn't ingest install attribution — it's not the right system for that.

What if the share sheet completes but the user cancels?

iOS's UIActivityViewController and Android's Intent chooser both call back with a cancellation flag. Don't fire share_* on cancel — fire share_cancelled (a single event regardless of channel) if you want to track abandonment.

Related guides

Track what matters. Collect nothing you don't.

Five-field event schema, RAM-only event queue, no IDFA, no AAID, no persistent user IDs. Helps developers avoid collecting personal data in the first place.