Guidelines and best practices

Caching bitly links

Since bitly links never change or expire, we recommend that publishers shorten long URLs on their back ends and cache the corresponding bitly short URLs for repeated use. When the short URL for a given page is stored locally, it can easily be shared using a number of cut-and-paste buttons and widgets.

Note that the JavaScript wrapper for the Tweet Button — and any similar solution that calls the bitly API on page load — is only recommended for smaller publishers, as larger publishers may encounter rate limiting issues. For more information on using the bitly API to shorten links on your site, visit https://dev.bitly.com/.

API Key Security

To ensure that the security of your API key is not compromised, we strongly recommend that all shorten requests are made server-side. If this is not possible, we recommend that you encrypt or otherwise obfuscate your API key within the source code of your page. Note that even encrypted API keys can be compromised when passed to our server via client-side code.

Link Wrapping on Twitter

Twitter’s link wrapper t.co is designed to invisibly wrap all links across all Twitter clients, while still displaying the exact URL that you share. T.co wrapping does not affect bitly’s analytics, and when t.co is working properly it should not impact your branding either. If you’re seeing t.co links in places where you aren’t expecting them, take a quick look at status.twitter.com or the @twitterAPI account on Twitter to see if there is a system-wide bug that is affecting the way that links are displayed on Twitter. If you are building your own tool or widget to display, for example, your company’s Twitter stream on your own website, be sure to follow the display guidelines provided by Twitter at http://bit.ly/vIyMnM.

Third party buttons and widgets

Twitter Tweet Button

bitly links can be shared via Twitter’s Tweet Button by using the “data-url” field to pass a given page’s bitly short link. The following code:

<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://bit.ly/9p0rrv" data-count="vertical">Tweet</a><script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>

… creates a button that shares this page’s bitly short link (http://bit.ly/9p0rrv):

Additional documentation for using and customizing this button is available here.

LinkedIn Share Button

bitly links can be shared via LinkedIn’s Share Button by using the “data-url” field to pass a given page’s bitly short link. The following code:

<script src="//platform.linkedin.com/in.js" type="text/javascript"></script> <script type="IN/Share" data-url="http://bit.ly/9p0rrv" data-counter="top"></script>

… creates a button that shares this page’s bitly short link (http://bit.ly/9p0rrv):

Additional documentation for using and customizing this button is available here.

Facebook Like Button

bitly links can be shared via Facebook’s Like Button by using the “href” parameter to pass a given page’s bitly short link (URL encoded). The following code:

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fbit.ly%2F9p0rrv&layout=standard&show_faces=false&width=450&action=like&colorscheme=light&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe>;

… creates a button that shares this page’s bitly short link (http://bit.ly/9p0rrv):

Additional documentation for using and customizing this button is available here.

AddThis Button

bitly links can be shared via the AddThis Button by using the “addthis:url” field to pass a given page’s bitly short link. The following code:

<script type="text/javascript">

var addthis_config = {

username: "xa-4b8f95c5449a2ffd"

}

</script>

<a href="http://www.addthis.com/bookmark.php?v=250"

class="addthis_button" addthis:url="http://bit.ly/9p0rrv"><img

src="http://s7.addthis.com/static/btn/v2/lg-share-en.gif"

width="125" height="16" border="0" alt="Share" /></a>

<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>

… creates a button that shares this page’s bitly short link (http://bit.ly/9p0rrv):

Note that this example passes a random hash (xa-4b8f95c5449a2ffd) as the AddThis username. If you have an AddThis account, you can replace this hash with your own AddThis username. Additional documentation for using and customizing this button is available here.

Reddit Button

bitly links can be shared via the Reddit Button by using the “reddit_url” variable to pass a given page’s bitly short link. The following code:

<script type="text/javascript">

reddit_url="http://bit.ly/9p0rrv";

reddit_newwindow=1;

</script>

<script type="text/javascript" src="http://reddit.com/static/button/button1.js"></script>

… creates a button that shares this page’s bitly short link (http://bit.ly/9p0rrv):

Additional documentation for using and customizing this button is available here.

Integration with blogging/publishing platforms

TypePad

TypePad integrates with bitly for sharing and metrics. See this page for more information.