Promize SDK

Promize SDK is a data collection SDK provides an easy way to collect your users data and interests

Overview

The App SDK provides methods to send transactional messages and trigger events.The other methods help you save information about people, most visited pages and events.

Getting Started

First, register account on the promize console

Then add promize_sdk as a dependency in your pubspec.yaml file.

Prerequisites

This Package Works on Dart >=2.12.4 make sure to upgrade Your Sdk

sdk: ">=2.12.4 <4.0.0"

also this SDK uses FCM you need to setup Firebase in your project please refer to documentation for more info

How To Use

initialize

you need first thing to initialize the sdk by calling initialize method

  final _promizeSdkPlugin = PromizeSdk.instance;

  @override
  void initState() {
    super.initState();
         await _promizeSdkPlugin.initialize(
        apiKey:
            'your api key',
        siteId: 'your site id',
        baseUrl: 'your base url',
        pushEnabled: true, //detemins if you want to recive notification or not
        appVersion: 'your app version' //Optional,
      );
  }

Authentication

you need to add user on sign in or on register

final user = User(name,email,userId,Map<String,dynamic> additionalUserData);

_promizeSdkPlugin.createUser(user:user);


Update user

you can update user info as following

_promizeSdkPlugin.updateUser(user:user);

update device token

for the use of firebase cloud messaging you need to add the updateDeviceToken method in your onTokenChangedCallback

 messaging.onTokenRefresh.listen((newToken) { 
    _promizeSdkPlugin.updateDeviceToken(
      deviceToken:
          "your-device-token",
          
    );
        });

Save Device Token

you can save the device token without calling updateDeviceToken method by calling saveDeviceToken method

_promizeSdkPlugin.saveDeviceToken(
      deviceToken:
          "your-device-token",
          
    );

Logout

you need to call logout method when user logout from your app to clear user data

_promizeSdkPlugin.logout();

Add event

after register user you can add event any where in you app just use the add event and pass all the params you need to watch

    _promizeSdkPlugin.addEvent(
        eventName: "test Event",
        eventType: EventType.event,
        eventData: {"first_collectd": "data"});

Notification

if you want to track the notification sent by our system you need to call trackNotificationActivity method on your notification click callback

onBackgroundMessageHandler

to track when the notification received in background

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  final _promizeSdkPlugin = PromizeSdk.instance;
  // If you're going to use other Firebase services in the background, such as Firestore,
  // make sure you call `initializeApp` before using other Firebase services.
  await Firebase.initializeApp();
  await _promizeSdkPlugin.initialize(
    apiKey: '{your-api-key}',
    siteId: '{your-site-id}',
    baseUrl: '{your-base-url}',
    pushEnabled: true,
    appVersion: '0.0.1',
  );
  // track notification activity as received in background
  _promizeSdkPlugin.trackNotificationActivity(
    activityType: NotificationAction.received,
    data: message.data,
  );
}

OnMessage

to track when the notification received in foreground && when the notification clicked

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
      // track notification activity as received in foreground
      _promizeSdkPlugin.trackNotificationActivity(
        activityType: NotificationAction.received,
        data: message.data,
      );

      if (message.notification != null) {
        print(
            'Message also contained a notification: ${message.notification?.title ?? ''} - ${message.notification?.body ?? ''}');
      }
      Alert.instance.showNotification(
        context,
        message.notification?.title,
        message.notification?.body,
        () {
          // track notification activity as clicked
          _promizeSdkPlugin.trackNotificationActivity(
            activityType: NotificationAction.clicked,
            data: message.data,
          );
        },
      );
    });

onMessageOpenedApp

to track when the notification clicked and the app is in background

    FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
      // track notification activity as clicked
      _promizeSdkPlugin.trackNotificationActivity(
        activityType: NotificationAction.clicked,
        data: message.data,
      );
    });

Note

If you want to send Event data contains a DateTime it is required to use this format (Y-m-d H:i:s ex: 2023-03-14 00:00:00)

Built With

  • Flutter - the framework built for

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see the LICENSE.md file for details