Google Analytics is a valuable tool for tracking the traffic and user behavior on your website. If you have a Jekyll website, you can easily add Google Analytics tracking by following these steps:
- Sign up for a Google Analytics account and create a new property for your website. You will be given a tracking code, which you will need to add to your Jekyll website.
- In your Jekyll website, create a new file in the
_includes
directory called g-analytics.html. This file will contain the tracking code that you will include in your website. - In the g-analytics.html file, paste the tracking code that you received from Google Analytics. The tracking code should look something like this:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_TRACKING_ID');
</script>
- Replace
GA_TRACKING_ID
with your actual tracking ID, which can be found in your Google Analytics account. - In your Jekyll website, open the html file that creates the head section of your website.
- Paste the following code.
{% include g-analytics.htl %}
This will insert the tracking code from the g-analytics.html file into all of your pages.
- Save the changes and push the changes to your website.
- That’s it! You have successfully added Google Analytics tracking to your Jekyll website. It may take a few hours for the tracking to start appearing in your Google Analytics account.
I hope this helps! Let me know if you have any questions.