Netmera Flutter SDK

NETMERA is a Mobile Application Engagement Platform. We offer a series of development tools and app communication features to help your mobile business ignite and soar.

Installation

For using this package as a library:
  • Add this to your package's pubspec.yaml file
dependencies:
  netmera_flutter_sdk: ^x.x.x
  • You can install packages from the command line with Flutter:
$ flutter pub get

For both native sides(Android & iOS) you don't have to include extra Netmera SDK libraries.

Setup - Android Part

  1. Create and register your app in Firebase console.

  2. Download google-services.json file and place it into android/app/ folder.

  3. In your project's build gradle file, add the following dependency.

buildscript {
  dependencies {
    // Add this line
    classpath 'com.google.gms:google-services:4.2.0'
  }
}
  1. In your app's build gradle file, add the following dependency.

 dependencies {
 
     implementation 'androidx.core:core:1.1.0'
     
 }
  1. Add the following into the bottom of app's buid.gradle file
apply plugin: 'com.google.gms.google-services'
  1. Create an application class as shown below.
  • Your Application class must extends FlutterApplication and implements PluginRegistry.PluginRegistrantCallback , if you want to listen Push Broadcasts in dart part.
public class NMApp extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {

      @Override
      public void onCreate() {

          super.onCreate();

          FNetmeraService.setPluginRegistrant(this); // This is needed for receiving push broadcasts in dart classes
          FNetmera.logging(true); // This is for enabling Netmera logs.
          FNetmera.init(this, <YOUR GCM SENDER ID>, <YOUR NETMERA API KEY>); // Calling Netmera init.
      }

      @Override
      public void registerWith(PluginRegistry pluginRegistry) {
          GeneratedPluginRegistrant.registerWith(pluginRegistry);
      }
  }
  1. Register Application and Service classes into manifest file.
 <application
        android:name=".NMApp"
        android:label="netmera_flutter_sdk_example"
        android:icon="@mipmap/ic_launcher">

        <!-- Register broadcast class as below -->
        <receiver
            android:name="com.netmera.netmera_flutter_sdk.FNetmeraPushBroadcastReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.netmera.push.intent.REGISTER" />
                <action android:name="com.netmera.push.intent.RECEIVE" />
                <action android:name="com.netmera.push.intent.OPEN" />
                <action android:name="com.netmera.push.intent.DISMISS" />
                <action android:name="com.netmera.push.intent.BUTTON" />
            </intent-filter>
        </receiver>

         <!-- Register service class as below -->
        <service
            android:name="com.netmera.netmera_flutter_sdk.FNetmeraService"
            android:exported="true"
            android:permission="android.permission.BIND_JOB_SERVICE">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </service>

        ...
        ..
        .
  1. Inside dart class add the following
void main() {
  initBroadcastReceiver();
  runApp(MyApp());
}

void _onPushRegister(Map<dynamic, dynamic> bundle) async {
  print("onPushRegister: $bundle");
}

void _onPushReceive(Map<dynamic, dynamic> bundle) async {
  print("onPushReceive: $bundle");
}

void _onPushDismiss(Map<dynamic, dynamic> bundle) async {
  print("onPushDismiss: $bundle");
}

void _onPushOpen(Map<dynamic, dynamic> bundle) async {
  print("onPushOpen: $bundle");
}

void _onPushButtonClicked(Map<dynamic, dynamic> bundle) async {
  print("onPushButtonClicked: $bundle");
}

void initBroadcastReceiver() {
  NetmeraPushBroadcastReceiver receiver = new NetmeraPushBroadcastReceiver();
  receiver.initialize(
    onPushRegister: _onPushRegister,
    onPushReceive: _onPushReceive,
    onPushDismiss: _onPushDismiss,
    onPushOpen: _onPushOpen,
    onPushButtonClicked: _onPushButtonClicked,
  );
}

Setup - iOS Part

  1. Navigate to ios folder in your terminal and run the following command.
$ pod install
  1. If you are using Swift, enter the following in your Runner-Bridging-Header.h.
#import "FNetmera.h"
#import "FNetmeraService.h"
#import "NetmeraFlutterSdkPlugin.h"
  1. If you want to use Android alike message sending from iOS to dart please consider to shape your AppDelegate class as following.
import UIKit
import Flutter

