Skip to content

Geofence

Introduction

StreetHawk's Geofence component is used for running location based campaigns based on user's entry and exit into a geofence area. The document describes integrating StreetHawk SDK's Geofence module into your application. You will be required to register the geofence of interest into StreetHawk console. Steps for registering geofence in StreetHawk console are described below under Create Your First Geofence Based Campaign section.

Prerequisite

StreetHawkPush component depends on StreetHawk's Analytics components. This document assumes that you have already integrated StreetHawkAnalytics component. if not then click here for detailed documentation on StreetHawkAnalytics components which describes steps to integrate Analytics component.

Integration Steps


  • Include StreetHawkAnalytics Component

1.In Xamarin Studio, double click on Components folder
2.Click on "Get More Components" and search for StreetHawk Geofence. Click Add to App
3.Once downloaded, click on Add to Project

  • Include Google Play Service - Location Component

Open components folder in Xamarin studio, search for Google Play Services -Location component and press Add to project.

  • Modify AndroidManifest.xml

Add the following location permissions

<manifest>
    ...

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application>
    ...
    </application>
</manifest>

Now add the following code under application tag of AndroidManifest.xml

<manifest>
...
    <application>   
...
        <uses-library android:name="com.google.android.maps" />
            <service
                android:name="com.streethawk.library.geofence.GeofenceService"
                android:exported="false"></service>
            <receiver
                android:name="com.streethawk.library.geofence.SHCoreModuleReceiver"
                android:enabled="true"
                android:exported="true">
                <intent-filter>
                    <action android:name="com.streethawk.intent.action.APP_STATUS_NOTIFICATION" />
                    <action android:name="android.location.PROVIDERS_CHANGED" />
                </intent-filter>
            </receiver>
</application>
</manifest>
  • Include statements

Add the following include statements in you application's launcher class

using Com.Streethawk.Library.Core;
using Com.Streethawk.Library.Geofence;
  • Initialise StreetHawk

Set application;s app_key and call init function from onCreate function of your application's launcher class as show below.

namespace XamHawkGeofence
{
    [Activity (Label = "XamHawkGeofence", MainLauncher = true, Icon = "@mipmap/icon")]
    public class MainActivity : Activity
    {
        int count = 1;

        protected override void OnCreate (Bundle savedInstanceState)
        {
            Xamarin.Insights.Initialize (XamarinInsights.ApiKey, this);
            base.OnCreate (savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            StreetHawk.Instance.SetAppKey (<APPKEY>);
            StreetHawk.Instance.Init (Application);
        }
    }
}
  • Start Geofence monitoring

Start monitoring geofences by calling StartGeofenceMonitoring() as shown below

SHGeofence.GetInstance(this).StartGeofenceMonitoring();

Create Your First Geofence Based Campaign


  • Create Geofence in StreetHawk Console

Open StreetHawk console and click on Geofence&Beacons 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.