Skip to content

Analytics

Introduction

Analytics plugin is the core module of StreetHawk SDK. The module reports various vital raw data to StreetHawk servers which is further processed and used for various analytic for your application. The module also provides API for tagging the install, identifying the users and tracking various important events inside your application. You can find the source code of the plugin here.

Integration steps

  • Add streethawkanalytics plugin

Execute below mentioned command to add StreetHawk Analytics plugin to your application. In the command below, replace YOUR_APPLICATIONS_APP_KEY with application’s app_key registered with StreetHawk and URL_SCHEME_OF_APP with url scheme of your application for deeplinking.

$ cd <APPLICATION_DIRECTORY>
$ cordova plugin add streethawkanalytics  --variable APP_KEY="<YOUR_APPLICATIONS_APP_KEY>" --variable URL_SCHEME="<URL_SCHEME_OF_APP>"

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 streethawkanalytics --variable APP_KEY="<YOUR_APPLICATIONS_APP_KEY>" --variable URL_SCHEME="<URL_SCHEME_OF_APP>"
  • Initialise StreetHawk

Add the following code at launcher function of your application . For example you can call streethawkinit() as soon as you receive deviceReady event or inside onDeviceReady function.

<script type="text/javascript" src="plugins/com.streethawk.core/www/Streethawk.js"></script>
...
...
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    var sh = cordova.require("com.streethawk.core.Streethawk");
    sh.streethawkinit();
}
  • Modify Info.plist in iOS

For iOS application, In the Project Settings window -> Capabilities pane, if Background Modes isn’t enabled, click the switch in the Background Modes section, then enable Background Fetch.

  • Build and run Application

That’s it your application is integrated with StreetHawk Analytics plugin. Build and run your application by following commands

For iOS platform:

cordova run ios

For Android platform:

cordova run android

Identify your app users

  • Tagging customer's unique ID
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.tagCuid("<USER_UNIQUE_ID>");
  • Tagging user's email address
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.tagString("sh_email", "hello@streethawk.com");
  • Tagging user first name
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.tagString("sh_first_name", "David");
  • Tag user language

Use tagUserLanguage to tag install with language. When SDK running it automatically tag device's language. Customer can also use this API to tag language.

var sh = cordova.require("com.streethawk.core.Streethawk");
sh.tagUserLanguage("<language>");

Similarly you can tag other attributes by changing key and value. Click here for complete list of StreetHawk defined tags

Tag Events inside your application

The following code snippets demonstrates tagging of important events inside your application.

  • String value
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.tagString("ProductOffer", "Liked");
  • Numeric value
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.tagString("BidValue", 549);
  • Tag DateTime value
var sh = cordova.require("com.streethawk.core.Streethawk");
// Tagging using predefined StreetHawk tag.
sh.tagDatetime("sh_registered", "2015-10-18 15:33:20");
// Tagging using custom tag.
sh.tagDatetime("Birthday", "2015-10-18 15:33:20");

getCurrentFormattedDateTime can as well be used for tagging with current time in UTC. Sample implementation of the same is as shown below.

var sh = cordova.require("com.streethawk.core.Streethawk");
sh.getCurrentFormattedDateTime(function(result){sh.tagDatetime("login", result);}, function(){});
  • getFormattedDateTime

getFormattedDateTime returns StreetHawk format datetime since the miliseconds from 1970 in UTC. sample usage is as shown below.

var sh = cordova.require("com.streethawk.core.Streethawk");
var timeInUTC;
sh.getFormattedDateTime(60*60*1000, function(result){timeInUTC = result;}, function(error){});
  • Increment Tag Value
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.incrementTag("PageVisited");
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.incrementTag("PageVisited", 100);
  • Remove Tag
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.removeTag("RemoveUser");

Track when user enters and exit a page

The following code snippets demonstrates trace page enter and exit as demand.

  • Page enter
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.notifyViewEnter("welcome.html");
  • Page exit
var sh = cordova.require("com.streethawk.core.Streethawk");
sh.notifyViewExit("welcome.html");