Flutter SDK
Coming soon
The Flutter SDK will provide event tracking and identity for Flutter apps with parity to the Web SDK.
Track progress: cotton-web-sdk (Web SDK repo — Flutter SDK will be a separate package)
Interim integration
Until the Flutter SDK ships, send events directly via the Connect RPC API.
Add dependencies
# pubspec.yaml
dependencies:
http: ^1.2.0Send events
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<void> trackEvent(String name, Map<String, dynamic> properties) async {
final response = await http.post(
Uri.parse('https://api.pug.sh/events.v1.EventsService/BatchCreate'),
headers: {
'Authorization': 'Bearer YOUR_SDK_API_KEY',
'x-project-id': 'YOUR_PROJECT_ID',
'Content-Type': 'application/json',
'Connect-Protocol-Version': '1',
},
body: jsonEncode({
'events': [
{
'name': name,
'properties': properties,
'timestamp': DateTime.now().toUtc().toIso8601String(),
}
]
}),
);
if (response.statusCode != 200) {
throw Exception('Track failed: ${response.body}');
}
}
// Usage
await trackEvent('page_view', {'screen': 'Home'});
await trackEvent('purchase', {'revenue': 29.99, 'currency': 'USD', 'order_id': 'ord-123'});Identify users
Future<void> identifyUser(String externalId, Map<String, dynamic> traits) async {
await http.post(
Uri.parse('https://api.pug.sh/profiles.v1.ProfilesSDKService/Identify'),
headers: {
'Authorization': 'Bearer YOUR_SDK_API_KEY',
'x-project-id': 'YOUR_PROJECT_ID',
'Content-Type': 'application/json',
'Connect-Protocol-Version': '1',
},
body: jsonEncode({
'externalId': externalId,
'traits': traits,
}),
);
}Flutter Web
For Flutter Web targets, use the Web SDK directly via JS interop — it handles batching, sessions, and auto-tracking.
Planned features
-
init/track/identify/resetparity with Web SDK - Automatic session management
- Offline queue with flush on reconnect
- Auto-track app lifecycle events
- Dart protobuf client generated from proto
Further reading
- Events API — BatchCreate reference
- Profiles API — Identify reference
Last updated on