Handling App Store and LinkShare Links

One of the perks of being part of the App Treasures label is that we get some nice cross-promotion with an in-game view to display other titles in the label. This list is, of course, stored in our server and pulled in through a standard UIWebView. It links to other pages with details for each of our games, and a link to buy it directly from the App Store. Everything is really straightforward, except for the App Store link.

AppTreasuresWebView

By default, the UIWebView will try to open the App Store link itself, which results in an error. What we want to do instead is intercept the request and launch it directly with an NSURLConnection so the call can be redirected to the iPhone App Store app. The best place to implement this is in the -[UIWebViewDelegate webView:shouldStartLoadWithRequest:navigationType:] method:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    if ([[[request URL] host] isEqualToString:@"phobos.apple.com"])
    {
        NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[request URL]] delegate:self startImmediately:YES];
        [conn release];
        return NO;
    }
    return YES;
}

While we’re in the topic of links, I also recently added some LinkShare links to my apps. The 5% kickback for each purchase is nice, but the tracking capabilities it gives you is the real reason I wanted to use it. The way LinkShare works is by providing a custom URL that contains your referral ID to allow LinkShare to track the transaction. Unfortunately, unlike the Amazon referral program for example, LinkShare is a third party company and is not tied directly into the App Store. That means the links they provide go through click.linksynergy.com and then are redirected to the App Store. The result is that trying to follow one of those links from your app will result in Safari coming up, opening up a new page, shutting down, and then opening the App Store app. Not pretty!

Fortunately, there’s a workaround. Just like we did with the App Store links, we can open the LinkShare link directly with a NSURLConnection instead of letting Safari handle it. Then, once the link resolves to the forwarded one, we can open it directly with the App Store app:

- (IBAction)buyItNow
{
    NSString* link = @"http://click.linksynergy.com/fs-bin/click?........";
    NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:link]] delegate:self startImmediately:YES];
    [conn release];    
}

- (NSURLRequest*)connection:(NSURLConnection*)connection willSendRequest:(NSURLRequest*)request redirectResponse:(NSURLResponse*)response
{
    m_iTunesURL = [response URL];
    return request;
}

- (void)connectionDidFinishLoading:(NSURLConnection*)connection
{
    [[UIApplication sharedApplication] openURL:m_iTunesURL];
}

Voila! The user goes directly to the App Store page, there are no annoying Safari transitions, and you still get the referral bonus.

Incidentally, most of this is already documented in an Apple Technical Q&A note, but it’s kind of hidden away and I think most people don’t know about it.

If you’re using LinkShare, you should also check out this post at Mobile Orchard. One of the things I learned there was the use of the &u1 parameter, which allows you to tag links with arbitrary information so you can track where purchases came from. Knowing where people are buying your app from is extremely helpful to know how to maximize sales!

[Edit: Sam Steele pointed me to the source code for the Last.fm app which handles all the URL redirects. Thanks!]

  • http://acornheroes.com George Sealy

    Nice post Noel.

    It’s this sort of technical detail that I really like to see in articles. Nice change to the layout of your site, too. How did you find the theme? Do you just browse randomly, or is there a cleverer way to find them?

  • http://gamesfromwithin.com Noel

    Glad you found the article useful, George.

    As for the layout, it was pretty much random. I had browsed a bunch of those “Top 10 blah blah blah themes” but nothing stood out. Then I saw another blog with a format I really liked and it was a modified Hamaski theme. I spent a couple of hours massaging it and it was ready to go.

  • http://blog.mundue.net Matt Martel

    Noel, this is good stuff. Here’s an interesting tidbit you may not be aware of.

    Keep in mind that if you use the u1 signature parameter for Linkshare, it tracks ALL purchases made from that referral, not just conversions on your app. You might be able to correlate a referral to a conversion, based on price, etc, but it’s not obvious from the Linkshare reports what the user actually purchased.

    -Matt

  • http://gamesfromwithin.com Noel

    Yes, I learned that recently from reading my reports, and it was really surprising. The LinkShare reports are a mess. So hard to tell what’s going on. Still, I suppose it’s better than nothing, and the 5% never hurts :-b

  • http://twitter.com/okaniel Oren Kaniel

    Stop the guess work! With http://www.AppsFlyer.com you can track these installations and in-app engagement!