Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A Jekyll plugin that downloads Google Analytics data for each post and enables sorting by pageviews or visits.
jekyll-ga is an open-source Jekyll plugin that downloads Google Analytics data and attaches the configured metric to every post's metadata as post._ga, enabling popularity-based sorting and display in any Jekyll site.
jekyll-ga is a Jekyll plugin that connects to the Google Analytics API, retrieves a single metric over a configurable date range, and stores that value on each post's metadata. It requires a Google Analytics service account, a private key file, and a profile ID, all specified in a jekyll_ga block in _config.yml. The plugin runs during the Jekyll build process, and the resulting post._ga value can be printed in Liquid templates or used to reorder posts. It is distributed as a single Ruby file named jekyll-ga.rb that is copied into a site's /_plugins/ directory, and it depends on the chronic and google-api-client Ruby gems.
post._ga on every post, ready to be rendered in Liquid templates.sort: true orders posts by the metric value first and then reverse-chronologically, replacing the default date ordering.start and end are parsed by the Chronic gem, accepting natural phrases like now, yesterday, last month, or 2 weeks ago.ga:pageviews or ga:visits) can be used, with the dimension always set to ga:pagePath.segment and filters parameters can be added to the API request to narrow down the data.sort is disabled, the _ga metric can be used with the Jekyll-Sort plugin to build a separate site.posts_popular collection.jekyll_ga block in _config.yml, covering credentials, profile, date range, metric, and sort options.ga:pageviews and output them as a site.posts_popular list using Jekyll-Sort, while keeping the main blog in chronological order.post._ga in a template to display the metric beside titles, tags, or excerpts.segment and filters keys to analyze a subset of traffic, such as a specific channel or landing page.The plugin runs inside the Jekyll build and requires a Google Analytics service account. Setup involves installing the chronic and google-api-client gems, copying jekyll-ga.rb into /_plugins/, creating a service account in the Google API console, downloading the private key, and adding the service account email as a user in Google Analytics. After filling in the jekyll_ga configuration block in _config.yml, the plugin queries the Analytics API with the specified profile ID, date range, metric, and optional filters, assigns the response value to each matching post path, and attaches it as _ga.
ga:pagePath.Go to the Google Analytics report page and look at the URL. The number after the p near the end of the URL is the profileID you add to the jekyll_ga configuration block.
You can use any single Google Analytics metric, such as ga:pageviews or ga:visits. The dimension is always ga:pagePath. Google's Query Explorer is recommended for experimenting with available metrics.
The plugin is only tested with Jekyll 0.12.0 and Ruby 1.8.7, and compatibility with other versions is not guaranteed, though it may work.
Yes. Set sort: false in the jekyll_ga configuration and define a Jekyll-Sort rule that sorts posts by the _ga key, creating a separate site.posts_popular list.
