Skip to content

Growth

Introduction

The Growth module lets your user share your application with friends. Also the feature can be extended to invite the new user to a deeplinked page inside your application. Create a Share button inside your application and call originateShareWithCampaign to generate the share url. StreetHawk SDK will then ask user ways to share the generated url. That is (email, post on Facebook etc). Below are the APIs which generates sharable URL. An open url scheme for deeplinking is required for StreetHawk growth.


  • Add pod to Application's Podfile

In pod file of your Application, add one line:

pod "streethawk/Growth"
  • 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)
Installing streethawk/Growth (1.7.0)
Generating Pods project
Integrating client project

This will automatically add StreetHawk/Core and StreetHawk/Growth 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

Add Open Url scheme in Info.plist.

  • Input App ID

Input your App ID into web console locating: App Details->App Summary->Apple App ID, which is formatted as <Team ID>.<Bundle ID>.

The team id and bundle id can read in https://developer.apple.com, section "iOS App IDs":

Add associate domain in XCode project

In XCode project, select the target, Capabilities->Associate Domains, add domain applinks:hwk.io, applinks:pointzi.streethawk.com.

Normally XCode can automatically re-generate provisioning profile for this change. In case XCode fail to do it, please go to https://developer.apple.com to enable "Associate Domains" in App ID, and re-generate provisioning profiles.

  • Generate share link

StreetHawk Growth feature lets your user share your application with friends. Also the feature can be extended to invite the new user to a deeplinking page inside your application. Create a Share button inside your application and call originateShareWithCampaign to generate the share url. App can get the generated url and share by any way ie (email, post on Facebook etc). A scheme for deep linking is required for StreetHawk growth. Refer Deeplinking section to configure deep linking for your application.

  • Generate share link and handle in application

In this case, SDK fetches the share link and pass it to application to present it to user for sharing it. Below is the sample code.

NSString *ID = @"ShareViaFacebook"
NSString *shareLink = @"recipeApp://homepage?recipe=chocolatechipcookie";
NSString *utm_source = @"Facebook";
NSString *utm_medium = @"cpc";
NSString *utm_term = @"facebookAdd";
NSString *campaign_content = @"best chocolate chip cookie recipe";
NSString *default_url = @"http://recipeApp.com/chocolatechipcookie";
[StreetHawk originateShareWithCampaign:ID withSource:utm_source withMedium:utm_medium  
withContent:campaign_content withTerm:utm_term 
shareUrl:[NSURL URLWithString:shareLink] 
withDestinationUrl:[NSURL URLWithString:default_url] 
streetHawkGrowth_object:^(NSObject *result, NSError *error)
    {
        presentErrorAlert(error, YES);
        if (error == nil)
        {
            dispatch_async(dispatch_get_main_queue(), ^
               {
                   NSString *shareUrl = (NSString *)result;
                   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share_guid_url" message:shareUrl delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
                   [alert show];
               });
        }
    }];
  • Generate link with source selection

In this case the SDK presents user with list of applications (Email, SMS, Facebook, Twitter, Sina Weibo, Tencent Weibo) on which the URL can be shared and picks utm_source parameter as per the user's selection. Below is the sample code.

NSString *ID = @"ShareViaFacebook"
NSString *shareLink = @"recipeApp://homepage?recipe=chocolatechipcookie";
NSString *utm_medium = @"cpc";
NSString *utm_term = @"facebookAdd";
NSString *campaign_content = @"best chocolate chip cookie recipe";
NSString *default_url = @"http://recipeApp.com/chocolatechipcookie";
[StreetHawk originateShareWithCampaign:ID withMedium:utm_medium 
withContent:campaign_content withTerm:utm_term 
shareUrl:[NSURL URLWithString:shareLink]
 withDestinationUrl:[NSURL URLWithString:default_url] 
withMessage:@"This is the best chocolate!"];
Parameter Data type Description
utm_campaign NSString Optional, for identify how this share is used for. For example in a book App, it would be "Child", "Computer", "Poetry".
utm_source NSString Optional, indicate where share url will be posted (Example facebook, twitter, whatsapp etc). It's free text string.
utm_medium NSString Optional, medium as url will be posted. For example cpc.
utm_content NSString Optional, content of campaign.
utm_term NSString Optional, keywords for campaing.
shareUrl NSURL Optional, deeplinking url which will open App by browser link. For example, to open App page with parameter, url like "SCHEME://HOST?param1=VALUE1&param2=VALUE2".
default_url NSURL Optional, fallback url if user opens url not on iOS or Android mobile devices. It's a normal url to display on browser, for example the developer's website which describes the App, like http://www.myapp.com.
handler SHCallbackHandler Share result callback handler, when successfully share `result` is share_guid_url, otherwise it contains error.
  • Handle shared deeplinking Url

App would like to handle the deeplinking Url by itself, not leverage StreetHawk SDK to automatically launch the page. In this case, implement following code snippet. It can handle any format of url by yourselves, like scheme://host/path?param1=value1&param2=value2.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...
    StreetHawk.openUrlHandler = ^(NSURL *openUrl)
    {
        //receive deeplinking url and do whatever you want
    };

    return YES;
}

Swift code:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
        ...
        SHApp.sharedInstance().openUrlHandler = { openUrl in
            let alertView = UIAlertView(title: "Open Url", message: openUrl?.absoluteString, delegate: nil, cancelButtonTitle: "OK")
            alertView.show()
        }
        return true
}

Implement the code snippet below to deep link into a Facebook page from your application.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...
    StreetHawk.openUrlHandler = ^(NSURL *openUrl)
    {
        [[UIApplication sharedApplication] openURL:openUrl];
    };

    return YES;
}

API document

Check here for API document.