dozz_analytics_sdk 0.1.1
dozz_analytics_sdk: ^0.1.1 copied to clipboard
Consent-aware, offline-first mobile analytics and click attribution for Flutter applications.
dozz_analytics_sdk #
Consent-aware, offline-first analytics and trusted click attribution for Flutter applications on Android and iOS.
Installation #
flutter pub add dozz_analytics_sdk:^0.1.1
Setup #
Create one SDK instance for the application. The write key identifies the customer application; it is public mobile configuration, not an administrative secret.
import 'package:dozz_analytics_sdk/dozz_analytics_sdk.dart';
import 'package:http/http.dart' as http;
final httpClient = http.Client();
final analytics = DozzAnalyticsSdk(
config: DozzAnalyticsConfig(
endpoint: Uri.parse('https://track.example.com/sdk/v1/events'),
writeKey: const String.fromEnvironment('DOZZ_WRITE_KEY'),
),
storage: SharedPreferencesDozzStorage(),
httpClient: HttpDozzClient(httpClient),
);
await analytics.initialize();
final lifecycle = DozzAnalyticsLifecycle(analytics)..start();
Pass the launch URL to initialize(initialUrl: ...) when the application's linking integration provides one. Forward later deep links from the same handler:
Future<void> onDeepLink(Uri deepLink) async {
await analytics.captureAttribution(deepLink.toString());
}
The SDK only reads a valid UUID click_id. It ignores client-provided affiliate or payout data.
Consent #
Consent begins as unknown. No event is created or delivered until the user makes a real analytics choice:
Future<void> saveAnalyticsChoice(bool accepted) {
return analytics.setConsent(
accepted ? DozzConsent.granted : DozzConsent.denied,
);
}
Changing consent away from granted aborts active delivery and clears queued events and attribution. analytics.reset() additionally erases consent and anonymous identity.
Tracking #
await analytics.trackScreen('ride_home', {'entry_kind': 'deep_link'});
await analytics.trackTap('request_ride');
await analytics.trackRide('requested', {
'vehicle_class': 'standard',
'estimated_fare_bucket': '10_15',
});
await analytics.trackEvent('search_completed', {'result_count': 8});
String properties are lowercase categorical values containing only letters, numbers, underscores, and hyphens. Long digit sequences are rejected as possible phone or account identifiers. Numeric properties are non-negative integers no greater than 1,000,000. Unsupported properties and values are discarded before persistence.
Never send names, email addresses, phone numbers, precise coordinates, addresses, free-form search text, authentication tokens, advertising identifiers, or customer/driver IDs.
Journey events are analytics evidence only. They must not approve affiliate payouts or replace a server-to-server conversion postback.
Lifecycle and diagnostics #
Dispose the lifecycle observer and HTTP client with their owner:
lifecycle.dispose();
httpClient.close();
The SDK persists events in shared_preferences until acknowledged or permanently rejected, and retries temporary failures with bounded backoff. Production endpoints must use HTTPS; HTTP is accepted only for localhost development. Invalid configuration throws ArgumentError or RangeError; storage failures propagate to the caller so the application can keep analytics disabled and report the failure through its existing error pipeline.
analytics.getDiagnostics();
// {'dropped_events': 0, 'rejected_events': 0}
dropped_events counts bounded-queue evictions. rejected_events counts events discarded after a permanent server rejection.
Documentation #
License #
This is proprietary software. A written Dozz customer agreement is required before production use.