Contlo Flutter SDK
👋 Introduction
Contlo supports integrating your Flutter application with Flutter SDK to enable push notifications, events, analytics, automation, etc.
✅ Installation
To use this plugin in your Flutter project, add it to your pubspec.yaml
file:
dependencies:
contlo_plugin: ^1.0.0
Run flutter pub get
to install the SDK
Now, in your Dart code, you can use:
import 'package:contlo_plugin/contlo_plugin.dart';
You can now use ContloPlugin to send user data or send custom events to Contlo.
Note: All the methods inside ContloPlugin are asyncronous, meaning you will have to call them using async and await.
👍 Initialise the Contlo Plugin
To initialise the Contlo Plugin, you have to call this method on the start of your application. This usually means you have to add the code after "runApp()" code
ContloPlugin.init("<Your API KEY>")
👤 Sending User Details to Contlo
You can use the Contlo Plugin to send user details to Contlo.
Future<void> sendUserDetails() async {
try {
print("Send user: $email, $phone, $name, $city");
String data = await ContloPlugin.sendUserDetail({
"email": email,
"phone_number":phone,
"first_name": name.isEmpty? "aman": name,
"city": city.isEmpty? "ranchi":city,
"custom_properties": {
'key': 'value'
}
});
print("User details response: $data");
} on PlatformException catch (e){
print("Exception thrown $e");
}
}
🎤 Sending Events to Contlo
Contlo Plugin also allows you to send custom events to Contlo. Here's an example of how to send an event:
void sendEvent() async {
String data = await ContloPlugin.sendEvent({
"event": eventName,
"properties": {
eventDetails['key']: eventDetails['value']
}
});
print("Event response: $data");
}
A simpler way to send events can be:
ContloPlugin.sendEvent("eventName");
📳 Sending Push Consent to Contlo
Starting from Android 13 and above, you need to explicitly ask users for their consent to receive push notifications.
Add this permission to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
If the device uses Android 12 or less, permission to send notifications is already granted. If the device uses Android 13 or above, you need to explicitly ask the user for permission. Use the below code according to the user consent:
ContloPlugin.subscribeToMobilePush(<consent>)
Based upon the consent received, the function would subscribe or unsubscribe your Audience from Mobile Push on your Contlo Dashboard.
📲 Advertising ID Tracking
Advertising Id Tracking - If you want to track anonymous users across devices, you can enable tracking of Advertising Id. This will set the Advertising ID as a Profile Property in the contact details under the Audience Section in your Contlo dashboard. Follow the below steps:
Add the following permission in your AndroidManifest.xml file: