Ghost Google Analytics — Analytics Settings and Custom Code Injection
In this tutorial, you'll learn how to add Google Analytics to your Ghost site using code injection, understand Ghost's built-in analytics for members and email, and configure custom tracking scripts for advanced analytics.
What You'll Learn
- Ghost's built-in analytics: members, email, content performance
- Adding Google Analytics via code injection
- Adding Google Tag Manager via code injection
- Understanding the four code injection areas
- Custom analytics scripts and event tracking
- Privacy considerations and cookie consent
- Analytics for headless Ghost sites
- Interpreting analytics data for content decisions
Why It Matters
Data drives content decisions. Without analytics, you are guessing what content resonates with your audience. Ghost provides built-in analytics for member engagement and email performance, but for full traffic analysis — page views, user behavior, acquisition channels, conversion funnels — you need Google Analytics or a similar platform. Ghost's code injection makes adding tracking straightforward.
Real-World Use
A content creator uses Ghost's built-in analytics to see which posts have the highest member engagement (opens, clicks). She uses Google Analytics (added via code injection) to see which traffic sources drive the most signups. She discovers that posts shared on LinkedIn have a 40% higher conversion rate to paid members than Twitter posts. She adjusts her promotion strategy accordingly.
Learning Path
flowchart LR A["Sitemaps & Robots"] --> B["Google Analytics
You are here"]:::current B --> C["Structured Data"] C --> D["Performance Optimization"] classDef current fill:#38bdf8,color:#0f172a,stroke-width:2px
Ghost's Built-in Analytics
Ghost provides analytics for members and email directly in the admin panel.
Dashboard Analytics
- Total members: Current member count
- Paid members: Active paid subscribers
- Member growth: Chart over time
- Email open rate: Average across all newsletters
- Email click rate: Average across all newsletters
- Top posts: Most-viewed content
Per-Post Analytics
For each post sent as a newsletter:
- Sent: Total emails sent
- Opened: Unique opens and open rate
- Clicked: Unique clicks and click rate
- Unsubscribed: Members who unsubscribed after this email
Member-Level Analytics
For each member:
- Email opens: Total opens
- Email clicks: Total clicks
- Last opened: Date of last open
- Last seen: Last site visit
- Activity timeline: Posts viewed, emails opened, subscription changes
Adding Google Analytics via Code Injection
Step 1: Get Your Google Analytics Tag
- Go to
analytics.google.comand create an account if needed. - Create a new property for your Ghost site.
- Get your Measurement ID (starts with
G-) or tracking code snippet.
Step 2: Open Ghost Code Injection
- Go to
Settings > Code Injection. - You see four text areas.
Step 3: Add the Tracking Code
Paste the Google Analytics tag in the Site Footer section:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
Why Site Footer?
- Ghost loads the footer scripts after the main content
- Analytics scripts are non-blocking — they should not delay page rendering
- The footer is the last thing rendered, ensuring the page is loaded before tracking
Step 4: Verify Tracking
- Save the code injection.
- Load your site in a browser.
- Open Developer Tools > Network tab.
- Look for requests to
google-analytics.comorgoogletagmanager.com. - Alternatively, use the Google Tag Assistant browser extension.
Code Injection Areas
Ghost provides four code injection areas:
Site Header
<!-- Added to <head> on EVERY page -->
Use for:
- Font loading (preconnect, preload)
- SEO meta tags
- Schema markup (global)
- Verification meta tags (Google Search Console, Bing Webmaster)
Site Footer
<!-- Added before </body> on EVERY page -->
Use for:
- Analytics scripts (Google Analytics, Plausible, Fathom)
- Chat widgets (Intercom, Crisp)
- Custom JavaScript (tracking, heatmaps)
- Retargeting pixels
Post Header
<!-- Added to <head> on POSTS and PAGES -->
Use for:
- Per-post schema markup (Recipe, FAQ, Product)
- Per-post custom CSS
- Post-specific OG meta tags (as override)
Post Footer
<!-- Added before </body> on POSTS and PAGES -->
Use for:
- Per-post call-to-action scripts
- Post-specific JavaScript
Google Tag Manager
If you use multiple analytics/ marketing tools, use Google Tag Manager instead of individual scripts.
Adding GTM
In Site Header:
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->
In Site Footer (for noscript fallback):
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
Other Analytics Options
Plausible Analytics
Privacy-focused, lightweight alternative:
<script defer data-domain="yoursite.com" src="https://plausible.io/js/script.js"></script>
Fathom Analytics
Another privacy-first option:
<script src="https://cdn.usefathom.com/script.js" data-site="YOUR_CODE" defer></script>
Simple Analytics
<script async defer src="https://scripts.simpleanalyticscdn.com/latest.js"></script>
<noscript><img src="https://queue.simpleanalyticscdn.com/noscript.gif" alt="" /></noscript>
Event Tracking
For tracking specific user actions (clicks, signups, downloads), add custom event tracking:
<script>
document.addEventListener('click', function(e) {
// Track newsletter signup button clicks
if (e.target.matches('[data-portal="signup"]')) {
gtag('event', 'signup_click', {
'event_category': 'engagement',
'event_label': 'newsletter_signup'
});
}
// Track external link clicks
if (e.target.matches('a[href^="http"]:not([href*="mysite.com"])')) {
gtag('event', 'click', {
'event_category': 'external_link',
'event_label': e.target.href
});
}
});
</script>
Analytics for Headless Ghost
In headless mode, add analytics to your frontend application, not to Ghost's code injection.
Next.js with Google Analytics
// components/GoogleAnalytics.js
import Script from 'next/script';
export default function GoogleAnalytics() {
return (
<>
<Script
src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
`}
</Script>
</>
);
}
Privacy and Cookie Consent
If you use Google Analytics, you need cookie consent for GDPR Compliance (EU visitors).
Cookie Consent Solutions
- Cookiebot: Full-featured consent management
- Osano: Simple consent banner
- Custom: Build your own with localStorage
Add the consent banner script in Site Footer:
<script
type="text/javascript"
id="cookiebot"
src="https://consent.cookiebot.com/uc.js"
data-cbid="YOUR_COOKIEBOT_ID"
data-blockingmode="auto"
defer>
</script>
Common Mistakes
Putting analytics in the Site Header instead of Footer: Analytics scripts should load after the page content. Placing them in the header can block rendering. Always use Site Footer for analytics. Use Site Header only for preload/preconnect tags.
Adding multiple analytics scripts from different providers without a tag manager: Each analytics script adds HTTP requests and processing time. Consolidate through Google Tag Manager or choose one primary analytics platform.
Not excluding your own traffic: Your visits inflate analytics. Set up IP filtering in Google Analytics to exclude your own IP address. Alternatively, use a browser extension like Ghostery to block analytics on your own site.
Forgetting to add analytics to headless frontend: If you use Ghost headless, code injection in Ghost admin does not affect your frontend. Add analytics scripts to your frontend app directly.
Ignoring Ghost's built-in analytics: Google Analytics gives you traffic data, but Ghost's built-in analytics gives you member engagement data. Use both for a complete picture.
Practice Questions
Where should you add Google Analytics tracking code in Ghost, and why? Answer: In the Site Footer section of Code Injection. The footer loads after the main content, so analytics scripts do not block page rendering. Placing analytics in the header can negatively impact page load time.
What are the four code injection areas in Ghost and their use cases? Answer: Site Header (meta tags, font preload, verification tags), Site Footer (analytics, chat widgets, tracking scripts), Post Header (per-post schema, custom CSS), Post Footer (per-post JavaScript, CTAs).
How does Ghost's built-in member analytics differ from Google Analytics? Answer: Ghost's analytics track member-specific data: email opens/clicks, member growth, per-member activity timeline, and subscription status. Google Analytics tracks page views, traffic sources, user behavior, and conversion funnels. They complement each other.
Challenge: Set up complete analytics for a Ghost site. Add Google Analytics via code injection, verify the tracking code fires correctly, set up IP filtering to exclude your own traffic, configure a custom event to track newsletter signup button clicks, and create a Google Analytics dashboard showing the top 5 most-viewed posts and traffic sources.
FAQ
Mini Project
Your task: Set up a complete analytics stack for a Ghost site.
- Create a Google Analytics 4 property for your site.
- Add the GA4 tracking code to Ghost Site Footer.
- Verify the tracking code fires using browser developer tools or Google Tag Assistant.
- Set up Google Search Console and link it to Google Analytics.
- Configure IP filtering to exclude your own traffic.
- Create a custom event in Google Analytics to track member signups.
- Build a Google Analytics dashboard that shows page views, traffic sources, top content, and conversion events.
This exercise gives you a professional analytics setup for data-driven content decisions.
What's Next
Now that analytics are configured, learn about structured data:
Continue to Lesson 33: Structured Data — JSON-LD, article schema, FAQ schema, and Open Graph.
Related lessons:
- SEO Settings — Meta tags and social sharing
- Google Analytics — Traffic analysis
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro