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

Integration Steps


  • Add pod to Application's Podfile

In pod file of your Application, add one line:

pod "streethawk/Core"
  • Install Pod

In the OS X command line terminal, enter the following command (making sure that you’re in the directory containing your project and Podfile).

First time to install StreetHawk framework:

pod install

Next to check and upgrade to latest StreetHawk framework:

pod update

You should see output similar to the following.

Analysing dependencies
Downloading dependencies
Installing streethawk/Core (1.7.0)
Generating Pods project
Integrating client project

This will automatically add StreetHawk/Core open source code into your pod project, and configure everything ready for use.

Note: there is a bug in Cocoapods, which may cause error "No such file or directory". Solution: delete Pods folder and Podfile.lock file, run "pod install" again.

  • Modify Info.plist

The "Heartbeat" feature allows you to report on App uninstalls. If your App is inactive for 6 hours, it wakes up in the background and tells us it's still alive (hasn't been uninstalled), then goes back to sleep. To enable this feature: 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.

  • Initialise StreetHawk SDK.
#import <StreetHawkCore/StreetHawkCore.h>  // StreetHawk header file

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [StreetHawk registerInstallForApp:<your_app_key> withDebugMode:YES<print log info>];
    return YES;
}

Swift code:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
    SHApp.sharedInstance().registerInstall(forApp: "<your_app_key>", withDebugMode: true<print log info>)
    return true
}

where,

  • your_app_key: The app_key register on StreetHawk Cloud.
  • debugMode (Yes or No): This is to print verbos:1e logging to the device console.

StreetHawk automatically configures a lot of system AppDelegate functions. In case there is a need to configure AppDelegate functions manually, then follow iOS Manual Setup

Note: All the APIs in StreetHawk SDK can be used with Swift as shown in the example below.

  • Import StreetHawk framework by adding below to bridging header file, file name is <project_name>-Bridging-Header.h:

  • Add the bridging header file into project settings:

  • All the corresponding functions to called using syntax [StreetHawk <API>] in objective c, can be called as in swift as SHApp.sharedInstance().<API> as shown below.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
    SHApp.sharedInstance().registerInstall(forApp: "<app_key>", withDebugMode: true)        
    return true
}
  • In case in Swift you would like to get AppDelegate, use code:
let appDelegate = SHApp.sharedInstance().getAppDelegate() as! AppDelegate

Identify your app users

  • Tagging customer's unique ID
[StreetHawk tagCuid:@"<USER_UNIQUE_ID>"];
  • Swift code:
SHApp.sharedInstance().tagCuid("<USER_UNIQUE_ID>")
  • Tagging user's email address
NSString *key = @"sh_email";
NSString *string_value = @"hello@streethawk.com";
[StreetHawk tagString:string_value forKey:key];
  • Swift code:
let key = "sh_email"
let string_value = "hello@streethawk.com"
SHApp.sharedInstance().tagString(string_value, forKey: key)
  • Tagging user first name
NSString *key = @"sh_first_name";
NSString *string_value = @"David";
[StreetHawk tagString:string_value forKey:key];
  • Swift code:
let key = "sh_first_name"
let string_value = "David"
SHApp.sharedInstance().tagString(string_value, forKey: key)

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
NSString *key = @"ProductOffer";
NSString *string_value = @"Liked";
[StreetHawk tagString:string_value forKey:key];
  • Swift Code:
let key = "ProductOffer" let string_value = "Liked"
SHApp.sharedInstance().tagString(string_value, forKey: key)
  • Numeric value
NSString *key = @"BidValue";
NSInteger numeric_value = 549;
[StreetHawk tagNumeric:numeric_value forKey:key];
  • Swift Code:
let key = "BidValue"
SHApp.sharedInstance().tagNumeric(549, forKey: key)
  • Tag DateTime value
// Tagging using predefined StreetHawk tag.
NSString *key = @"sh_registered";
NSDate *datetime_value = [NSDate date];
[StreetHawk tagDatetime:datetime_value forKey:key];

// Tagging using custom tag
NSString *key = @"Birthday";
NSDate *datetime_value = [NSDate date];
[StreetHawk tagDatetime:datetime_value forKey:key]; // string Date time value in UTC
  • Swift Code:
// Tagging using predefined StreetHawk tag.
let key = "sh_registered"
let datetime_value = NSDate()
SHApp.sharedInstance().tagDatetime(datetime_value, forKey: key)

// Tagging using custom tag
let key = "Birthday"
let datetime_value = NSDate()
SHApp.sharedInstance().tagDatetime(datetime_value, forKey: key) // string Date time value in UTC
  • Increment Tag Value
NSString *key = @"PageVisited";
[StreetHawk incrementTag:key];
  • Swift Code
let key = "PageVisited"
SHApp.sharedInstance().incrementTag(key)
  • Remove Tag
NSString *key = @"RemoveUser";
[StreetHawk removeTag:key];
  • Swift Code:
let key = "RemoveUser"
SHApp.sharedInstance().removeTag(key)

Track VC

Use Track VC feature for tracking events of user entering and exiting a view controller inside your application without writing lines of code inside every viewwDidLoad function.

Simply replace the base ViewController classes and inherit from classes as shown below.

From To
UITableViewController StreetHawkBaseTableViewController
UIViewController StreetHawkBaseViewController
UICollectionViewController StreetHawkBaseCollectionViewController

Please note that new base classes does not change any behaviour effect performance. Rather it simply notifies StreetHawk about user entering and exiting a view controller.

In case the StreetHawk base classes cannot, then explicitly notify enter or exit from a VC as shown below.

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [StreetHawk shNotifyPageEnter:self.class.description];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [StreetHawk shNotifyPageExit:self.class.description];
}

Swift code:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    SHApp.sharedInstance().shNotifyPageEnter(self.description)
}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    SHApp.sharedInstance().shNotifyPageExit(self.description)
}
  • Capture Advertising Identifer

StreetHawk can automatically capture advertising identifier to identify your customer's device. When you enable this feature, you need to provide a reason for Apple when submitting to AppStore. To enable this feature, add AdSupport.framework into your project. The SDK will automatically capture advertising identifier and you can identify your customer's device. If you would like not to capture, just not add AdSupport.framework, and your App will not capture advertising identifier so that it can be submitted to AppStore without providing reason.

API document

Check here for API document.