Copied To Clipboard

Cordova


Integration

Import the NotifyVisitors SDK in your project

  1. Download the SDK from the link given below. You can also check our sample project for the reference.
  2. Download SDK Sample App

    Extract the file. Open your app (i.e. your cordovaAppFolder >> platforms >> android) in Android Studio and now form Android Studio goto File -> New -> Import Module and browse to the extracted folder (i.e. notifyvisitors) and click on finish.

  3. Add the following dependency to your build.gradle file:
  • Android

        dependencies {
            compile project(":notifyvisitors")
        }   
        
  1. In the (assets/www/js) folder copy the notify_plugin.js object.
  2. In the (src/your_package_folder) folder copy the NotifyPlugin.java class.
  3. In the (res/xml/config.xml) file add the below given code:
  • Android

       .................
        .................
        <feature name="NotifyPlugin">
        <param name="android-package"
        value="your_package.NotifyPlugin" />
        </feature>
        .................
        .................
        </widget>
        
  1. where your_package is the package name of your app
  2. In the (assets/www/cordova_plugin.js) edit the module.exports to register notify_plugin.js & deep_link.js like this:
  • Android

        module.exports = [
        {"file": "js/notify_plugin.js"},
        {"file": "js/deep_link.js"}  
        ];
        

Configure AndroidManifest.xml

  1. Insert the below XML snippet inside application tag of your AndroidManifest.xml file
  • Android

         <aplication>
            <meta-data android:name="notifyvisitors_bid" android:value="52X"> </meta-data>
            <meta-data android:name="notifyvisitors_bid_e"
        android:value="768B370B0002A3DEE5E8CD991DA80A12" ></meta-data>  
        
  1. Insert the below XML snippet inside manifest tag of your AndroidManifest.xml file
  • Android

        <manifest>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.GET_ACCOUNTS" />
        <uses-permission android:name="android.permission.WAKE_LOCK" />
  
        

Initialise the SDK

Initialise the SDK from the onCreate method of your Application class.

  • Android

        NotifyVisitorsApplication.register(this);    
        

OR

If you don’t have your own application class, then you can register our application class in the manifest file.

  • Android

        <application android:name="com.notifyvisitors.notifyvisitors.NotifyVisitorsApplication">    
        

InApp Notifications

InApp Notifications include both Banners and Surveys. These are displayed based on Custom Rule.

To show in app popups in your app, you can call the show() method like this:-

  • Android

        var newSuccess = function(successMessage) {
        var pageName = successMessage.PageToBeOpened;
               //alert(JSON.stringify(successMessage));
        var parameters = successMessage.actionParamsArray;
        var params = JSON.stringify(parameters);
        var link = pageName+'?parameters='+params;
              window.location.href = link;
        };
        notifyPlugin.show((JsonObject)tokens,(JsonObjects)customObjects,(String)fragmentName,newSuccess);
             
        

*newSuccess is required if you want to navigate user within the app, on click of in-app popup, else you can pass null as last parameter in show() method

At the receiving end you can get parameters like this:

  • Android

        var result = app.getUrlParameter('parameters');
        var jsonData =JSON.parse(result);
        var value = jsonData.key2;      
        

Dynamic Tokens() -Dynamic tokens are used to show personalised content in Notification messages real time.

  • Android

        var dynamicToken = '{"firstCategory":"standard","secondCategory":"fancy"}';
           
        

Custom Rules() - This data can be used in configuring targeting rules for the Notifications.

  • Android

        var customRule = '{"categoryID":"101","categoryName":"shoes"}';
           
        

Fragment Name (string) - If you have multiple fragment tabs in your activity, you can call the show method for each fragment and pass the fragment name as third argument.

Push Notifications

Add permissions in AndroidManifest.xml file

  • Android

       <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>  
            <permission android:name="your_app_package_name.permission.C2D_MESSAGE" 
       android:protectionLevel="signature" />
            <uses-permission
       android:name="your_app_package_name.permission.C2D_MESSAGE" />

        

Configure Notification’s Icon

For below Lollipop devices:- Devices below lollipop shows only one icon in the push notifications, that you can configure from notifyvisitors panel.To change default notification icon, you can replace icon sm_push.png in notifyvisitors/src/main/res/drawable folder.

