Skip to main content

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

AppSynk Mobile Attribution SDK — bridge over the native iOS/Android SDKs.

example/lib/main.dart

import 'dart:async';

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

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // Initialize the SDK once at startup. Replace with your own API key
  // (ak_live_... in production; the prefix selects the environment).
  await AppSynk.configure(
    'ak_sandbox_example',
    options: const AppSynkOptions(logLevel: AppSynkLogLevel.debug),
  );
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: HomePage());
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  AttributionData? _attribution;
  String _attStatus = 'unknown';
  StreamSubscription<AttributionData>? _deepLinkSub;

  @override
  void initState() {
    super.initState();
    _loadAttribution();
    // Deferred / resolved deep links, auto-captured natively (no forwarding).
    _deepLinkSub = AppSynk.onDeepLink.listen((data) {
      if (!mounted) return;
      setState(() => _attribution = data);
      _toast('Deep link: ${data.deepLink ?? data.source ?? 'received'}');
    });
  }

  Future<void> _loadAttribution() async {
    final data = await AppSynk.getAttributionData();
    if (!mounted) return;
    setState(() => _attribution = data);
  }

  @override
  void dispose() {
    _deepLinkSub?.cancel();
    super.dispose();
  }

  void _toast(String message) {
    ScaffoldMessenger.of(context)
      ..hideCurrentSnackBar()
      ..showSnackBar(SnackBar(content: Text(message)));
  }

  @override
  Widget build(BuildContext context) {
    final attribution = _attribution;
    final summary = attribution == null
        ? 'none'
        : (attribution.source ?? 'organic');
    return Scaffold(
      appBar: AppBar(title: const Text('AppSynk example')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Attribution: $summary'),
            if (attribution != null)
              Text('Campaign: ${attribution.campaignName ?? '—'}'),
            if (attribution != null)
              Text('Deep link: ${attribution.deepLink ?? '—'}'),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: () {
                AppSynk.trackEvent('level_complete', properties: {'level': 5});
                _toast('trackEvent: level_complete');
              },
              child: const Text('Track event'),
            ),
            ElevatedButton(
              onPressed: () {
                AppSynk.trackRevenue(
                  9.99,
                  'EUR',
                  'premium_monthly',
                  'ORDER_123',
                );
                _toast('trackRevenue: 9.99 EUR');
              },
              child: const Text('Track revenue'),
            ),
            ElevatedButton(
              onPressed: () async {
                final status = await AppSynk.requestTrackingAuthorization();
                if (!mounted) return;
                setState(() => _attStatus = status);
                _toast('ATT: $status');
              },
              child: Text('Request ATT (status: $_attStatus)'),
            ),
            ElevatedButton(
              onPressed: _loadAttribution,
              child: const Text('Refresh attribution'),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
150
points
38
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

AppSynk Mobile Attribution SDK — bridge over the native iOS/Android SDKs.

Homepage
Repository (GitHub)
View/report issues

Topics

#attribution #analytics #mmp #deep-linking

License

MIT (license)

Dependencies

flutter

More

Packages that depend on appsynk

Packages that implement appsynk