contlo_plugin 0.0.1-beta
contlo_plugin: ^0.0.1-beta copied to clipboard
Contlo Flutter Plugin
contlo_plugin #
Version: 1.0.0
contlo_plugin is a Flutter plugin that allows you to integrate Contlo services into your Flutter application. It provides functionality for sending user details to Contlo, sending events to Contlo, and setting up Firebase Messaging for push notifications.
Installation #
To use this plugin in your Flutter project, add it to your pubspec.yaml file:
dependencies:
contlo_plugin: ^1.0.0
Setup Contlo Plugin #
To use the Contlo SDK, you need to add this import
import 'package:contlo_plugin/contlo_plugin.dart';
final contloPlugin = ContloPlugin();
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
final contloPlugin = ContloPlugin();
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");
}
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>) // true if consent was received
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: