Skip to content

Push

Introduction

StreetHawk's Push plugin lets your send push notifications from StreetHawk server to your application. The plugin also calculates user's response to the push notification and presents you with Analytics for the push notification based campaigns. You can find the source code of the plugin here.

Integration steps


  • Add streethawkanalytics plugin

Push plugin depends on analytics plugin. Click here to integrate StreetHawk's Analytics plugin if you haven't already done it.

  • Add streethawkpush plugin

Execute below mentioned command to apply StreetHawk.

$ cd <APPLICATION_DIRECTORY>
$ cordova plugin add streethawkpush

Alternatively you can use plugman to install the plugins by using following commands:

plugman install --platform <android|ios>  --project ./PATH_TO_PROJECT/platform/<android|ios> --plugin streethawkpush

Configuration

  • Configure push messaging (iOS)
    Configure push messaging(iOS) describes steps for creating p12 files and upload the same on StreetHawk server.

  • Configure push messaging (Android)
    Configure push messaging (Android) describes steps for creating Google API project for your application to obtain SenderId (Project Number) and register API key with StreetHawk. Once done, set project number inside your application as shown below.

  • Click here for application registered on Firebase.

var sh = cordova.require("com.streethawk.core.Streethawk");
sh.shSetGcmSenderId("<SENDER_ID>");  // set gcm project number here
...
sh.streethawkinit(); 

Send your first push notification


After the install is successfully registered with StreetHawk, you can send a test push message by clicking User search under Growth campaigns, click on your test install and select Send Notification Tab. Enter any title and message and press send button. You should see a test message (Simple push message) arriving on your device.

Supporting Custom Dialogs Themes

For a push message, by default SDK generates Android's default notification dialog.However you can override this behaviour by following the steps as shown below.

  • setUseCustomDialog
    Use setUseCustomDialog to true if you wish to handle StreetHawk push messages in dialogs customised for your application
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.setUseCustomDialog(true);
  • pushDataCallback
    Use pushDataCallback to receive pushData from StreetHawk server in your application and to generate dialog based on it. Refer to table 1 for pushdata variables and table 2 for action codes.
var sh = cordova.require("com.streethawk.core.Streethawk");
function shSuccess(result){
        var action      = result.action;
            var title       = result.title;
            var message     =result.message;
            var msgid   = result.msgid;
            var data        = result.data;
            var portion = result.portion;
            var orientation = result.orientation;
        var speed       = result.speed;
            var sound       = result.sound;
        var badge   = result.badge;
            var noDialog    = result.displaywihtoutdialog;
        sh.pushDataCallback(shSuccess,function(){}); // registering call back again
    }
sh.pushDataCallback(shSuccess,function(){});
  • pushResultCallback
    Use pushResultCallback to receive push result from StreetHawk server in your application.Refer to table 1 for pushdata variables, table 2 for action codes and table 3 for push result codes
var sh = cordova.require("com.streethawk.core.Streethawk");
function shSuccess(result){
        var pushResult   = result.result
        var action      = result.action;
            var title       = result.title;
            var message     =result.message;
            var msgid   = result.msgid;
            var data        = result.data;
            var portion = result.portion;
            var orientation = result.orientation;
        var speed       = result.speed;
            var sound       = result.sound;
        var badge   = result.badge;
            var noDialog    = result.displaywihtoutdialog;
        sh.pushResultCallback(shSuccess,function(){}); // registering call back again
    }
sh.pushResultCallback(shSuccess,function(){});
  • sendPushResult
    use sendPushResult to send push result to StreetHawk SDK. The API can be used to notify push result if you are handling pushData using your custom dialog
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.sendPushResult(pushData.msgId,1);
  • Table 1: PushData variables and description
