For a content-heavy site like the new healthcare.gov, surfacing popular content gets the most interesting information to readers quickly. To make this possible with static sites generated with Jekyll, we're releasing the new jekyll-ga plugin that gets the latest Google Analytics data when Jekyll builds the site, making it available to use for sorting and in templates.
By default Jekyll sorts content posts chronologically and alphabetically. This works well for blogs, but now with
jekyll-ga, we have many more options. Any metric you can track in Google Analytics — including custom variables — can be used to sort content or as a variable in our Liquid templates.
Using the plugin
Jekyll has a plugin system thats allows for dropping in custom code written in Ruby to generate or modify content. Any
.rb files in the
/_plugins directory get run at site build time.
Full instructions for setting up jekyll-ga are in the readme file, but here's the basic idea. By adding some configuration information into the
_config.yml file for a Jekyll site, you can define a custom report to query from Google Analytics. You can specify any metric you want, and the date range for the report using absolute dates or several relative date formats such as
last week, and
three months ago. Optionally, you can apply filters or segments to your reports based on settings you configure in Google Analytics. Here's how it all looks:
jekyll_ga: service_account_email: # service account email address key_file: privatekey.p12 # service account private key file key_secret: notasecret # service account private key's password profileID: ga:#### # profile ID start: last month # Beginning of report end: now # End of report metric: ga:pageviews # Metric code segment: # optional filters: # optional sort: true # Sort posts by this metric
jekyll-ga with jekyll-sort let's you have content sorted in multiple lists, such as preserving the default chronological sorting of
site.posts content lists, while also adding in a
We're developing healthcare.gov as a CMS-free Jekyll website in tandem with a new release of Prose, the online editor for Jekyll and GitHub. Stay tuned for more updates on both in the next few days, including a simple web server that lets you run your own on-premises GitHub Pages-like hosting service.