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 are 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.

Integration Steps


  • Add dependencies to app

1) Include StreetHawk Analytics in your TOP level build.gradle for all projects.

allprojects {
    ...
    repositories {
        ...
        maven {
            url "http://pkg.streethawk.com/artifactory/streethawk"
        }
        ...
    }
    ...
}

2) Include StreetHawk Analytics dependencies in your module level build.gradle.

dependencies {
    ...
    compile "com.streethawk:core:latest.release"
    ...
}

3) Add the following code in onCreate method of your application's Launcher Activity.

import com.streethawk.library.core.StreetHawk;

.....
.....    

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
.....
.....
        Application app = getApplication();
        StreetHawk.INSTANCE.setAppKey(<APP_KEY>);  // APP_KEY registered with StreetHawk
        StreetHawk.INSTANCE.init(app);
    }

Identify if your install has Succeeded:

Note

implement the ISHEventObserver interface

public class MyActivity implement ISHEventObserver {

and Register

StreetHawk.INSTANCE.registerEventObserver(this);

Function is called when install is successful with Device:

public class MyActivity implement ISHEventObserver {


  StreetHawk.INSTANCE.registerEventObserver(this);


 @Override
    public void onInstallRegistered(final String installId) {
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(mActivity, "Install registered " + installId, Toast.LENGTH_LONG).show();
            }
        });
    }
}

Identify if your install has FAILED:

** implement the ISHErrorObserver interface**

public class MyActivity implement ISHErrorObserver {

and Register

StreetHawk.INSTANCE.registerInstallErrorObserver(this);

Function is called when install has failed on Device:

public class MyActivity implement ISHErrorObserver{


  StreetHawk.INSTANCE.registerInstallErrorObserver(this);


 @Override
    public void onInstallRegisterError(final String errorMsg) {
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(mActivity, "Oh no.. something went wrong " + errorMsg, Toast.LENGTH_LONG).show();
            }
        });
    }
}

Identify your app users

  • Tagging customer's unique ID
public void registerUser {
        // Tagging cuid
        StreetHawk.INSTANCE.tagCuid("<USER_UNIQUE_ID");
    }
  • Tagging user's email address
String key = "sh_email";
String string_value = "support@streethawk.com";
StreetHawk.INSTANCE.tagString(key, string_value ); 
  • Tagging user first name
String key = "sh_first_name";
String string_value = "David";
StreetHawk.INSTANCE.tagString(key, string_value );

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 demonstrate tagging of important events inside your application.

  • String value
String key = "ProductOffer";
String string_value = "Liked";
StreetHawk.INSTANCE.tagString(key, string_value );
  • Numeric value
String key  = "BidValue";
double numeric_value = 549.99;
StreetHawk.INSTANCE.tagNumeric(key, numeric_value);   // double numeric_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);

Alternatively you may use StreetHawk’s getFormattedDateTime() API to get current time in UTC.

String key = "ValueSaved";
StreetHawk.INSTANCE.tagDatetime(key, StreetHawk.getFormattedDateTime(System.currentTimeMillis()));
  • Increment Tag Value
String key = "PageVisited";
StreetHawk.INSTANCE.incrementTag(key);
  • Remove Tag
String key = "RemoveUser";
StreetHawk.INSTANCE.removeTag(key);