Adding Google Analytics 4 and Google Tag Manager to Your Jekyll Blog
This guide will walk you through the process of setting up Google Analytics 4 (GA4) and Google Tag Manager (GTM) on your Jekyll blog to track visitor behavior, custom events, and optimize your content strategy.
Setting Up Google Analytics 4
Step 1: Create a Google Analytics Account
- Go to Google Analytics and sign in with your Google account
- Click “Start measuring”
- Enter an account name (this could be your name or company name)
- Configure your data sharing settings and click “Next”
Step 2: Set Up a Property
- Enter a property name (typically your blog name)
- Select your reporting time zone and currency
- Click “Show advanced options” if you want to create a Universal Analytics property alongside GA4
- Click “Next”
Step 3: Enter Business Information
- Select your industry category
- Select your business size and how you intend to use Google Analytics
- Click “Create”
Step 4: Set Up Data Collection
- Select “Web” as your platform
- Enter your website URL, stream name (usually your site name), and choose your enhanced measurement settings
- Click “Create stream”
- Take note of your Measurement ID (it looks like G-XXXXXXX)
Setting Up Google Tag Manager
Step 1: Create a Google Tag Manager Account
- Go to Google Tag Manager and sign in with your Google account
- Click “Create Account”
- Enter an account name and select your country
- Enter a container name (your blog name) and select “Web” as the target platform
- Click “Create” and accept the Terms of Service
Step 2: Get Your GTM Snippet
After creating your account and container, Google Tag Manager will provide you with two code snippets:
- A script to be placed in the
<head>of your HTML - A noscript fallback to be placed immediately after the opening
<body>tag
Copy these codes for later use.
Integrating with Jekyll
Method 1: Direct Implementation in Theme Files
Step 1: Add Google Analytics to Your Jekyll Site
- Open your Jekyll project and navigate to the
_includesfolder - Create or edit a file called
google-analytics.htmlwith the following content: