@@ -5,6 +5,7 @@ Clix Flutter SDK is a powerful tool for managing push notifications and user eve
55## Installation
66
77Add this to your package's ` pubspec.yaml ` file:
8+
89``` yaml
910dependencies :
1011 clix_flutter : ^0.0.2
@@ -21,6 +22,7 @@ flutter pub get
2122- Flutter 3.0.0 or later
2223- Dart 2.17.0 or later
2324- iOS 14.0+ / Android API 21+
25+ - Firebase Cloud Messaging
2426
2527## Usage
2628
@@ -34,19 +36,18 @@ import 'package:firebase_core/firebase_core.dart';
3436
3537void main() async {
3638 WidgetsFlutterBinding.ensureInitialized();
37-
39+
3840 // Initialize Firebase first
3941 await Firebase.initializeApp();
40-
42+
4143 // Initialize Clix SDK
4244 await Clix.initialize(const ClixConfig(
4345 projectId: 'YOUR_PROJECT_ID',
4446 apiKey: 'YOUR_API_KEY',
4547 endpoint: 'https://api.clix.so', // Optional: default is https://api.clix.so
46- logLevel: ClixLogLevel.debug, // Optional: set log level
47- extraHeaders: {}, // Optional: extra headers for API requests
48+ logLevel: ClixLogLevel.debug, // Optional: set log level
4849 ));
49-
50+
5051 runApp(MyApp());
5152}
5253```
@@ -62,7 +63,6 @@ await Clix.setUserProperty('name', 'John Doe');
6263await Clix.setUserProperties({
6364 'age': 25,
6465 'premium': true,
65- 'subscription_plan': 'pro',
6666});
6767
6868// Remove user properties
@@ -73,14 +73,29 @@ await Clix.removeUserProperties(['age', 'premium']);
7373await Clix.removeUserId();
7474```
7575
76+ ### Event Tracking
77+
78+ ``` dart
79+ // Track an event with properties
80+ await Clix.trackEvent(
81+ 'signup_completed',
82+ properties: {
83+ 'method': 'email',
84+ 'discount_applied': true,
85+ 'trial_days': 14,
86+ 'completed_at': DateTime.now(),
87+ },
88+ );
89+ ```
90+
7691### Device Information
7792
7893``` dart
7994// Get device ID
8095final deviceId = await Clix.getDeviceId();
8196
8297// Get push token
83- final pushToken = await Clix.getPushToken ();
98+ final pushToken = await Clix.Notification.getToken ();
8499```
85100
86101### Logging
@@ -100,94 +115,76 @@ Clix.setLogLevel(ClixLogLevel.debug);
100115
101116The Clix Flutter SDK automatically handles push notification integration through Firebase Cloud Messaging.
102117
103- #### Setup Firebase
104-
105- 1 . ** Add Firebase to your Flutter project**
106- - Follow the [ Firebase setup guide] ( https://firebase.google.com/docs/flutter/setup )
107- - Add ` google-services.json ` (Android) and ` GoogleService-Info.plist ` (iOS)
108-
109- 2 . ** Enable Push Notifications**
110- - For iOS: Enable Push Notifications capability in Xcode
111- - For Android: No additional setup required
112-
113- 3 . ** Add Firebase dependencies**
114-
115- ``` yaml
116- dependencies :
117- firebase_core : ^3.6.0
118- firebase_messaging : ^15.1.3
119- ` ` `
120-
121- #### Handling Notifications
122-
123- The SDK automatically handles notification registration and token management. Notifications are processed internally for analytics and tracking.
124-
125- ` ` ` dart
126- // Notification handling is automatic - no additional code required
127- // The SDK will track notification delivery and engagement automatically
128- ```
129-
130- ## Firebase Setup
131-
132- ### iOS Setup
118+ #### 1. Firebase Setup
133119
120+ ** iOS:**
1341211 . Add your ` GoogleService-Info.plist ` to the iOS project in Xcode
1351222 . Enable Push Notifications capability in your iOS project
1361233 . Add Background Modes capability and check "Remote notifications"
137124
138- ### Android Setup
139-
125+ ** Android:**
1401261 . Add your ` google-services.json ` to ` android/app/ `
141- 2 . Add the Google Services plugin to your ` android/build.gradle ` :
127+ 2 . Firebase configuration is handled automatically by FlutterFire
142128
143- ``` gradle
144- buildscript {
145- dependencies {
146- classpath 'com.google.gms:google-services:4.3.15'
147- }
148- }
149- ```
129+ #### 2. Configure Notification Handlers
150130
151- 3 . Apply the plugin in ` android/app/build.gradle ` :
131+ Register handlers for push notification events :
152132
153- ``` gradle
154- apply plugin: 'com.google.gms.google-services'
155- ```
133+ ``` dart
134+ void main() async {
135+ WidgetsFlutterBinding.ensureInitialized();
156136
157- ## Configuration Options
137+ await Firebase.initializeApp();
138+ await Clix.initialize(const ClixConfig(
139+ projectId: 'YOUR_PROJECT_ID',
140+ apiKey: 'YOUR_API_KEY',
141+ ));
158142
159- ### ClixConfig
143+ // Register notification handlers
144+ Clix.Notification.onMessage((notificationData) async {
145+ // Return true to display the notification, false to suppress it
146+ return true;
147+ });
148+
149+ Clix.Notification.onBackgroundMessage((notificationData) {
150+ // Handle background notification
151+ print('Background notification received: $notificationData');
152+ });
153+
154+ Clix.Notification.onNotificationOpened((notificationData) {
155+ // Custom routing (called when user taps notification)
156+ final clixData = notificationData['clix'] as Map<String, dynamic>?;
157+ final landingURL = clixData?['landing_url'] as String?;
158+ if (landingURL != null) {
159+ // Handle custom routing
160+ }
161+ });
160162
161- - ` projectId ` (required): Your Clix project ID
162- - ` apiKey ` (required): Your Clix API key
163- - ` endpoint ` : API endpoint (default: 'https://api.clix.so ')
164- - ` logLevel ` : Logging level (default: ClixLogLevel.error)
165- - ` extraHeaders ` : Additional HTTP headers for API requests
163+ Clix.Notification.onFcmTokenError((error) {
164+ print('FCM token error: $error');
165+ });
166166
167- ### ClixLogLevel
167+ runApp(MyApp());
168+ }
169+ ```
168170
169- - ` verbose ` : All logs including detailed debugging
170- - ` debug ` : Debug information and above
171- - ` info ` : General information and above
172- - ` warning ` : Warning messages and above
173- - ` error ` : Error messages only
174- - ` none ` : No logging
171+ ** Important:** All ` Clix.Notification ` methods must be called ** after** ` Clix.initialize() ` .
175172
176- ## Sample App
173+ ##### About ` notificationData `
177174
178- A comprehensive sample app is provided in the ` samples/basic_app ` directory. The sample demonstrates:
175+ - The ` notificationData ` map is the full FCM payload as delivered to the device
176+ - Every Clix notification callback (` onMessage ` , ` onBackgroundMessage ` , ` onNotificationOpened ` ) passes this map through untouched
177+ - ` notificationData['clix'] ` holds the Clix metadata JSON, while all other keys represent app-specific data
179178
180- - Basic Clix SDK integration
181- - Push notification handling with Firebase
182- - User property management
183- - Device information display
179+ #### 3. Token Management
184180
185- To run the sample:
181+ ``` dart
182+ // Get current FCM token
183+ final token = await Clix.Notification.getToken();
186184
187- 1 . Navigate to ` samples/basic_app `
188- 2 . Follow the Firebase setup instructions in ` FIREBASE_SETUP.md `
189- 3 . Update ` lib/clix_info.dart ` with your project details
190- 4 . Run the app: ` flutter run `
185+ // Delete FCM token
186+ await Clix.Notification.deleteToken();
187+ ```
191188
192189## Error Handling
193190
@@ -205,62 +202,58 @@ try {
205202
206203The SDK is thread-safe and all operations can be called from any isolate. Async operations will automatically wait for SDK initialization to complete.
207204
208- ## Advanced Features
205+ ## Troubleshooting
209206
210- ### Manual Event Tracking
207+ ### Push Notifications Not Working
211208
212- While the SDK automatically tracks notification events, you can also track custom events :
209+ If push notifications aren't working, verify :
213210
214- ``` dart
215- // Custom event tracking methods would be implemented here
216- // Currently handled automatically by the SDK
217- ```
211+ 1 . ✅ Firebase is initialized before Clix SDK
212+ 2 . ✅ ` google-services.json ` (Android) and ` GoogleService-Info.plist ` (iOS) are added
213+ 3 . ✅ Push Notifications capability is enabled (iOS)
214+ 4 . ✅ Testing on a real device (push notifications don't work on iOS simulator)
215+ 5 . ✅ Debug logs show FCM token registration messages
218216
219- ### Custom Properties
217+ ### FCM Token Errors
220218
221- User properties support various data types :
219+ If you're experiencing FCM token registration failures, use the error handler :
222220
223221``` dart
224- await Clix.setUserProperties({
225- 'name': 'John Doe', // String
226- 'age': 25, // Number
227- 'premium': true, // Boolean
228- 'tags': ['flutter', 'mobile'], // Array
229- 'metadata': { // Object
230- 'source': 'mobile_app',
231- 'version': '1.0.0',
232- },
222+ Clix.Notification.onFcmTokenError((error) {
223+ print('FCM token error: $error');
224+ // Common causes:
225+ // - Missing or invalid google-services.json/GoogleService-Info.plist
226+ // - Network connectivity issues
227+ // - Firebase service errors
233228});
234229```
235230
236- ## Platform-Specific Considerations
237-
238- ### iOS
231+ ### Getting Help
239232
240- - Requires iOS 14.0 or later
241- - Push notifications require user permission
242- - Background processing is automatically handled
233+ If you continue to experience issues:
243234
244- ### Android
235+ 1 . Enable debug logging (` ClixLogLevel.debug ` )
236+ 2 . Check console for Clix log messages
237+ 3 . Verify your device appears in the Clix console Users page
238+ 4 . Check if ` push_token ` field is populated for your device
239+ 5 . Create an issue on [ GitHub] ( https://github.com/clix-so/clix-flutter-sdk/issues ) with logs and configuration details
245240
246- - Requires Android API level 21 or later
247- - Notification channels are automatically managed
248- - Background processing follows Android guidelines
241+ ## Sample App
249242
250- ## Performance
243+ A comprehensive sample app is provided in the ` samples/basic_app ` directory. The sample demonstrates:
251244
252- - Lightweight initialization
253- - Efficient background processing
254- - Minimal memory footprint
255- - Optimized network requests
245+ - Basic Clix SDK integration
246+ - Push notification handling with Firebase
247+ - User property management
248+ - Event tracking
249+ - Device information display
256250
257- ## Privacy
251+ To run the sample:
258252
259- The SDK respects user privacy:
260- - Only collects necessary device information
261- - User data is handled according to your privacy policy
262- - Push tokens are managed securely
263- - No personal data is collected without consent
253+ 1 . Navigate to ` samples/basic_app `
254+ 2 . Follow the Firebase setup instructions in ` FIREBASE_SETUP.md `
255+ 3 . Update ` lib/clix_configuration.dart ` with your project details
256+ 4 . Run the app: ` flutter run `
264257
265258## License
266259
@@ -273,10 +266,3 @@ See the full release history and changes in the [CHANGELOG.md](CHANGELOG.md) fil
273266## Contributing
274267
275268We welcome contributions! Please read the [ CONTRIBUTING.md] ( CONTRIBUTING.md ) guide before submitting issues or pull requests.
276-
277- ## Support
278-
279- For support and questions:
280- - Check the sample app for implementation examples
281- - Review the API documentation
282- - Contact support through your Clix dashboard
0 commit comments