superfine_sdk 0.0.3 copy "superfine_sdk: ^0.0.3" to clipboard
superfine_sdk: ^0.0.3 copied to clipboard

This the Flutter SDK of Superfine™. You can read more about Superfine™ at https://docs.superfine.org.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';

import 'package:flutter/services.dart';
import 'package:superfine_sdk/superfine_sdk.dart';
import 'package:superfine_sdk/superfine_sdk_settings.dart';
import 'package:superfine_sdk/superfine_sdk_types.dart';
// import 'package:superfine_sdk_appsflyer/superfine_sdk_appsflyer_module_settings.dart';

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await _initSuperfineSDK();
  runApp(const MyApp());
}

Future _initSuperfineSDK() async {
  try {
    // If you use Appsflyer as your mobile measurement partner
    // final appsflyerModuleSettings =
    //     SuperfineSdkAppsflyerModuleSettings(devKey: "{{YOUR_DEV_KEY}}");
    final superfineSettings = SuperfineSdkSettings(
        appId: "14ae1b11c3ceeb387c0cf88a",
        appSecret: "50d2682b206211eeae66927620615b6c",
        flushInterval: 5000,
        flushQueueSize: 5,
        logLevel: LogLevel.verbose,
        // modules: [appsflyerModuleSettings],
        autoStart: true);

    SuperfineSDK.registerSuperfineSDKLifecycleListener(
        SuperfineSDKLifecycleListenerImplementation());

    SuperfineSDK.registerDeepLinkingListener((url) {
      print("[Superfine]: On Set DeepLink: $url");
    });

    SuperfineSDK.registerPushTokenListener((token) {
      print("[Superfine]: $token");
    });

    SuperfineSDK.registerSendEventListener((jsonEvent) {
      print("[Superfine]: On Sent Event: $jsonEvent");
    });

    final initialized = await SuperfineSDK.initialize(superfineSettings);
    print("[Superfine]: Initialized: $initialized");
    if (initialized) {
      _onInit();
    }
  } on PlatformException {
    print("[Superfine]: Init SDK Failed");
  }
}

