markjnet

Tweeting from an Ad on the iPhone Using URL Schemes

Lately I’ve been experimenting with promoting out app ‘Friend Focus (for Facebook)‘ by ‘turning out the vote’ – ie getting our existing users to help us promote Focus. Once I’ve found a formula that works well we’ll implement the scheme in app and figure out a way to reward users for helping us, but for now I’ve been using house ads. House ads are our own ads placed in our app using the ad network we’re integrated with. Admob in this case. This is a great way to try out ad copy and experiment with different promotions because its all done with no code updates to our app, all I have to make is a simple HTML landing page for each ad.

A recent campaign we’ve been running is ‘Tweet your support for Focus’, which asks people to tweet saying that Focus is great:

Tweet support for Focus ad

Tweet support landing page

Naturally the tweet has to be pre-filled, which lets me use a bit.ly link so I can track the effectiveness of the campaign. A ‘tweet me’ link is pretty easy on the web, but this is on people’s iphone. Twitter users with lots of followers (ie the people we want to tweet) aren’t using the twitter website on their iPhone, they’re using a twitter app, of which there are many to choose from! So how do we turn a click on my ad into a pre-filled tweet right inside someone’s pre-logged in twitter app of choice? The solution is to use custom URL schemes. Several iPhone twitter apps have custom url schemes that allow you to launch them and pre-fill a tweet using their custom url. This works just as well from the landing page of an admob, in code in a native app, in a web page in mobile safari, or a link in an email.

Hmmm, but which twitter app to choose? Turns out you can choose them all! I wrote some simple javascript to just open all of them – one of them is bound to hit. The code is below. I picked 5 of the most popular twitter clients and included them. The script works great in the UIWebView that Admob opens to show the landing page for the ad, because the UIWebView isn’t throwing up a dialog saying “couldn’t open that URL” for urls where a scheme isn’t installed on the devide. Its imperfect as a web page because of these alerts, which you will see if you try it. I tried a bunch of things – using the tweet url for an image src, in an iframe, as a form submit. I also played with timers and onblur event to try to cancel out the urls tries upon returning to the page in Safari. If someone could figure out the perfect javascript for this that works in Safari and post here in the comments, that would be very awesome.

Go ahead and try it by clicking the ad above, and if you tweet your support for Focus, that would be splendid! As you can see to the left, it works… we’ve had 28 tweets so far, from a variety of twitter apps, which has generated 165 click throughs to the Focus website. Thanks to everyone who tweeted for us so far. Below is my hastily put together javascript.

 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Tweet Focus Support</title>
 <meta name="viewport" content="width=300; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0" />
 
<script type="text/javascript">
var msg = "Get%20the%20best%20Facebook%20on%20%23iphone%20with%20Focus%20for%20Facebook%20http%3A%2F%2Fbit.ly%2FFocus4Facebook%20%40focusedapps%0A";
var tweetTry=0;
var tweetTryCancel=false;
var tweetTrys = new Array();
tweetTrys[0]="tweetie:///post?message="+msg;
tweetTrys[1]="twitterrific:///post?message="+msg;
tweetTrys[2]="echofon:///message?"+msg;
tweetTrys[3]="twit:///post?message="+msg;   //twitelator
tweetTrys[4]="x-birdfeed://post?text="+msg;
 
function tweetPress() {
	tweetTryTime=0;
	tweetTry=0;
	tweetTryCancel=false;
	tweet();
}
 
function tweet() {
//alert("tweet");
	if (tweetTryCancel) {
		alert("cancel");
		return;
	}
	var currentTime = (new Date()).getTime();
	if (tweetTryTime!=0) {
		var elapsedSinceLastTry = currentTime-tweetTryTime;
		//alert(elapsedSinceLastTry);
		if (elapsedSinceLastTry>400) {
		alert(elapsedSinceLastTry);
			tweetTryTime=0;
			tweetTry=0;
			tweetTryCancel=false;
			//alert("reset");
			return;
		}
	}
 
	tweetTryTime = currentTime;
 
	var url = tweetTrys[tweetTry++];
	if (tweetTry>5 || url==null) return;
	if (tweetTryCancel) return;
	//alert(url);
	if ("http:"==url.substr(0,5)) {
		window.location=url;
		window.setTimeout("tweet()",10);
		return;
	} else {
		//window.location=url;
		var obj = document.getElementById("if1");
		obj.src = url;
		window.setTimeout("tweet()",10);
		return;
	}
}
 
function onBlur() {
	tweetTryCancel = true;
};
 
 
window.onblur = onBlur;
 
</script>
</head>
<body>
<div style="margin-right: auto;margin-left: auto;width: 280px;background-color: #DFEFF5;padding: 5px;border: 3px solid #6080C0;"><center>
  <div align="center" class="style1">Tweet Your Support  </div>
  <p align="left">We need your help to spread the word about Focus for Facebook. If you use Twitter, please take a moment to...</p>
 
  <p align="center"><a href="" onclick="tweetPress(); return false;" }><img src="tweetSupportApp.png" alt="tweet support" width="245" height="41" /></a></p>
 
  <p align="center"><a href="http://clicktotweet.com/ha89H"><img src="tweetSupportWeb.png" alt="tweet support" width="245" height="41" /></a></p>
 
  <table width="219" height="94" border="0" align="center" cellpadding="2">
    <tr>
      <td height="15" colspan="3">&nbsp;</td>
    </tr>
    <tr>
      <td rowspan="2" align="left" valign="top"><img src="logo62.png" width="62" height="62" /></td>
      <td rowspan="2" align="left" valign="top">&nbsp;</td>
      <td height="5" align="left" valign="bottom">Thanks,</td>
    </tr>
    <tr>
      <td height="5" align="left" valign="top"><p>Mark &amp; Rob, Focused Apps.</p>
      </td>
    </tr>
  </table>
  <img src="" width="1" height="1" id="img1" /><img src="" width="1" height="1" id="t2" />
  <form id="form1" name="form1" method="get" action=""></form>
  <iframe id=if1 src ="" width="1" height="1"></iframe>
 
  </div>
</body>

[Slashdot] [Digg] [del.icio.us] [StumbleUpon]

Comments

4 Responses to “Tweeting from an Ad on the iPhone Using URL Schemes”

Trackbacks

Check out what others are saying about this post...
  1. [...] article entitled Tweeting From an Ad on the iPhone Using URL Schemes takes advantage of the fact that many twitter apps on the iPhone have their own custom URL Scheme. [...]

  2. [...] LogYourRun allows users to share their activities using both twitter and Facebook.  On the full site this is easily take care of by Facebook Connect as well as a direct link to Twitter.  On a mobile browser, particularly on the iPhone, most people will not be using the twitter website as their main twitter client – usually they will have one of the numerous twitter iPhone application.  Since a bunch of these actually respond to custom URL schemes the tweet can be sent directly to the Twitter app using some clever JavaScript as posted by Mark J. [...]



Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

  • Categories

  • markjnet