flux_analytics_sdk 0.1.13 copy "flux_analytics_sdk: ^0.1.13" to clipboard
flux_analytics_sdk: ^0.1.13 copied to clipboard

Flux Analytics official Flutter SDK for tracking events, sessions, and user identity.

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _isInitialized = false;

  @override
  void initState() {
    super.initState();
    _initFlux();
  }

  Future<void> _initFlux() async {
    // Demo API Key and IDs
    await Flux.init(
      appId: 'demo-app-123',
      firmId: 'demo-firm-456',
      apiKey: 'your-supabase-anon-key', // Replace with a real key for testing
      debug: true,
    );

    Flux.identify('tester@example.com');

    setState(() {
      _isInitialized = true;
    });
  }

  void _fakePurchase() {
    Flux.trackRevenue(19.99, 'USD', {'item': 'starter_pack'});
    ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(content: Text('Flux: Gelir Takip Edildi! (\$19.99) 💰')),
    );
  }

  void _upgradeUser() {
    Flux.setUserProperty('user_type', 'premium');
    ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(content: Text('Flux: Kullanıcı Özelliği Güncellendi! ✨')),
    );
  }

  void _trackScreen() {
    Flux.trackScreen('SettingsPage');
    ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(content: Text('Flux: Ekran Takip Edildi! 📱')),
    );
  }

  void _setCampaign() {
    Flux.setCampaign('summer_sale_2024');
    ScaffoldMessenger.of(
      context,
    ).showSnackBar(const SnackBar(content: Text('Flux: Kampanya Atandı! 📣')));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(useMaterial3: true, colorSchemeSeed: Colors.indigo),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flux SDK Advanced Demo'),
          centerTitle: true,
        ),
        body: SingleChildScrollView(
          padding: const EdgeInsets.all(24),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Icon(
                _isInitialized ? Icons.check_circle : Icons.hourglass_empty,
                size: 64,
                color: _isInitialized ? Colors.green : Colors.orange,
              ),
              const SizedBox(height: 16),
              Text(
                _isInitialized ? 'Flux SDK Hazır' : 'SDK Başlatılıyor...',
                style: const TextStyle(
                  fontSize: 18,
                  fontWeight: FontWeight.bold,
                ),
              ),
              if (_isInitialized && Flux.anonymousId != null) ...[
                const SizedBox(height: 8),
                Text(
                  'Anonim ID: ${Flux.anonymousId!.substring(0, 8)}...',
                  style: const TextStyle(fontSize: 12, color: Colors.grey),
                ),
              ],
              const SizedBox(height: 32),
              const Text(
                'Analitik Aksiyonları',
                style: TextStyle(
                  fontSize: 14,
                  fontWeight: FontWeight.w900,
                  color: Colors.grey,
                  letterSpacing: 1.2,
                ),
              ),
              const SizedBox(height: 16),
              _buildActionButton(
                onPressed: _isInitialized ? _upgradeUser : null,
                icon: Icons.star,
                label: 'Kullanıcıyı Premium Yap',
                color: Colors.amber,
              ),
              _buildActionButton(
                onPressed: _isInitialized ? _fakePurchase : null,
                icon: Icons.shopping_cart,
                label: '19.99\$ Satın Alma Yap',
                color: Colors.teal,
              ),
              _buildActionButton(
                onPressed: _isInitialized ? _trackScreen : null,
                icon: Icons.layers,
                label: 'Ekran Görüntüleme Kaydet',
                color: Colors.blue,
              ),
              _buildActionButton(
                onPressed: _isInitialized ? _setCampaign : null,
                icon: Icons.campaign,
                label: 'Kampanya Atat (Summer Sale)',
                color: Colors.purple,
              ),
              const SizedBox(height: 24),
              const Text(
                'Derin Analiz (Phase 4)',
                style: TextStyle(
                  fontSize: 14,
                  fontWeight: FontWeight.w900,
                  color: Colors.grey,
                  letterSpacing: 1.2,
                ),
              ),
              const SizedBox(height: 16),
              Row(
                children: [
                  Expanded(
                    child: _buildActionButton(
                      onPressed: _isInitialized ? () => Flux.setAge(25) : null,
                      icon: Icons.cake,
                      label: 'Yaş: 25',
                      color: Colors.orange,
                    ),
                  ),
                  const SizedBox(width: 12),
                  Expanded(
                    child: _buildActionButton(
                      onPressed: _isInitialized
                          ? () => Flux.setGender('f')
                          : null,
                      icon: Icons.person_outline,
                      label: 'Cinsiyet: K',
                      color: Colors.pink,
                    ),
                  ),
                ],
              ),
              Row(
                children: [
                  Expanded(
                    child: _buildActionButton(
                      onPressed: _isInitialized
                          ? () => Flux.startScreen('GamePage')
                          : null,
                      icon: Icons.play_arrow,
                      label: 'Ekran Başlat',
                      color: Colors.green,
                    ),
                  ),
                  const SizedBox(width: 12),
                  Expanded(
                    child: _buildActionButton(
                      onPressed: _isInitialized
                          ? () => Flux.endScreen('GamePage')
                          : null,
                      icon: Icons.stop,
                      label: 'Ekran Bitir',
                      color: Colors.red,
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildActionButton({
    required VoidCallback? onPressed,
    required IconData icon,
    required String label,
    required Color color,
  }) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 12),
      child: SizedBox(
        width: double.infinity,
        child: ElevatedButton.icon(
          onPressed: onPressed,
          icon: Icon(icon, size: 20),
          label: Text(label),
          style: ElevatedButton.styleFrom(
            backgroundColor: color.withOpacity(0.1),
            foregroundColor: color,
            padding: const EdgeInsets.symmetric(vertical: 16),
            side: BorderSide(color: color.withOpacity(0.2)),
            elevation: 0,
          ),
        ),
      ),
    );
  }
}
0
likes
140
points
112
downloads

Publisher

unverified uploader

Weekly Downloads

Flux Analytics official Flutter SDK for tracking events, sessions, and user identity.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

connectivity_plus, device_info_plus, flutter, flutter_secure_storage, http, package_info_plus, plugin_platform_interface, shared_preferences, uuid

More

Packages that depend on flux_analytics_sdk

Packages that implement flux_analytics_sdk