Flutter SDK - Methods Reference

Flutter SDK - Methods Reference

This comprehensive reference documents all available methods in the Singular SDK for Flutter applications. The SDK provides functionality for initialization, event tracking, revenue reporting, attribution, data privacy compliance, and configuration. Each method is presented with a description, signature, and practical usage examples to help developers integrate Singular's SDK capabilities into their Flutter applications.


adRevenue

Singular.adRevenue Method

Tracks ad revenue events with detailed ad data information. This method allows you to report revenue generated from ads displayed in your application, including ad network data, placement information, and revenue amounts.

Signature

static void adRevenue(SingularAdData adData)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';
import 'package:singular_flutter_sdk/singular_ad_data.dart';

// Create ad data object
SingularAdData adData = SingularAdData(
  'AdMob',
  'USD',
  0.99
)
  ..withAdPlatfom('Android')
  ..withAdType('Rewarded')
  ..withAdGroupId('group_123')
  ..withAdGroupName('Rewarded Video Group')
  ..withAdGroupType('rewarded_video')
  ..withImpressionId('impression_abc123')
  ..withAdPlacementName('main_menu')
  ..withAdUnitId('ca-app-pub-123456789')
  ..withAdUnitName('Main Menu Rewarded Video');

// Track the ad revenue
Singular.adRevenue(adData);

clearGlobalProperties

Singular.clearGlobalProperties Method

Removes all global properties that have been set. Global properties are key-value pairs that are automatically added to all events tracked by the SDK.

Signature

static void clearGlobalProperties()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Clear all global properties
Singular.clearGlobalProperties();

createReferrerShortLink

Singular.createReferrerShortLink Method

Creates a Singular short link for referral tracking. This method generates a short link that can be shared by users to track referral attribution.

Signature

static void createReferrerShortLink(
  String baseLink,
  String referrerName,
  String referrerId,
  Map<String, String> passthroughParams,
  ShortLinkCallback completionHandler
)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Create a referrer short link
Singular.createReferrerShortLink(
  'https://yourapp.sng.link/A1b2c',
  'John Doe',
  'user_12345',
  {
    'promo_code': 'SUMMER2025',
    'campaign': 'referral_program'
  },
  (String? shortLink, String? error) {
    if (error != null) {
      print('Error creating short link: $error');
    } else {
      print('Short link created: $shortLink');
    }
  }
);

customRevenue

Singular.customRevenue Method

Tracks custom revenue events with a specified event name, currency, and amount. This method is used for tracking revenue that is not related to in-app purchases or ad revenue.

Signature

static void customRevenue(
  String eventName,
  String currency,
  double amount
)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Track custom revenue event
Singular.customRevenue('Subscription_Purchase', 'USD', 9.99);

customRevenueWithAttributes

Singular.customRevenueWithAttributes Method

Tracks custom revenue events with additional attributes. This method extends the basic custom revenue tracking by allowing you to include custom key-value pairs for more detailed tracking.

Signature

static void customRevenueWithAttributes(
  String eventName,
  String currency,
  double amount,
  Map attributes
)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Track custom revenue with additional attributes
Singular.customRevenueWithAttributes(
  'Premium_Upgrade',
  'USD',
  29.99,
  {
    'subscription_tier': 'premium',
    'billing_cycle': 'annual',
    'promotion_code': 'ANNUAL20'
  }
);

customRevenueWithAllAttributes

Singular.customRevenueWithAllAttributes Method

Tracks custom revenue events with all possible attributes including product SKU, product name, product category, product quantity, and custom attributes.

Signature

static void customRevenueWithAllAttributes(
  String eventName,
  String currency,
  double amount,
  String productSKU,
  String productName,
  String productCategory,
  int productQuantity,
  Map attributes
)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Track custom revenue with all attributes
Singular.customRevenueWithAllAttributes(
  'In_Game_Purchase',
  'USD',
  4.99,
  'gold_pack_500',
  'Gold Pack 500',
  'virtual_currency',
  1,
  {
    'payment_method': 'credit_card',
    'discount_applied': 'false'
  }
);

event

Singular.event Method

Tracks a simple event with only an event name. This is the most basic form of event tracking in the Singular SDK.

Signature

static void event(String eventName)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Track a simple event
Singular.event('Level_Completed');

eventWithArgs

Singular.eventWithArgs Method

Tracks an event with additional attributes in the form of key-value pairs. This allows for more detailed event tracking with custom parameters.

Signature

static void eventWithArgs(String eventName, Map args)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Track event with custom attributes
Singular.eventWithArgs('Level_Completed', {
  'level_number': 10,
  'score': 8500,
  'time_seconds': 245,
  'difficulty': 'hard'
});

getGlobalProperties

Singular.getGlobalProperties Method

Returns a map of all currently set global properties. Global properties are automatically included with every event tracked by the SDK.

Signature

static Future<Map<String, String>> getGlobalProperties()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Get all global properties
Map<String, String> properties = await Singular.getGlobalProperties();
print('Current global properties: $properties');

getLimitDataSharing

Singular.getLimitDataSharing Method

Returns the current state of data sharing limitation. This method checks whether data sharing with third parties is currently limited.

Signature

static Future<bool> getLimitDataSharing()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Check if data sharing is limited
bool isLimited = await Singular.getLimitDataSharing();
print('Data sharing limited: $isLimited');

handlePushNotification

Singular.handlePushNotification Method

Handles push notification attribution. This method should be called when your app receives a push notification to enable attribution tracking for notification-driven app opens.

Signature

static void handlePushNotification(Map notification)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Handle incoming push notification
Map<String, dynamic> notificationData = {
  'title': 'New Offer Available',
  'body': 'Check out our latest deals',
  'campaign_id': 'summer_2025'
};

Singular.handlePushNotification(notificationData);

inAppPurchase

Singular.inAppPurchase Method

Tracks in-app purchase events. This method reports purchases made within your application to Singular for revenue tracking and attribution. Use the Flutter in_app_purchase package to retrieve the purchase object with complete transaction details.

The SingularIAP purchase object must be constructed using the platform specific subclass constructors:

  • SingularIOSIAP(double revenue, String? currencyCode, String? productId, String? transactionId, String? receipt)
  • SingularAndroidIAP(double revenue, String? currencyCode, String? signature, String? receipt)

So build the appropriate SingularIAP subclass with revenue and currencyCode first, then platform-specific fields.

Signature

static void inAppPurchase(String eventName, SingularIAP purchase)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';
import 'package:singular_flutter_sdk/singular_iap.dart';

// Build an iOS SingularIAP purchase object and send it to the SDK
const String eventName = 'iap_purchase'; // <= 32 ASCII chars
final SingularIAP purchase = SingularIOSIAP(
  4.99,               // revenue (double)
  'USD',              // currency code (String)
  'com.example.sku',  // productId (String)
  'transactionId123', // transactionID from AppStorePurchaseDetails (String)
  'base64_receipt'    // JWS receipt from StoreKit (String)
);

// OR, Build an Android SingularIAP purchase object and send it to the SDK
const String eventName = 'iap_purchase'; // <= 32 ASCII chars
final SingularIAP purchase = SingularAndroidIAP(
  4.99,               // revenue (double)
  'USD',              // currency code (String)
  'com.example.sku',  // Signature from GooglePlayPurchase (String)
  'originalJson_receipt'    // receipt Object from GooglePlayPurchase originalJson (String)
);

// Basic tracking
Singular.inAppPurchase(eventName, purchase);

inAppPurchaseWithAttributes

Singular.inAppPurchaseWithAttributes Method

Tracks in-app purchase events with additional custom attributes. This method extends the basic IAP tracking by allowing custom key-value pairs for more detailed purchase tracking.

Signature

static void inAppPurchaseWithAttributes(String eventName, SingularIAP purchase, Map attributes)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';
import 'package:singular_flutter_sdk/singular_iap.dart';
// Generate SingularIAP purchase as above
// Tracking with attributes
  Singular.inAppPurchaseWithAttributes(eventName, purchase, {
    'user_level': 42,
    'is_first_purchase': true,
    'gems_balance': 1500
  });

isAllTrackingStopped

Singular.isAllTrackingStopped Method

Returns whether all tracking has been stopped. This method checks if the SDK is currently in a state where no data is being collected or sent.

Signature

static Future<bool> isAllTrackingStopped()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Check if tracking is stopped
bool isStopped = await Singular.isAllTrackingStopped();
print('All tracking stopped: $isStopped');

limitDataSharing

Singular.limitDataSharing Method

Limits or enables data sharing with third parties. This method controls whether the SDK shares data with ad networks and other third-party services for attribution purposes.

Signature

static void limitDataSharing(bool limitDataSharingValue)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Limit data sharing
Singular.limitDataSharing(true);

// Or enable data sharing
Singular.limitDataSharing(false);

registerDeviceTokenForUninstall

Singular.registerDeviceTokenForUninstall Method

Registers the device's push notification token for uninstall tracking. This enables Singular to detect when users uninstall your application.

Signature

static void registerDeviceTokenForUninstall(String token)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Register device token for uninstall tracking
String deviceToken = 'your_device_push_token_here';
Singular.registerDeviceTokenForUninstall(deviceToken);

resumeAllTracking

Singular.resumeAllTracking Method

Resumes all tracking that was previously stopped. This method re-enables data collection and transmission after tracking has been stopped.

Signature

static void resumeAllTracking()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Resume tracking after it was stopped
Singular.resumeAllTracking();

setCustomUserId

Singular.setCustomUserId Method

Sets a custom user identifier for tracking. This method associates events with a specific user ID from your application's user system.

Signature

static void setCustomUserId(String customUserId)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Set custom user ID after user logs in
Singular.setCustomUserId('user_12345');

setDeviceCustomUserId

Singular.setDeviceCustomUserId Method

Sets a device-level custom user identifier. This method is used to associate a custom identifier with the device itself, persisting across app sessions and user logins.

Signature

static void setDeviceCustomUserId(String customUserId)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Set device-level custom user ID
Singular.setDeviceCustomUserId('device_user_67890');

setFCMDeviceToken

Singular.setFCMDeviceToken Method

Sets the Firebase Cloud Messaging (FCM) device token. This method is specifically for Android devices using FCM for push notifications.

Signature

static void setFCMDeviceToken(String token)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';
import 'dart:io';

// Set FCM token (Android only)
if (Platform.isAndroid) {
  String fcmToken = 'your_fcm_token_here';
  Singular.setFCMDeviceToken(fcmToken);
}

setGlobalProperty

Singular.setGlobalProperty Method

Sets a global property that will be included with all subsequent events. Global properties are key-value pairs automatically added to every event tracked by the SDK.

Signature

static void setGlobalProperty(
  String key,
  String value,
  bool overrideExisting
)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Set a global property
Singular.setGlobalProperty('user_type', 'premium', true);
Singular.setGlobalProperty('app_theme', 'dark', false);

setLimitAdvertisingIdentifiers

Singular.setLimitAdvertisingIdentifiers Method

Limits the collection of advertising identifiers (IDFA on iOS, GAID on Android). This method controls whether the SDK collects and uses advertising IDs for attribution.

Signature

static void setLimitAdvertisingIdentifiers(bool limit)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Limit advertising identifier collection
Singular.setLimitAdvertisingIdentifiers(true);

skanGetConversionValue

Singular.skanGetConversionValue Method

Gets the current SKAdNetwork conversion value (iOS only). This method retrieves the conversion value that has been set for SKAdNetwork attribution.