//This function is needed for sending messages to the dart side. (Setting the callback function)
func registerPlugins(registry: FlutterPluginRegistry) {
    GeneratedPluginRegistrant.register(with: registry)
};

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate,UNUserNotificationCenterDelegate,NetmeraPushDelegate {

    override func application(_ application: UIApplication,
                didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    GeneratedPluginRegistrant.register(with: self)

        if #available(iOS 10.0, *) {
        UNUserNotificationCenter.current().delegate = self
    } else {
        // Fallback on earlier versions
    };

        //For triggering onPushReceive when app is killed and push clicked by user
        let notification = launchOptions?[.remoteNotification]
        if notification != nil {
            self.application(application, didReceiveRemoteNotification: notification as! [AnyHashable : Any])
        }

    //This function is needed for sending messages to the dart side.
    NetmeraFlutterSdkPlugin.setPluginRegistrantCallback(registerPlugins)

    FNetmera.logging(true) // Enable Netmera logging
    FNetmera.init("<YOUR-NETMERA-KEY>") //Initializing Netmera packages.
    FNetmera.setPushDelegate(self) //

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }


    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        FNetmeraService.handleWork(ON_PUSH_REGISTER, dict: ["pushToken": deviceToken])
    }

    override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        FNetmeraService.handleWork(ON_PUSH_RECEIVE, dict:["userInfo" : userInfo])
    }


    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler:
        @escaping () -> Void) {

        if response.actionIdentifier == UNNotificationDismissActionIdentifier {
            FNetmeraService.handleWork(ON_PUSH_DISMISS,dict:["userInfo" : response.notification.request.content.userInfo])
        }
        else if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
            FNetmeraService.handleWork(ON_PUSH_OPEN, dict:["userInfo" : response.notification.request.content.userInfo])
        }
        completionHandler()
    }

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([UNNotificationPresentationOptions.alert])
    }
}

For example if you trigger FNetmeraService.handleWork(ON_PUSH_RECEIVE, dict:["userInfo" : userInfo]) from AppDelegate, in the dart part the following method will be triggered.

void _onPushReceive(Map<dynamic, dynamic> bundle) async {
  print("onPushReceive: $bundle");
}

Please take a look at Setup-Android part 8

Calling Dart methods

Update User Example
updateUser() {
    NetmeraUser user = new NetmeraUser();
    user.setUserId(userController.text);
    user.setName(nameController.text);
    user.setSurname(surnameController.text);
    user.setEmail(emailController.text);
    user.setMsisdn(msisdnController.text);
    user.setGender(int.parse(_selectedGender));
    Netmera.updateUser(user);
  }
Sending Event Examples
  void sendLoginEvent() {
    NetmeraEventLogin loginEvent = new NetmeraEventLogin();
    Netmera.sendEvent(loginEvent);
  }

  void sendRegisterEvent() {
    NetmeraEventRegister registerEvent = new NetmeraEventRegister();
    Netmera.sendEvent(registerEvent);
  }

  void sendViewCartEvent() {
    NetmeraEventCartView cartViewEvent = new NetmeraEventCartView();
    cartViewEvent.setItemCount(3);
    cartViewEvent.setSubTotal(15.99);
    Netmera.sendEvent(cartViewEvent);
  }

  void purchaseEvent() {
    NetmeraLineItem netmeraLineItem = new NetmeraLineItem();
    netmeraLineItem.setBrandId("brandId12");
    netmeraLineItem.setBrandName("brandNameInomera");
    netmeraLineItem.setCampaignId("campaignId1223");
    netmeraLineItem.setCategoryIds(["categoryIds1", "categoryIds2"]);
    netmeraLineItem.setCategoryNames(["categoryNames1", "categoryNames2", "categoryNames3"]);
    netmeraLineItem.setKeywords(["keyword1", "keyword2", "keyword3"]);
    netmeraLineItem.setCount(12);
    netmeraLineItem.setId("Id123123");
    netmeraLineItem.setPrice(130);

    NetmeraEventPurchase purchaseEvent = new NetmeraEventPurchase();
    purchaseEvent.setCoupon("INOMERACODE");
    purchaseEvent.setDiscount(10);
    purchaseEvent.setItemCount(2);
    purchaseEvent.setPaymentMethod("Credit Card");
    purchaseEvent.setSubTotal(260.89);
    purchaseEvent.setShippingCost(0.0);
    purchaseEvent.setLineItems([netmeraLineItem, netmeraLineItem]);
    Netmera.sendEvent(purchaseEvent);
  }

For detailed information please explore example folder in the netmera sdk library.

Libraries

Netmera
NetmeraEvent
NetmeraEventBannerOpen
NetmeraEventBatteryLevel
NetmeraEventCartAddProduct
NetmeraEventCartRemoveProduct
NetmeraEventCartView
NetmeraEventCategoryView
NetmeraEventContent
NetmeraEventContentComment
NetmeraEventContentRate
NetmeraEventContentView
NetmeraEventInAppPurchase
NetmeraEventLogin
NetmeraEventOrderCancel
NetmeraEventProductComment
NetmeraEventProductRate
NetmeraEventProductView
NetmeraEventPurchase
NetmeraEventRegister
NetmeraEventScreenView
NetmeraEventSearch
NetmeraEventShare
NetmeraEventWishList
NetmeraInboxFilter
NetmeraLineItem
NetmeraProduct
NetmeraPushBroadcastReceiver
NetmeraPushInbox
NetmeraUser
callbackDispatcher