Jekyll
Integrate analytics-tube Analytics with your Jekyll static site using layout files or includes
Integrating analytics-tube Analytics with your Jekyll static site involves adding the tracking script to your site's main layout file or by creating an include file.
Get Your Tracking Script
First, you'll need your analytics-tube tracking script. You can find this in your analytics-tube dashboard under Site Settings > Tracking Code. It will look something like this:
<script async defer src="https://app.analytics.tube/api/script.js" data-site-id="YOUR_SITE_ID"></script>Replace YOUR_SITE_ID with your actual Site ID from your analytics-tube dashboard.
Option A: Add to Default Layout
The simplest way is to add the script directly to your default layout file.
Locate your main layout file
In your Jekyll project, find your main layout file. This is often _layouts/default.html.
Add the tracking script
Open this file and paste the analytics-tube tracking script just before the closing </body> tag.
{{ site.title }}
{{ content }}
<!-- Other footer content -->
<!-- analytics-tube Analytics Script -->
{% if jekyll.environment == "production" %}
<script async defer src="https://app.analytics.tube/api/script.js" data-site-id="YOUR_SITE_ID"></script>
{% endif %}
</body>
</html>Explanation:
{% if jekyll.environment == "production" %}: This Liquid tag condition ensures the script is only included when your site is built for production (e.g., whenJEKYLL_ENV=production jekyll build). This prevents tracking your local development views.- Replace
YOUR_SITE_IDwith your actual Site ID. The script sourcehttps://app.analytics.tube/api/script.jsis for the standard cloud-hosted analytics-tube instance.
Option B: Create an Include File (Recommended)
A cleaner approach is to create an include file for the script.
Create the Include File
- In your Jekyll project, navigate to the
_includes/directory. If it doesn't exist, create it. - Create a new file named
analytics-tube-analytics.html(or similar) inside_includes/. - Paste the following into
_includes/analytics-tube-analytics.html:
{% comment %} _includes/analytics-tube-analytics.html {% endcomment %}
{% if jekyll.environment == "production" and site.analytics-tube_site_id %}
<script async defer src="{{ site.analytics-tube_instance_url | default: 'https://app.analytics.tube' }}/api/script.js" data-site-id="{{ site.analytics-tube_site_id }}"></script>
{% endif %}Include in Layout
- Open your main layout file (e.g.,
_layouts/default.html). - Just before the closing
</body>tag, add:
{{ site.title }}
{{ content }}
<!-- Other footer content -->
{% include analytics-tube-analytics.html %}
</body>
</html>Configure _config.yml
- Open your
_config.ymlfile and add your analytics-tube details:
# analytics-tube Analytics Configuration
analytics-tube_instance_url: "https://app.analytics.tube" # Optional, defaults in include
analytics-tube_site_id: "YOUR_SITE_ID"This method keeps your credentials in the configuration file and makes the script inclusion conditional on analytics-tube_site_id being set.
Build and Deploy
Build your Jekyll site
Build your Jekyll site. For production, set the JEKYLL_ENV environment variable:
JEKYLL_ENV=production jekyll buildOr, if you use GitHub Pages, it typically sets jekyll.environment to production automatically during its build process.
Deploy
Deploy the generated _site/ directory to your web server.
Verify Integration
- Open your live Jekyll website in a browser.
- Navigate through a few pages.
- Check your analytics-tube dashboard for incoming data. It might take a few minutes for the first events to appear.
That's it! analytics-tube Analytics is now integrated with your Jekyll site and will only track visits on your production deployment.