Signature

static Future<int> skanGetConversionValue()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';
import 'dart:io';

// Get current SKAdNetwork conversion value (iOS only)
if (Platform.isIOS) {
  int conversionValue = await Singular.skanGetConversionValue();
  print('Current conversion value: $conversionValue');
}

skanRegisterAppForAdNetworkAttribution

Singular.skanRegisterAppForAdNetworkAttribution Method

Registers the app for SKAdNetwork attribution (iOS only). This method should be called to enable SKAdNetwork tracking on iOS devices.

Signature

static void skanRegisterAppForAdNetworkAttribution()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';
import 'dart:io';

// Register for SKAdNetwork attribution (iOS only)
if (Platform.isIOS) {
  Singular.skanRegisterAppForAdNetworkAttribution();
}

skanUpdateConversionValue

Singular.skanUpdateConversionValue Method

Updates the SKAdNetwork conversion value (iOS only). This method sets a new conversion value for SKAdNetwork attribution, representing user quality or engagement level.

Signature

static void skanUpdateConversionValue(int conversionValue)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';
import 'dart:io';

// Update SKAdNetwork conversion value (iOS only)
if (Platform.isIOS) {
  Singular.skanUpdateConversionValue(5);
}

skanUpdateConversionValues

Singular.skanUpdateConversionValues Method

Updates SKAdNetwork conversion values with additional parameters including coarse conversion value and lock status (iOS 16.1+ only). This method provides more granular control over SKAdNetwork postbacks.

Signature

static void skanUpdateConversionValues(
  int conversionValue,
  int coarse,
  bool lock
)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';
import 'dart:io';

// Update conversion values with coarse value and lock (iOS 16.1+)
if (Platform.isIOS) {
  Singular.skanUpdateConversionValues(
    10,    // fine conversion value
    1,     // coarse conversion value
    false  // lock status
  );
}

start

Singular.start Method

Initializes and starts the Singular SDK with the provided configuration. This method must be called before any other SDK methods and should be called as early as possible in your application lifecycle.

Signature

static void start(SingularConfig config)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';
import 'package:singular_flutter_sdk/singular_config.dart';

// Create and configure the SDK
SingularConfig config = SingularConfig(
  'YOUR_API_KEY',
  'YOUR_SECRET_KEY'
)
  ..withLoggingEnabled()
  ..withSessionTimeoutInSec(60);

// Start the SDK
Singular.start(config);

stopAllTracking

Singular.stopAllTracking Method

Stops all tracking by the SDK. This method halts all data collection and transmission, typically used for privacy compliance when a user opts out of tracking.

Signature

static void stopAllTracking()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Stop all tracking (for privacy opt-out)
Singular.stopAllTracking();

trackingOptIn

Singular.trackingOptIn Method

Indicates that the user has opted in to tracking. This method should be called when a user explicitly consents to data tracking and attribution.

Signature

static void trackingOptIn()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// User opted in to tracking
Singular.trackingOptIn();

trackingUnder13

Singular.trackingUnder13 Method

Indicates that the user is under 13 years old. This method enables COPPA compliance mode, limiting data collection for users under the age of 13.

Signature

static void trackingUnder13()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Enable COPPA compliance mode
Singular.trackingUnder13();

unsetCustomUserId

Singular.unsetCustomUserId Method

Removes the custom user identifier. This method clears any previously set custom user ID, typically called when a user logs out.

Signature

static void unsetCustomUserId()

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Remove custom user ID on logout
Singular.unsetCustomUserId();

unsetGlobalProperty

Singular.unsetGlobalProperty Method

Removes a specific global property by key. This method clears a single global property that was previously set.

Signature

static void unsetGlobalProperty(String key)

Usage Example

Dart
import 'package:singular_flutter_sdk/singular.dart';

// Remove a specific global property
Singular.unsetGlobalProperty('user_type');