void _onInit() async {
  if (Platform.isAndroid) {
    SuperfineSDK.requestPermissions([
      "android.permission.ACCESS_COARSE_LOCATION",
      "android.permission.ACCESS_FINE_LOCATION"
    ]);
  }
  if (Platform.isIOS) {
    SuperfineSDK.registerAppForAdNetworkAttribution();
    SuperfineSDK.requestTrackingAuthorization();
    SuperfineSDK.requestNotificationAuthorization(
        IosNotificationAuthorizationOptions.badge);
  }
}

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    SuperfineSDK.destroy();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Superfine SDK Example App'),
        ),
        body: Center(
          child: Column(
            children: [
              TextButton(
                  onPressed: () async {
                    try {
                      await SuperfineSDK.start();
                    } on PlatformException {
                      print("[Superfine]: Start Failed");
                    }
                  },
                  child: const Text("START")),
              TextButton(
                  onPressed: () async {
                    try {
                      await SuperfineSDK.stop();
                    } on PlatformException {
                      print("[Superfine]: Stop Failed");
                    }
                  },
                  child: const Text("STOP")),
              TextButton(
                  onPressed: _sendEvents, child: const Text("SEND EVENTS")),
            ],
          ),
        ),
      ),
    );
  }

  void _sendEvents() async {
    try {
      // Test logging an event with various data types
      await SuperfineSDK.log("sample_event_string", data: "Event data string");
      await SuperfineSDK.log("sample_event_int", data: 123);
      await SuperfineSDK.log("sample_event_map", data: {"key": "value"});
      await SuperfineSDK.log("sample_event_json", data: '{"key":"value"}');

      // Test logging a custom event
      SuperfineSDKEvent customEvent = SuperfineSDKEvent(
          eventName: "custom_event_name",
          revenue: 0.01,
          currency: "USD",
          value: "something",
          eventFlag: EventFlag.none);
      await SuperfineSDK.logCustomEvent(customEvent);

      // Test logging a cache event
      SuperfineSDKEvent cacheEvent = SuperfineSDKEvent(
          eventName: "cache_event_name",
          revenue: 0.01,
          currency: "USD",
          value: "something",
          eventFlag: EventFlag.cache);
      await SuperfineSDK.logCache(cacheEvent);

      // Test boot start and end logging
      await SuperfineSDK.logBootStart();
      await SuperfineSDK.logBootEnd();

      // Test level start and end logging
      await SuperfineSDK.logLevelStart(1, "Level 1");
      await SuperfineSDK.logLevelEnd(1, "Level 1", true); // Assuming success

      // Test update app logging
      await SuperfineSDK.logUpdateApp("1.0.1");

      // Test app rating logging
      await SuperfineSDK.logRateApp();

      // Test location logging
      await SuperfineSDK.logLocation(
          37.7749, -122.4194); // San Francisco coordinates

      // Test user phone number addition and removal
      await SuperfineSDK.addUserPhoneNumber(1, "555-1234");
      await SuperfineSDK.removeUserPhoneNumber(1, "555-1234");

      // Test user email addition and removal
      await SuperfineSDK.addUserEmail("user@example.com");
      await SuperfineSDK.removeUserEmail("user@example.com");

      // Test user name setting
      await SuperfineSDK.setUserName(firstName: "John", lastName: "Doe");

      // Test user city, state, country, and zip code setting
      await SuperfineSDK.setUserCity("San Francisco");
      await SuperfineSDK.setUserState("California");
      await SuperfineSDK.setUserCountry("United States");
      await SuperfineSDK.setUserZipCode("94103");

      // Test user date of birth setting
      await SuperfineSDK.setUserDateOfBirth(day: 15, month: 6, year: 1990);

      // Test user gender setting
      await SuperfineSDK.setUserGender(UserGender.male);

      // Ads
      await SuperfineSDK.logAdLoad("1", AdPlacementType.banner,
          adPlacement: AdPlacement.bottom);
      await SuperfineSDK.logAdImpression("1", AdPlacementType.banner,
          adPlacement: AdPlacement.bottom);
      await SuperfineSDK.logAdClose("1", AdPlacementType.banner,
          adPlacement: AdPlacement.bottom);
      await SuperfineSDK.logAdClick("1", AdPlacementType.banner,
          adPlacement: AdPlacement.bottom);

      // IAP Initialization
      await SuperfineSDK.logIAPInitialization(true);

      // IAP Restore Purchase
      await SuperfineSDK.logIAPRestorePurchase();

      // IAP Result
      await SuperfineSDK.logIAPResult("com.example.pack", 9.99, 1, "USD", true);

      // IAP Receipts
      await SuperfineSDK.logIAPReceiptApple("sample_apple_receipt");
      await SuperfineSDK.logIAPReceiptGoogle(
          "sample_google_data", "sample_signature");
      await SuperfineSDK.logIAPReceiptAmazon(
          "sample_user_id", "sample_receipt_id");
      await SuperfineSDK.logIAPReceiptRoku("sample_transaction_id");
      await SuperfineSDK.logIAPReceiptWindows("sample_windows_receipt");
      await SuperfineSDK.logIAPReceiptFacebook("sample_facebook_receipt");
      await SuperfineSDK.logIAPReceiptUnity("sample_unity_receipt");
      await SuperfineSDK.logIAPReceiptAppStoreServer(
          "sample_transaction_id_appstore");

      // Google Play Receipts
      await SuperfineSDK.logIAPReceiptGooglePlayProduct("product_id", "token");
      await SuperfineSDK.logIAPReceiptGooglePlaySubscription(
          "subscription_id", "token");
      await SuperfineSDK.logIAPReceiptGooglePlaySubscriptionV2(
          "subscription_token");

      // Wallet Linking and Unlinking
      await SuperfineSDK.logWalletLink("sample_wallet_address",
          type: "ethereum");
      await SuperfineSDK.logWalletUnlink("sample_wallet_address",
          type: "ethereum");

      // Crypto Payment
      await SuperfineSDK.logCryptoPayment("crypto_pack", 0.05, 1,
          currency: "ETH", chain: "ethereum");

      // Ad Revenue
      await SuperfineSDK.logAdRevenue("source_name", 10.0, "USD",
          network: "ad_network",
          networkData: {"campaign": "summer_sale", "adGroup": "group1"});

      // Facebook Link/Unlink
      await SuperfineSDK.logFacebookLink("sample_facebook_user_id");
      await SuperfineSDK.logFacebookULink();

      // Instagram Link/Unlink
      await SuperfineSDK.logInstagramLink("sample_instagram_user_id");
      await SuperfineSDK.logInstagramUnlink();

      // Apple Link/Unlink
      await SuperfineSDK.logAppleLink("sample_apple_user_id");
      await SuperfineSDK.logAppleUnlink();

      // Apple Game Center Link/Unlink
      await SuperfineSDK.logAppleGameCenterLink("sample_game_player_id");
      await SuperfineSDK.logAppleGameCenterTeamLink("sample_team_player_id");
      await SuperfineSDK.logAppleGameCenterUnlink();

      // Google Link/Unlink
      await SuperfineSDK.logGoogleLink("sample_google_user_id");
      await SuperfineSDK.logGoogleUnlink();

      // Google Play Game Services Link/Unlink
      await SuperfineSDK.logGooglePlayGameServicesLink("sample_game_player_id");
      await SuperfineSDK.logGooglePlayGameServicesDeveloperLink(
          "sample_developer_player_key");
      await SuperfineSDK.logGooglePlayGameServicesUnlink();

      // LinkedIn Link/Unlink
      await SuperfineSDK.logLinkedInLink("sample_linkedin_person_id");
      await SuperfineSDK.logLinkedInUnlink();

      // Meetup Link/Unlink
      await SuperfineSDK.logMeetupLink("sample_meetup_user_id");
      await SuperfineSDK.logMeetupUnlink();

      // GitHub Link/Unlink
      await SuperfineSDK.logGitHubLink("sample_github_user_id");
      await SuperfineSDK.logGitHubUnlink();

      // Discord Link/Unlink
      await SuperfineSDK.logDiscordLink("sample_discord_user_id");
      await SuperfineSDK.logDiscordUnlink();

      // Twitter Link/Unlink
      await SuperfineSDK.logTwitterLink("sample_twitter_user_id");
      await SuperfineSDK.logTwitterUnlink();

      // Spotify Link/Unlink
      await SuperfineSDK.logSpotifyLink("sample_spotify_user_id");
      await SuperfineSDK.logSpotifyUnlink();

      // Microsoft Link/Unlink
      await SuperfineSDK.logMicrosoftLink("sample_microsoft_user_id");
      await SuperfineSDK.logMicrosoftUnlink();

      // LINE Link/Unlink
      await SuperfineSDK.logLINELink("sample_line_user_id");
      await SuperfineSDK.logLINEUnlink();

      // VK Link/Unlink
      await SuperfineSDK.logVKLink("sample_vk_user_id");
      await SuperfineSDK.logVKUnlink();

      // QQ Link/Unlink
      await SuperfineSDK.logQQLink("sample_qq_open_id");
      await SuperfineSDK.logQQUnionLink("sample_qq_union_id");
      await SuperfineSDK.logQQUnlink();

      // WeChat Link/Unlink
      await SuperfineSDK.logWeChatLink("sample_wechat_open_id");
      await SuperfineSDK.logWeChatUnionLink("sample_wechat_union_id");
      await SuperfineSDK.logWeChatUnlink();

      // TikTok Link/Unlink
      await SuperfineSDK.logTikTokLink("sample_tiktok_open_id");
      await SuperfineSDK.logTikTokUnionLink("sample_tiktok_union_id");
      await SuperfineSDK.logTikTokUnlink();

      // Weibo Link/Unlink
      await SuperfineSDK.logWeiboLink("sample_weibo_user_id");
      await SuperfineSDK.logWeiboUnlink();

      // Generic Account Link/Unlink
      await SuperfineSDK.logAccountLink("sample_account_id", "generic_type",
          scopeId: "scope_id", scopeType: "scope_type");
      await SuperfineSDK.logAccountUnlink("generic_type");

      // Set offline mode
      await SuperfineSDK.setOffline(true);
      print("[Superfine]: Offline mode set to true");

      await SuperfineSDK.setOffline(false);
      print("[Superfine]: Offline mode set to false");

      // Get SDK version
      String version = await SuperfineSDK.getVersion();
      print("[Superfine]: SDK Version: $version");

      // Set config ID
      await SuperfineSDK.setConfigId("sample_config_id");
      print("[Superfine]: Config ID set");

      // Set custom user ID
      await SuperfineSDK.setCustomUserId("sample_custom_user_id");
      print("[Superfine]: Custom User ID set");

      // Get application ID
      String appId = await SuperfineSDK.getAppId();
      print("[Superfine]: App ID: $appId");

      // Get user ID
      String userId = await SuperfineSDK.getUserId();
      print("[Superfine]: User ID: $userId");

      // Get session ID
      String sessionId = await SuperfineSDK.getSessionId();
      print("[Superfine]: Session ID: $sessionId");

      // Get host information
      String host = await SuperfineSDK.getHost();
      print("[Superfine]: Host: $host");

      // Get configuration URL
      String configUrl = await SuperfineSDK.getConfigUrl();
      print("[Superfine]: Config URL: $configUrl");

      // Get SDK configuration
      String sdkConfig = await SuperfineSDK.getSdkConfig();
      print("[Superfine]: SDK Config: $sdkConfig");

      // Get store type
      StoreType storeType = await SuperfineSDK.getStoreType();
      print("[Superfine]: Store Type: $storeType");

      // Get Facebook App ID
      String facebookAppId = await SuperfineSDK.getFacebookAppId();
      print("[Superfine]: Facebook App ID: $facebookAppId");

      // Get Instagram App ID
      String instagramAppId = await SuperfineSDK.getInstagramAppId();
      print("[Superfine]: Instagram App ID: $instagramAppId");

      // Get Apple-specific details
      if (Platform.isIOS) {
        String appleAppId = await SuperfineSDK.getAppleAppId();
        print("[Superfine]: Apple App ID: $appleAppId");

        String appleSignInClientId =
            await SuperfineSDK.getAppleSignInClientId();
        print("[Superfine]: Apple Sign-In Client ID: $appleSignInClientId");

        String appleDeveloperTeamId =
            await SuperfineSDK.getAppleDeveloperTeamId();
        print("[Superfine]: Apple Developer Team ID: $appleDeveloperTeamId");
      }

      // Get Android-specific details
      if (Platform.isAndroid) {
        String googlePlayGameServicesProjectId =
            await SuperfineSDK.getGooglePlayGameServicesProjectId();
        print(
            "Google Play Game Services Project ID: $googlePlayGameServicesProjectId");

        String googlePlayDeveloperAccountId =
            await SuperfineSDK.getGooglePlayDeveloperAccountId();
        print(
            "Google Play Developer Account ID: $googlePlayDeveloperAccountId");

        String imei = await SuperfineSDK.getIMEI();
        print("[Superfine]: IMEI: $imei");
      }

      // Get LinkedIn App ID
      String linkedInAppId = await SuperfineSDK.getLinkedInAppId();
      print("[Superfine]: LinkedIn App ID: $linkedInAppId");

      // Get QQ App ID
      String qqAppId = await SuperfineSDK.getQQAppId();
      print("[Superfine]: QQ App ID: $qqAppId");

      // Get WeChat App ID
      String weChatAppId = await SuperfineSDK.getWeChatAppId();
      print("[Superfine]: WeChat App ID: $weChatAppId");

      // Get TikTok App ID
      String tikTokAppId = await SuperfineSDK.getTikTokAppId();
      print("[Superfine]: TikTok App ID: $tikTokAppId");

      // Get Snap App ID
      String snapAppId = await SuperfineSDK.getSnapAppId();
      print("[Superfine]: Snap App ID: $snapAppId");

      // Test opening a URL
      await SuperfineSDK.openURL("https://example.com");
      print("[Superfine]: Opened URL: https://example.com");

      // Get deep link URL
      String deepLinkUrl = await SuperfineSDK.getDeepLinkUrl();
      print("[Superfine]: Deep Link URL: $deepLinkUrl");

      // Set push notification token
      await SuperfineSDK.setPushToken("sample_push_token");
      print("[Superfine]: Push Token set");

      // Get push notification token
      String pushToken = await SuperfineSDK.getPushToken();
      print("[Superfine]: Push Token: $pushToken");

      // GDPR compliance: forget me
      await SuperfineSDK.gdprForgetMe();
      print("[Superfine]: GDPR Forget Me executed");

      String config = await SuperfineSDK.fetchRemoteConfig();
      print("[Superfine]: Remote config: $config");

      print("[Superfine]: All events was sent successfully!");
    } on PlatformException catch (e) {
      print("[Superfine]: Send event failed with $e");
    }
  }
}

class SuperfineSDKLifecycleListenerImplementation
    extends SuperfineSdkLifeCycleListener {
  @override
  void onPause() {
    print("[Superfine]: onPause");
  }

  @override
  void onResume() {
    print("[Superfine]: onResume");
  }

  @override
  void onStart() {
    print("[Superfine]: onStart");
  }

  @override
  void onStop() {
    print("[Superfine]: onStop");
  }
}
2
likes
140
points
14
downloads

Publisher

unverified uploader

Weekly Downloads

This the Flutter SDK of Superfine™. You can read more about Superfine™ at https://docs.superfine.org.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on superfine_sdk

Packages that implement superfine_sdk