For Lollipop & above devices:- Devices supporting Lollipop & above shows two notifications icon i.e., small push icon & large push icon.

Large push icon is configured from panel & is shown as main push icon. However if large push icon is not configured from panel then small push icon is shown as main push icon.Small push icon

Small push icon according to android documentation(https://developer.android.com/about/versions/android-5.0-changes.html) should be transparent, otherwise it will be shown as square white spot. To change default notification icon, you can replace icon sm_push_logo.png in notifyvisitors/src/main/res/drawable folder.

Show Notification Center

You can show a list of push notifications received in an In-app Notification Center. Expiry of the notifications can be set from the panel.

You can call the showNotifications() method to show Notification Center on any click action.

  • Android

        notifyPlugin.showNotifications((int)dismiss);
        

Track Users

User API enables you to track a users' activity as they move from device to device and attach attributes to their profiles. Attributes enrich user profiles, like email, username, mobile, gender etc.

This method should be called when the user is identified (mostly on login).

  • Android

        notifyPlugin.userIdentifier(String userID, JSONArray jsonArray);
        

USER_ID - Setting the Unique ID is a critical piece to tie a user across devices and installs/uninstalls as well across all platforms (i.e. iOS, Android, Windows, The Web). Unique ID can be something like an email ID, a username (unique), or any Backend generated ID.

USER_ATTRIBUTES (JSON object) - You can set the user attributes like name, email, mobile number. These can then be used to send personalised content in notifications. But these attributes can not be used in segmenting the users.

Default Attribute Names -

  • name
  • email
  • mobile

You can also pass your custom attributes like username, birthday, first name, last name.

IMPORTANT :

Attribute Names should contain only alpha-numerics, white spaces or ‘_’ ; No other special characters are allowed. Recommended names - ‘first_name’, ‘last_name’

Sample Code

  • Android

        var name = '{"name":"John"}';
        var number = '{"number":"9898XXXXXX"}';
        var userArray = JSON.parse(name,number);
        notifyPlugin.userIdentifier('yourUserID',userArray);
        

Track Events

Event API enables you to record any actions your users perform, along with any properties that describe the action. These are then used for analytics, user segmentation or to trigger engagements or other actions.

  • Android

       notifyPlugin.event(String eventName, JSONObject attributes, String ltv, String scope);
        

EVENT_NAME (string) Name of the event like sale, register.
Event names should contain only alpha-numerics, white spaces or ‘_’ ; No other special characters are allowed.

EVENT_ATTRIBUTES (JSON object) Attributes associated with the event.
Attribute values should be passed in the form of Javascript strings, booleans and numbers respectively. Similarly date attribute values are expected in the form of Javascript date objects.

IMPORTANT :

Attribute Names should contain only alpha-numerics, white spaces or ‘_’ ;
No other special characters are allowed.
Recommended names - ‘category’, ‘price_usd’

LIFETIME_VALUE (integer) The score you would like to reward the user on performing this event like 10, 100.

SCOPE (integer)The scope of the event, whether it should be tracked every time it is called, or per session, or once in a lifetime. This parameter is used to minimise the duplication of data in analytics.
It is an integer whose values are :

  1. Track every time the api is called
  2. Track once per session
  3. Track once in a lifetime

  • Android

        var eventAttributes = '{"price":"20000","firstCategory":"standard","secondCategory":"fancy"}';
            notifyPlugin.event('eventName',eventAttributes,'7', '2');
        
  1. Add intent filter tag of your Androidmanifest.xml file inside activity tag something like this:
  • Android

            <activity android:name=”MainActivity”
                <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
             <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
               <data android:scheme="appscheme" />
             </intent-filter></activity>   
        
  1. In the (assets/www/js) folder copy the deep_link.js object.
  2. Create a DeepLinkHandler.js file & copy the following code into that file:
  • Android

            function handleOpenURL(schemeData) {
            var link = schemeData.split('://');
            var url = link[1];
            window.location = url;
            }
        

Register DeepLink.js file in your index.html file like this:

  • Android

            <script type = "text/javascript" src="js/DeepLinkHandler.js"></script>