Adding Bitly Support for Jekyll with jekyll_bitly_next - Enhanced Link Tracking
For blog owners and web developers, understanding user interaction is key to optimizing the user experience.
One way to gain insights into user behavior is through link tracking, which records the number of clicks a particular link receives.
Services like Bit.ly not only provide link shortening but also track the number of clicks a link receives.
If you are using Jekyll for your blog or website, you can integrate Bit.ly’s link tracking feature directly using the jekyll_bitly_next plugin - a modern, actively maintained gem that provides seamless Bitly integration.
To begin with, add the jekyll_bitly_next plugin to your Gemfile:
gem 'jekyll_bitly_next'
Then run:
bundle install
Next, add the plugin to your _config.yml:
plugins:
- jekyll_bitly_next
Note: For older Jekyll versions, use gems: instead of plugins:.
Configuration
You can configure your Bitly token using either of these methods:
Method 1: Jekyll Config (for local development)
Add to your _config.yml:
bitly:
token: YOUR_BITLY_TOKEN
⚠️ Security Warning: Never commit your API token to public repositories. Consider using environment variables for production.
Method 2: Environment Variable (recommended for production)
Set the BITLY_TOKEN environment variable:
# Linux/macOS
export BITLY_TOKEN=YOUR_BITLY_API_TOKEN_HERE
Replace YOUR_BITLY_TOKEN with your Bitly token. Priority: Config file settings take precedence over environment variables.
Usage
Once configured, you can use the bitly filter to shorten and track your URLs:
Basic Usage
[Link text]({{ 'https://yourwebsite.com' | bitly }})
Advanced Examples
In blog posts:
---
layout: post
title: "My Awesome Post"
canonical_url: https://yourdomain.com/2025/10/awesome-post
---
Share this post: {{ page.canonical_url | bitly }}
In layouts:
<a href="{{ page.url | absolute_url | bitly }}" class="share-link">
Share on Twitter
</a>
Replace https://yourwebsite.com with the URL you want to shorten and track, and Link text with the text you want to display for the link.
Getting Your Bitly API Token
To obtain your Bitly API token:
- Log in to your Bitly account
- Navigate to https://app.bitly.com/settings/api/
- Generate a new API token
- Copy the token for use in your configuration
Features & Benefits
The jekyll_bitly_next plugin offers several advantages:
- 🚀 Simple Integration: Easy-to-use Liquid filter
- 🔐 Secure: Token management via config or environment variables
- 💾 Performance: Automatic caching of shortened URLs
- 🧪 Reliable: Fully tested and actively maintained
- 🎯 Zero hassle: Minimal configuration required
Conclusion
Congratulations! You’ve successfully added Bitly support to your Jekyll site using the modern jekyll_bitly_next plugin. This will allow you to track the click rates of your links, providing valuable insights into user interaction with your content. The plugin’s caching feature ensures your site remains fast while providing comprehensive link analytics.
Whether you’re running a personal blog or a corporate website, link tracking is an essential tool for understanding your audience and optimizing your content strategy.
Share on
X Facebook LinkedIn BlueskyComments are configured with provider: utterances, but are disabled in non-production environments.
