Jekyll: Skip analytics scripts in development
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
Tags: jekyll