Variable Description
action Action associated to push msg. Action codes are listed in table below
msgid Id of push notification
title Title associated to a push message
message Message associated to a push message
data Data associated to a push message. Refer to table 4 for more details
portion If action = ACTION_OPEN_URL, portion denotes percentage of screen covered by animated webview which will display url in app.
orientation If action = ACTION_OPEN_URL, portion denotes direction from which the animated dialog will pop out.
speed If action = ACTION_OPEN_URL, speed denotes time in seconds for which the slide animation will be rendering.
displaywithoutdialog If action = ACTION_OPEN_URL,displaywithoutdialog if true, will display animated webview without confirmation dialog to user
sound File name of sound file which needs to be played as notification sound
badge Number to be displayed as badge. Not all Android devices can display badge
result Displays push result. Click here for push results
  • Table 2: Actions and respective codes
Action Code
ACTION_OPEN_URL 1
ACTION_LAUNCH_ACTIVITY 2
ACTION_RATE_APP 3
ACTION_USER_REGISTRATION_SCREEN 4
ACTION_USER_LOGIN_SCREEN 5
ACTION_UPDATE_APP 6
ACTION_CALL_TELEPHONE_NUMBER 7
ACTION_SIMPLE_PROMPT 8
ACTION_FEEDBACK 9
ACTION_ENABLE_BLUETOOTH 10
ACTION_ENABLE_PUSH_MSG 11
ACTION_ENABLE_LOCATION 12
  • Table 3 Push results codes and value
Push result Value
ACCEPTED 1
POSTPONED 0
DECLINE -1
  • Table 4 Data associated to actions
Action Data
ACTION_OPEN_URL Web url
ACTION_LAUNCH_ACTIVITY App page to be displayed
ACTION_RATE_APP NULL
ACTION_USER_REGISTRATION_SCREEN App page to be displayed
ACTION_USER_LOGIN_SCREEN App page to be displayed
ACTION_UPDATE_APP NULL
ACTION_CALL_TELEPHONE_NUMBER Phone number to be called
ACTION_SIMPLE_PROMPT NULL
ACTION_FEEDBACK JSON with feedback options. Empty JSON object for displaying simple feedback dialog
ACTION_ENABLE_BLUETOOTH NULL
ACTION_ENABLE_PUSH_MSG NULL
ACTION_ENABLE_LOCATION NULL

Remotely launch a view inside your application

StreetHawk's launch view page feature lets you route your application users to a given view remotely from StreetHawk console. Below mentioned are the steps.

  • shGetViewName
    Use shGetViewName to query name of the API which streetHawk library received from console when the app is in background.
var sh = cordova.require("com.streethawk.core.Streethawk");
var viewName;
sh.shGetViewNames(function(result){viewName=result},function(){});
  • shRegisterViewCallback
    Use shRegisterViewCallback to query name of the API which streetHawk library received from console when the app is in foreground.Call this api just after streethawkinit().
var sh = cordova.require("com.streethawk.core.Streethawk");
var viewName;
sh.shRegisterViewCallback(function(result){viewName=result},function(){});

Handle custom push payload in your application

Use shRawJsonCallback function to receive RawJSON from streetHawk server and handle the same in the application.

var sh = cordova.require("com.streethawk.core.Streethawk");
function shSuccess(result){
        var title = result.title;
        var message  = result.message;
        var rawjson = result.json;
        sh.shRawJsonCallback(shSuccess,function(){}); // registering call back again
    }

sh.shRawJsonCallback(shSuccess,function(){});

Delay asking for iOS notification permission (iOS only)

By default StreetHawk library register push notification on initialisation. In case you may wish to delay this and ask the user for push notification permission at the right time, you can use shSetDefaultNotificationService as shown below

var sh = cordova.require("com.streethawk.core.Streethawk");
sh.shSetDefaultNotificationService(false); //make streethawkinit not register for user notification, delay for later time.
//do streethawkinit and other things.
sh.shSetNotificationEnabled(true);  //later when ready to register for user notification, call this.

At any time, you can check whether notification is enabled by code:

var sh = cordova.require("com.streethawk.core.Streethawk");        
function failCallback(result) {
      alert("Fail: " + result);
}
var isNotificationEnabled;
sh.shGetNotificationEnabled(function(result){isNotificationEnabled = result;}, failCallback);