appmachina 1.0.0 copy "appmachina: ^1.0.0" to clipboard
appmachina: ^1.0.0 copied to clipboard

AppMachina SDK for Flutter. Analytics with ATT, SKAN, and deep link integrations.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:appmachina/appmachina.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Optional: register an error handler before init
  AppMachina.onError = (error) {
    debugPrint('SDK error: $error');
  };

  // 1. Initialize the SDK
  await AppMachina.init(AppMachinaConfig(
    appId: 'YOUR_APP_ID',
    enableDebug: true,
    environment: AppMachinaEnvironment.development,
  ));

  // 2. Identify the user (after login or from stored session)
  AppMachina.identify('example-user-42');

  // 3. Request ATT authorization on iOS (no-op on Android)
  final attStatus = await ATT.requestAuthorization();
  AppMachina.track('att_result', properties: {'status': attStatus.name});

  // 4. Set consent preferences
  AppMachina.setConsent(const ConsentSettings(
    analytics: true,
    advertising: false,
  ));

  // 5. Debug: print full SDK state
  AppMachina.debugPrintState();

  runApp(const AppMachinaExampleApp());
}

class AppMachinaExampleApp extends StatelessWidget {
  const AppMachinaExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AppMachina SDK Example',
      // 6. Automatic screen tracking via NavigatorObserver
      navigatorObservers: [AppMachinaNavigatorObserver()],
      theme: ThemeData(
        colorSchemeSeed: Colors.deepPurple,
        useMaterial3: true,
      ),
      home: const ExampleHome(),
    );
  }
}

class ExampleHome extends StatelessWidget {
  const ExampleHome({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('AppMachina SDK Example')),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          // Track a custom event
          FilledButton(
            onPressed: () {
              AppMachina.track('button_tapped', properties: {'screen': 'home'});
            },
            child: const Text('Track Event'),
          ),
          const SizedBox(height: 12),

          // Track a screen view
          FilledButton.tonal(
            onPressed: () {
              AppMachina.screen('SettingsScreen', properties: {'tab': 'general'});
            },
            child: const Text('Track Screen'),
          ),
          const SizedBox(height: 12),

          // Identify a different user
          OutlinedButton(
            onPressed: () {
              AppMachina.identify('new-user-99');
            },
            child: const Text('Identify User'),
          ),
          const SizedBox(height: 12),

          // Update consent
          OutlinedButton(
            onPressed: () {
              AppMachina.setConsent(const ConsentSettings(
                analytics: true,
                advertising: true,
              ));
            },
            child: const Text('Grant All Consent'),
          ),
          const SizedBox(height: 12),

          // Reset user state (logout flow)
          OutlinedButton(
            onPressed: () async {
              await AppMachina.reset();
            },
            child: const Text('Reset (Logout)'),
          ),
          const SizedBox(height: 12),

          // Debug print state
          OutlinedButton(
            onPressed: () {
              AppMachina.debugPrintState();
            },
            child: const Text('Debug Print State'),
          ),
          const SizedBox(height: 12),

          // Flush events
          OutlinedButton(
            onPressed: () {
              AppMachina.flush();
            },
            child: const Text('Flush Queue'),
          ),

          const SizedBox(height: 24),
          Text(
            'Session: ${AppMachina.sessionId ?? "N/A"}',
            style: Theme.of(context).textTheme.bodySmall,
          ),
          Text(
            'Queue: ${AppMachina.queueDepth} events',
            style: Theme.of(context).textTheme.bodySmall,
          ),
        ],
      ),
    );
  }
}
0
likes
125
points
39
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

AppMachina SDK for Flutter. Analytics with ATT, SKAN, and deep link integrations.

Homepage
Repository (GitHub)

License

MIT (license)

Dependencies

ffi, flutter, path_provider

More

Packages that depend on appmachina

Packages that implement appmachina