percept_flutter 0.0.19
percept_flutter: ^0.0.19 copied to clipboard
Official Percept Analytics Flutter SDK - Developed and Maintained by perceptinsight.com.
Percept-flutter #
Introducing the official Percept Flutter SDK
Getting Started #
1. Install #
- Add the following lines to your package's pubspec.yaml file to include the dependency:
dependencies:
percept_flutter: ^0.0.19
- To install the package, use the following command in your command line interface:
$ flutter pub get
- Import the package in your Dart code to make it available for use:
import 'package:percept_flutter/percept_flutter.dart'
2. Initialize Percept SDK #
import 'package:percept_flutter/percept_flutter.dart'
class YourClassState extends State<YourClass> {
Percept percept;
@override
void initState() {
super.initState();
percept=Percept(token)
}
}
NOTE: Token is the percept workspace token associated with your app.
3. Set user #
After successfully initializing the SDK, On login set current User using the following function.
percept.setUser(userId: "userId",userProperties: {UserProperty.name:"TestUser"}, additionalProperties: {"isVerifiedAccount": true})
4. Set currrent user properties #
use setCurrentUserProperties
method to set properties on the user profile created by setUser
// first call this method
await percept.setUser(userId: 'U1');
// sets user `deviceToken` and `isPaidUser` property to true
percept.setCurrentUserProperties(userProperties: {UserProperty.deviceToken:"token"}, additionalProperties: {"isPaidUser": true})
UserProperties can only have keys present in the UserProperty enum which are as follows.
User Property Name | Description |
---|---|
userId | UserId associated with the user |
phone | Phone number associated with the user |
Email ID associated with the user | |
deviceToken | FCM token for the device |
To get your firebase token you can use:
FirebaseMessaging.instance.getToken()
or
FirebaseMessaging.instance.onTokenRefresh.listen((token) => { });
5. Engage #
Integration with Firebase Messaging: To streamline push notification functionality and accurately monitor their impact on attribution.
- Capture when app session is initiated from terminated state by interacting with push notification.
// Get any messages which caused the application to open from a terminated state.
RemoteMessage? initialMessage = await FirebaseMessaging.instance.getInitialMessage();
if (initialMessage != null) {
_percept.trackPNTerminated(initialMessage.toMap());
}
- Capture when app session is resumed from background state by interacting with push notification.
// Get any messages which caused the application to open from a terminated state.
FirebaseMessaging.onMessageOpenedApp.listen(
(message) => _percept.trackPNBackground(message.toMap()),
);
This property will be tracked by pi_pn_attribution property in every subsequently tracked event.
pi_pn_attribution | Description |
---|---|
terminated | Interaction with pn initiated current app session from terminated state |
background | Interaction with pn resumed current app session from background state |
none | Current session is not attributed to any pn |
Along with pi_pn_attribution property following properties are tracked:
Property_name | Description |
---|---|
pi_pn_targetUrl | TargetUrl in the notification payload |
pi_pn_campaignId | CampaignId associated with the notificaiton |
pi_pn_campaignName | CampaignName associated with the notificaiton |
pi_pn_campaignSource | CampaignSource associated with the notificaiton |
Note: It is essential to have Firebase Messaging implemented to enable support for these properties.
6. Send Event #
You can capture event using the following function. Percept automatically generates a unique ID and stores it in local storage or a cookie.
// Track only event-name
percept.capture('Referral Banner Click');
// Track event-name with property
percept.capture('Screen View', {'screenName': 'Homepage'});
After initializing the library, Percept will automatically track some properties by default
7. Set Global Properties #
Set global properties which will be passed with all subsequent events
percept.setGlobalProperties({'global-property-key', 'value'});
8. Get all global properties #
Get all global properties
percept.getGlobalProperties();
9. Clear #
Call clear function on logout to delete all user related information
percept.clear()
Properties tracked by sdk #
Property_name | Description |
---|---|
pi_os_name | Operating system name like iOS or Android |
pi_os_version | Operating system version "7.1.3" |
pi_sdk_type | PI sdk type such as Flutter or Native |
pi_sdk_version | PI sdk version |
pi_pn_attribution | Tracks if current session is attributed to PN Interaction |
Along with other platform specific device info
Support #
If you have any questions, issues, or need assistance with Percept, here are the available support channels:
- Slack: #percept-platform
- GitHub Issues: Project Issues
Please feel free to reach out to us with any concerns or inquiries. We'll do our best to assist you and provide timely support.