Skip to main content

Flutter SDK Example App

A comprehensive Flutter application demonstrating all Trackier SDK features with complete implementation examples.

Overview

The Trackier Flutter SDK Simulator is a fully functional Flutter app that showcases:

  • Complete SDK Integration - All Trackier SDK features implemented
  • Real-world Examples - Production-ready Dart code patterns
  • Cross-platform Support - Android and iOS compatibility
  • Modern UI - User-friendly interfaces for testing features
  • Comprehensive Logging - Detailed debugging information
  • Firebase Integration - Uninstall tracking with Firebase Analytics

Key Features Demonstrated

SDK Initialization

Complete setup with environment variables, platform-specific configurations, and user data integration.

Event Tracking

  • Built-in Events - 15+ predefined events with revenue tracking
  • Custom Events - Flexible custom event implementation
  • Purchase Events - Product-specific tracking with detailed parameters
  • Revenue Tracking - Multi-currency support (50+ currencies)
  • Parameter System - Dynamic parameters (up to 10)

Deep Linking

  • Immediate Deep Links - Direct app navigation
  • Deferred Deep Links - Post-install attribution
  • URL Resolution - Advanced link parsing with query-string
  • Navigation Handling - Seamless user experience
  • Link Creation - Template-based generation
  • Multi-platform Support - Android, iOS, Desktop
  • Social Media Integration - Rich previews
  • Attribution Parameters - Campaign tracking

Advanced Features

  • Apple Search Ads Attribution - iOS advertising ID integration
  • Firebase Analytics - Uninstall tracking
  • Campaign Data - Complete parameter retrieval
  • User Data Management - Profile integration
  • Environment Management - Secure credential management with dotenv

Prerequisites

  • Flutter SDK (3.5.4 or higher)
  • Dart SDK
  • iOS 13.0+ / Android API 21+
  • Firebase project setup
  • Trackier account and credentials

Repository Structure

flutter-sdk-simulator/
├── lib/
│ ├── Screens/
│ │ ├── HomeScreen.dart # Main navigation hub
│ │ ├── BuildinEventScreen.dart # Built-in event tracking
│ │ ├── CustomEventsScreen.dart # Custom event tracking
│ │ ├── DeepLinkScreen.dart # Deep link testing
│ │ ├── DynamicLinkScreen.dart # Dynamic link creation/resolution
│ │ ├── CampaignDataScreen.dart # Campaign data retrieval
│ │ ├── ProductPageScreen.dart # Product display
│ │ ├── AddtoCartScreen.dart # Shopping cart functionality
│ │ ├── CakeScreen.dart # Product detail screen
│ │ └── SplashScreen.dart # App splash screen
│ ├── main.dart # SDK initialization and app entry
│ └── firebase_options.dart # Firebase configuration
├── android/ # Android platform files
├── ios/ # iOS platform files
├── .env # Environment variables (not in repo)
└── pubspec.yaml # Dependencies

Quick Start

1. Clone the Repository

git clone https://github.com/ApptroveLabs/flutter-sdk-simulator.git
cd flutter-sdk-simulator

2. Install Dependencies

flutter pub get

3. Configure Environment

Create .env file in project root with your Trackier credentials:

TR_DEV_KEY=your_trackier_dev_key_here
SECRET_ID=your_secret_id_here
SECRET_KEY=your_secret_key_here

4. Firebase Setup

  1. Add your GoogleService-Info.plist to ios/Runner/
  2. Add your google-services.json to android/app/
  3. Update lib/firebase_options.dart with your Firebase configuration

5. iOS Setup (macOS only)

cd ios
pod install
cd ..

6. Run the App

flutter run
Environment Variables

The .env file contains sensitive credentials and should never be committed to version control. Make sure to add it to your .gitignore file.

Firebase Configuration

Ensure your Firebase project is properly configured with the correct bundle ID for iOS and package name for Android to avoid initialization errors.

Implementation Examples

SDK Initialization

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

// 1. Firebase initialization
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

// 2. Load environment variables
await dotenv.load();

// 3. Handle initial deep link
final Uri? initialDeepLink = await _getInitialDeepLink();

// 4. Run app
runApp(MyApp(initialDeepLink: initialDeepLink));

// 5. Initialize SDKs after app is running
WidgetsBinding.instance.addPostFrameCallback((_) {
_initializeSDKs();
});
}

void _initializeSDKs() async {
// 1. Apple Search Ads token (iOS only)
if (Platform.isIOS) {
final token = await AppleSearchAdsHelper.getAttributionToken();
if (token != null) {
Trackierfluttersdk.updateAppleAdsToken(token);
}
}

// 2. Deep link parsing
Trackierfluttersdk.parseDeeplink(testDeepLink);

// 3. Trackier SDK initialization
Trackierfluttersdk.initializeSDK(config);

// 4. Firebase user property setting
_setTrackierUserProperty();

// 5. App open event tracking
_trackAppOpen();
}

Event Tracking

// Built-in event tracking
TrackierEvent event = TrackierEvent(TrackierEvent.PURCHASE);
event.revenue = 29.99;
event.currency = "USD";
event.orderId = "ORDER_123";
event.param1 = "premium_user";
event.param2 = "mobile_app";

Trackierfluttersdk.trackEvent(event);

// Custom event tracking
TrackierEvent customEvent = TrackierEvent("Q4YsqBKnzZ");
customEvent.revenue = 30.0;
customEvent.currency = "USD";
customEvent.param1 = "Britannia Cupcake";
customEvent.param2 = "Purchase Successfully";
customEvent.couponCode = "@3030303di";
customEvent.discount = 2.0;

// Custom JSON data
var jsonData = {"phone": "+91-8137872378", "name": "Satyam"};
customEvent.ev = jsonData;

Trackierfluttersdk.trackEvent(customEvent);
// Deferred deep link callback setup
trackerSDKConfig.deferredDeeplinkCallback = (uri) {
if (uri != null && uri.isNotEmpty) {
final Uri resolvedUri = Uri.parse(uri);
final String? dlv = resolvedUri.queryParameters['dlv'];

if (dlv != null) {
switch (dlv) {
case 'blueberrycupcake':
// Navigate to blueberry cupcake screen
break;
case 'chocochipcupcake':
// Navigate to chocolate chip cupcake screen
break;
// ... other cases
}
}
}
};

// Deep link parameter extraction
void handleDeepLink(String url) {
try {
final Uri uri = Uri.parse(url);
final String? productId = uri.queryParameters['product_id'];
final String? quantity = uri.queryParameters['quantity'];
final String? actionData = uri.queryParameters['actionData'];
final String? dlv = uri.queryParameters['dlv'];

// Process deep link data and navigate accordingly
if (productId != null && quantity != null) {
// Navigate to product screen with parameters
Navigator.pushNamed(context, '/product', arguments: {
'productId': productId,
'quantity': quantity,
'actionData': actionData,
'dlv': dlv,
});
}
} catch (error) {
print('Error parsing deep link: $error');
}
}
Future<void> createDynamicLink() async {
try {
final dynamicLinkConfig = {
'templateId': 'M5Osa2',
'link': 'https://trackier.u9ilnk.me/product/123',
'domainUriPrefix': 'https://trackier.u9ilnk.me',
'deepLinkValue': 'product_detail?product_id=123&quantity=2',

// Platform-specific parameters
'androidParameters': {
'redirectLink': 'https://play.google.com/store/apps/details?id=com.flutter_simulator'
},
'iosParameters': {
'redirectLink': 'https://apps.apple.com/app/id123456789'
},
'desktopParameters': {
'redirectLink': 'https://trackier.u9ilnk.me/desktop'
},

// Social media metadata
'socialMetaTagParameters': {
'title': 'Amazing Product',
'description': 'Check out this amazing product!',
'imageLink': 'https://example.com/product-image.jpg'
},

// SDK parameters
'sdkParameters': {
'param1': 'value1',
'param2': 'value2',
'param3': 'value3'
},

// Attribution parameters
'attributionParameters': {
'channel': 'social',
'campaign': 'summer_sale',
'mediaSource': 'facebook',
'p1': 'custom_param1',
'p2': 'custom_param2',
'p3': 'custom_param3'
}
};

final result = await Trackierfluttersdk.createDynamicLink(dynamicLinkConfig);
print('Dynamic link created: $result');
} catch (error) {
print('Error creating dynamic link: $error');
}
}
Future<void> resolveDeeplink(String url) async {
try {
final result = await Trackierfluttersdk.resolveDeeplinkUrl(url);
print('Resolved deep link: $result');

// Process resolved URL parameters
final Uri resolvedUri = Uri.parse(result);
final Map<String, String> params = resolvedUri.queryParameters;

// Display resolved parameters
setState(() {
resolvedData = params;
});
} catch (error) {
print('Error resolving deep link: $error');
}
}

Apple Search Ads Attribution

// Apple Search Ads Helper
class AppleSearchAdsHelper {
static Future<String?> getAttributionToken() async {
if (defaultTargetPlatform != TargetPlatform.iOS) {
return null;
}
try {
final String? token = await _channel.invokeMethod('getAttributionToken');
return token;
} on PlatformException catch (e) {
print('Error getting Apple Search Ads attribution token: ${e.message}');
return null;
}
}
}

Firebase Analytics Integration

Future<void> _setTrackierUserProperty() async {
var trackierId = await Trackierfluttersdk.getTrackierId();
await FirebaseAnalytics.instance.setUserProperty(
name: "ct_objectId",
value: trackierId
);
}

User Management

// Set user data
Trackierfluttersdk.setUserId("USER123");
Trackierfluttersdk.setUserEmail("user@example.com");
Trackierfluttersdk.setUserName("John Doe");
Trackierfluttersdk.setUserPhone("+1234567890");
Trackierfluttersdk.setDOB("1990-01-01");
Trackierfluttersdk.setGender(Gender.Male);
SDK Initialization Order

It's crucial to initialize SDKs in the correct order: Firebase first, then environment variables, then Trackier SDK, and finally user properties and event tracking.

Deep Link Handling

The deferred deep link callback should be set up before SDK initialization to ensure proper deep link processing on app launch.

🔧 Technical Implementation

SDK Initialization

The app initializes multiple SDKs in the correct order:

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

// 1. Firebase initialization
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

// 2. Load environment variables
await dotenv.load();

// 3. Handle initial deep link
final Uri? initialDeepLink = await _getInitialDeepLink();

// 4. Run app
runApp(MyApp(initialDeepLink: initialDeepLink));

// 5. Initialize SDKs after app is running
WidgetsBinding.instance.addPostFrameCallback((_) {
_initializeSDKs();
});
}

void _initializeSDKs() async {
// 1. Apple Search Ads token (iOS only)
if (Platform.isIOS) {
final token = await AppleSearchAdsHelper.getAttributionToken();
if (token != null) {
Trackierfluttersdk.updateAppleAdsToken(token);
}
}

// 2. Deep link parsing
Trackierfluttersdk.parseDeeplink(testDeepLink);

// 3. Trackier SDK initialization
Trackierfluttersdk.initializeSDK(config);

// 4. Firebase user property setting
_setTrackierUserProperty();

// 5. App open event tracking
_trackAppOpen();
}

The app implements comprehensive deep link handling:

trackerSDKConfig.deferredDeeplinkCallback = (uri) {
if (uri != null && uri.isNotEmpty) {
final Uri resolvedUri = Uri.parse(uri);
final String? dlv = resolvedUri.queryParameters['dlv'];

if (dlv != null) {
switch (dlv) {
case 'blueberrycupcake':
// Navigate to blueberry cupcake screen
break;
case 'chocochipcupcake':
// Navigate to chocolate chip cupcake screen
break;
// ... other cases
}
}
}
};

Event Tracking

Events are tracked with comprehensive data:

TrackierEvent event = TrackierEvent(TrackierEvent.PURCHASE);
event.revenue = 29.99;
event.currency = "USD";
event.orderId = "ORDER_123";
event.param1 = "premium_user";
event.param2 = "mobile_app";

Trackierfluttersdk.trackEvent(event);

Dependencies

Core Dependencies

# pubspec.yaml
dependencies:
flutter:
sdk: flutter
trackier_flutter_sdk: ^1.0.0
firebase_core: ^2.24.2
firebase_analytics: ^10.7.4
flutter_dotenv: ^5.1.0
url_launcher: ^6.2.2
clipboard: ^0.1.3

Environment Variables

# .env file
TR_DEV_KEY=your-sdk-key-here
SECRET_ID=your-secret-id-here
SECRET_KEY=your-secret-key-here

Event Summary

Event TypeEvent ID/NameLocationTrigger
Custom PurchaseQ4YsqBKnzZAddtoCartScreen.dartCake purchase
Built-in EventsTrackierEvent.*BuildinEventScreen.dartUser selection
Custom EventsUser-definedCustomEventsScreen.dartCustom event ID
Deep LinkAuto-detectedmain.dartDeep link received
Dynamic LinkTemplate-basedDynamicLinkScreen.dartLink creation

Logging and Debugging

Key Log Messages

  • SDK Initialization: "Trackier SDK initialized successfully"
  • Deep Link Received: Complete deep link data dump
  • Event Tracking: All tracked events with parameters
  • Dynamic Link Created: Successfully created dynamic links
  • Navigation: Screen navigation events
  • Parameter Parsing: Detailed parameter extraction logs

Console Output Examples

LOG  TR_DEV_KEY: xxxxxxxxxxxxxxxxxxxxx
LOG SECRET_ID: xxxxxxxxxxxxxxxxxxxxx
LOG SECRET_KEY: xxxxxxxxxxxxxxxxxxxxx
LOG Trackier SDK initialized successfully
LOG Deferred Deeplink Callback received
LOG URL: trackier58.u9ilnk.me/d?dlv=CakeActivity&product_id=chocochip&quantity=2
LOG Cake deeplink detected, processing...
LOG Processing deep link URL: trackier58.u9ilnk.me/d?dlv=CakeActivity&product_id=chocochip&quantity=2
LOG Parsed parameters: {"dlv": "CakeActivity", "product_id": "chocochip", "quantity": "2"}
LOG Cake parameters detected:
LOG - Product ID: chocochip
LOG - Quantity: 2
LOG - Action Data: noAction
LOG - DLV: CakeActivity
LOG Setting navigation to CakeScreen...
LOG Deep link processed successfully
LOG Navigating to CakeScreen...

Security Features

Encryption Support

The SDK supports encrypted event tracking:

trackerSDKConfig.setAppId("YOUR_APP_ID");
trackerSDKConfig.setEncryptionKey("YOUR_ENCRYPTION_KEY");
trackerSDKConfig.setEncryptionType(TrackierEncryptionType.AES_GCM);

App Secrets

Secure API communication:

trackerSDKConfig.setAppSecret(secretId, secretKey);
Security Best Practices

Always store sensitive credentials in environment variables and never commit them to version control. Use encryption for production environments.

Troubleshooting

Common Issues

SDK Not Initializing

  • Verify environment variables in .env file
  • Check console logs for credential errors
  • Ensure proper import statements

Deep Links Not Working

  • Verify URL format and parameters
  • Check console logs for parsing errors
  • Test with provided sample URLs

Events Not Tracking

  • Verify event IDs from Trackier panel
  • Check network connectivity
  • Monitor console logs for errors

iOS Build Issues

  • Clean and rebuild: cd ios && rm -rf build && pod install
  • Check Xcode project settings
  • Verify iOS deployment target

Firebase Configuration Error

  • Ensure GoogleService-Info.plist is properly added to iOS project
  • Verify bundle ID matches Firebase configuration
  • Check API key format (39 characters for iOS)

Apple Search Ads Attribution Error

  • Verify iOS 14.3+ requirement
  • Check AdServices framework availability
  • Ensure proper permissions

Debug Mode

Enable debug logging:

// Add to your main.dart
import 'dart:developer' as developer;
developer.log('Debug message', name: 'TrackierSDK');
Debugging Tips

Use the Flutter Inspector and console logs to debug deep link processing and event tracking. The app provides comprehensive logging for all SDK operations.

Support

For technical support and questions:


This example app provides comprehensive tracking, deep linking, and dynamic link functionality for Flutter applications using the Trackier SDK, demonstrating best practices for mobile app analytics and attribution with a modern, user-friendly interface.