Skip to content

Analytics

Introduction

StreetHawk's Analytics Component is core component of StreetHawk SDK. The module reports various vital raw data to StreetHawk servers which is 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. All other components of StreetHawk depends on Analytics component for it's functioning.

Integration Steps


  • Include StreetHawkAnalytics Component

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

  • Modify AndroidManifest.xml

Open AndroidManifest.xml (located inside Properties folder) of your application. Add the following permissions under the Manifest tag

<manifest>
    ...

    <uses-permission android:name="android.permission.INTERNET" />
        <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>
    ..

    </application>
</manifest>

Also add the following code under Application tag of AndroidManifest.xml

<manifest>
    <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>
  • Initialise StreetHawk

Include StreetHawk component adding following statement

using Com.Streethawk.Library.Core;

Add the following code in OnCreate function of Launcher class of your application.

[Activity (Label = "XamHawkAnalytics", 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 ("<APP_KEY>"); //Replace with your application's AppKey
            StreetHawk.Instance.Init (Application);
            }
    }

Identify Your App Users

  • Tagging customer's unique ID
string cuid = "support@streethawk.com"; // using user's email address cuid
StreetHawk.Instance.TagCuid(cuid);
  • Tagging customer's first name
string key = "sh_first_name";
string name = "David";
StreetHawk.Instance.TagString(key,name);
  • Tagging customer's email address
string key = "sh_email";
string email = "support@streethawk.com";
StreetHawk.Instance.TagString(key,email);

Tag Events Inside Application

  • String value
string key = "ProductOffer";
string value = "Liked";
StreetHawk.Instance.TagString(key,value);
  • Numeric Value
string key = "BidValue";
int value = 554.95;
StreetHawk.Instance.TagNumeric(key,value);
  • DateTime Value
// Example code using pre-defined StreetHawk keys
string key = "sh_registered";
string datetime_value = "2014-07-25 15:33:20";
StreetHawk.Instance.TagDatetime(key, datetime_value); // string Date time value in UTC
// Example code using custom tag
string key = "Birthday";
string string_value = "2014-07-25 15:33:20";
StreetHawk.Instance.TagDatetime(key, datetime_value);
  • Increment Tag's value
string key = "LikeButtonPressed";
StreetHawk.Instance.IncrementTag(key);  
  • Remove Tag
string key = "RemoveUser";
StreetHawk.Instance.RemoveTag(key); 

Track User Entering and Exiting View

  • View Enter

Call NotifyViewEnter when user enters a view. Following is the sample code for the same

StreetHawk.Instance.NotifyViewEnter ("<Add_VIEW_NAME>");
  • View Exit

Call NotifyViewExit when user exits a view. Following is the sample code for the same

StreetHawk.Instance.NotifyViewExit ("<ADD_VIEW_NAME>");