Nithin Bekal About

Jekyll: Skip analytics scripts in development

27 Jul 2023

When updating this site, I was looking for a way to skip rendering some scripts locally. For example, you might not want Google Analytics to record every local page visit you make when proofreading a post, or hide the Disqus comments section.

Jekyll exposes the environment that it is running in via jekyll.environment. This means that you can skip these scripts locally by doing something like this:

{% if jekyll.environment == "production" %}
  <!-- script goes here -->
{% endif %}

If you’re using Github Pages, the environment is already set as production for you. However, if you are compiling it for production yourself, you can set the JEKYLL_ENV environment variable when running jekyll build.

JEKYLL_ENV=production jekyll build
Hi, I’m Nithin! This is my blog about programming. Ruby is my programming language of choice and the topic of most of my articles here, but I occasionally also write about Elixir, and sometimes about the books I read. You can use the atom feed if you wish to subscribe to this blog or follow me on Mastodon.