Skip to content

Geofence

Introduction

StreetHawk's Geofencing plugin is used for running location based campaigns based on user's entry and exit into a geofence area. The document describes integrating StreetHawk's Geofence plugin into your application. You will be required to register the geofence of interest into StreetHawk console. You can find the source code of the plugin here.

Integration steps


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

  • Add streethawkgeofence plugin
    Execute below mentioned command to apply StreetHawk.

$ cd <APPLICATION_DIRECTORY>
$ cordova plugin add streethawkgeofence

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 streethawkgeofence

Additional configuration for iOS application

  • Modify Info.plist
    Since iOS 8 it needs to modify Info.plist to enable location service.

Create Your First Geofence Based Campaign


  • Create Geofence in StreetHawk Console
    Open StreetHawk console and click on Geofence under Growth Campaigns as shown below. Enter Title of the geofence and place the thumb pin at desired location to autofill latitude and longitude of your geofence.

  • Select Geofence filter
    Create a new campaign by selecting Campaigns under Growth Campaigns and by clicking the add button. Click on Geofence Filter as shown below. You may opt to select some single geofence or all geofences by clicking on the locations drop down and selecting the geofences for campaigns. You can select the minimum distance for triggering by selecting distance from around drop down menu.

  • Select an action
    Proceed to Choose the Engagement Method and select the desired action to be triggered when application user enters the geofence.

  • Set campaign running duration
    Schedule your campaign to run over the period of time desired by selecting Real-Time Monitoring option. Please note if the option is not selected, your campaign will fire only once and will target only those users who are present in the geofence at the moment when campaign ran.

  • Save and run campaign
    Give a title to your campaign and launch the campaign.

Delay asking for iOS location permission (iOS only)

Include in streethawklocations plugin, or streethawkgeofence plugin.

By default StreetHawk library request for location permission as soon as streethawkinit is called. In case you wish to delay this and later ask the user for location permission at an appropriate time, you can add the code be as shown below.

var sh = cordova.require("com.streethawk.core.Streethawk");
sh.shSetDefaultLocationService(false); //make streethawkinit not enable location service, delay for later time.
//do streethawkinit and other things.
sh.shSetLocationEnabled(true);  //later when ready to enable location service, call this.

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

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