Skip to content

Analytics

Introduction

The analytics module is core module of StreetHawk SDK. The module reports various vital raw data to StreetHawk servers which is then further processed and used for various analytics for your application. The module also provides API for tagging the install, identifying the users and tracking various important events inside your application.

Pre-requisites

The documents assume that you have downloaded and added the boiler-plate code described in the introduction document. You will require IStreetHawkAnalytics.cs, StreetHawkAnalytics.cs (iOS) and StreetHawkAnalytics.cs (Android) in particular for StreetHawkAnalytics module.

Integration Steps

  • Add StreetHawkAnalytics Component

  1. In iOS project, right click on component folder
  2. Click on "Get More Components" and search for StreetHawk Analytics. Click Add to App.
  3. Once downloaded, click on Add to Project.
  4. Repeat the above steps for adding StreetHawkAnalytics component in .Droid project of your application

  • Add platform specific code
    • iOS

Modify Info.plist to enable background fetch. This indicates server when the App is uninstalled.

Click Info.plist to open it, move to "Background Modes" and enable "Background fetch".

  • Android

Copy and paste the below code in AndroidManifest.xml located under properties folder of your Droid project.

<?xml version="1.0" encoding="utf-8"?>
<manifest >
...
    <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.GET_TASKS" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application >

     <receiver
            android:name="com.streethawk.library.core.StreethawkBroadcastReceiver"
            android:enabled="true"
            android:exported="true" >
            <intent-filter>
                <action android:name="android.location.PROVIDERS_CHANGED" />
                <action android:name="android.intent.action.TIMEZONE_CHANGED" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                <action android:name="com.streethawk.intent.action.gcm.STREETHAWK_APP_STATUS_CHK" />
            </intent-filter>
        </receiver>

        <service
            android:name="com.streethawk.library.core.StreetHawkCoreService"
            android:enabled="true"
            android:exported="true" >
        </service>
...     

    </application>
</manifest> 

Add the below-mentioned code in OnCreate function.

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity,
    IStreetHawkAnalytics,ISHEventObserver
    {
        private static Application mApplication;  //Application instance to be used by StreetHawk

        protected override void OnCreate(Bundle bundle)
        {
            ...
            new StreetHawkAnalytics(Application);

        }
  • Initialise StreetHawk

Open App.Xaml.cs in your portable project and add the following code in OnStart function as shown below.

using StreetHawkCrossplatform;

...
        protected override void OnStart()
        {
            //Replace APP_KEY below with AppKey registered for your application
            DependencyService.Get<IStreetHawkAnalytics>().SetAppKey("<APP_KEY>");
            DependencyService.Get<IStreetHawkAnalytics>().Init();
        }
...

Identify Your App Users

  • Tagging customer's unique ID
using StreetHawkCrossplatform;

string cuid = "support@streethawk.com"; // using user's email address as cuid
DependencyService.Get<IStreetHawkAnalytics>().TagCuid(cuid);
  • Tagging customer's first name
using StreetHawkCrossplatform;

string key = "sh_first_name";
string name = "David";
DependencyService.Get<IStreetHawkAnalytics>().TagString (key, name);
  • Tagging customer's email
using StreetHawkCrossplatform;

string key = "sh_email";
string email = "support@streethawk.com";
DependencyService.Get<IStreetHawkAnalytics>().TagString (key, email);

Tag Events Inside Application

  • String Value
using StreetHawkCrossplatform;

string key = "ProductOffer";
string value = "Liked";
DependencyService.Get<IStreetHawkAnalytics>().TagString (key, value);
  • Numeric Value
using StreetHawkCrossplatform;

string key = "BidValue";
double value = 554.95;
DependencyService.Get<IStreetHawkAnalytics>().TagNumeric (key, value);
  • DateTime value
using StreetHawkCrossplatform;

string key = "Birthday";
DateTime datetime_value = new DateTime(2014, 7, 25, 15, 33, 20);
DependencyService.Get<IStreetHawkAnalytics>().TagDateTime (key, datetime_value);
  • Increment Tag
using StreetHawkCrossplatform;

string key = "LikeButtonPressed";
DependencyService.Get<IStreetHawkAnalytics>().IncrementTag (key);

or

using StreetHawkCrossplatform;

string key = "LikeButtonPressed";
DependencyService.Get<IStreetHawkAnalytics>().IncrementTag (key, 100);
  • Remove Tag
using StreetHawkCrossplatform;

string key = "LikeButtonPressed";
DependencyService.Get<IStreetHawkAnalytics>().RemoveTag (key);

Track User Entering and Exiting Views

  • View Enter
using StreetHawkCrossplatform;

protected override void OnAppearing()
{
    base.OnAppearing();
    DependencyService.Get<IStreetHawkAnalytics>().NotifyViewEnter(this.GetType().Name);
}
  • View Exit
using StreetHawkCrossplatform;

protected override void OnDisappearing()
{
    base.OnDisappearing();
    DependencyService.Get<IStreetHawkAnalytics>().NotifyViewExit(this.GetType().Name);
}