Skip to content

Ghost Google Analytics — Analytics Settings and Custom Code Injection

DodaTech Updated 2026-06-28 8 min read

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

  1. Go to analytics.google.com and create an account if needed.
  2. Create a new property for your Ghost site.
  3. Get your Measurement ID (starts with G-) or tracking code snippet.

Step 2: Open Ghost Code Injection

  1. Go to Settings > Code Injection.
  2. 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>
  • 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

  1. Save the code injection.
  2. Load your site in a browser.
  3. Open Developer Tools > Network tab.
  4. Look for requests to google-analytics.com or googletagmanager.com.
  5. Alternatively, use the Google Tag Assistant browser extension.

Code Injection Areas

Ghost provides four code injection areas:

<!-- 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)
<!-- 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>
    </>
  );
}

If you use Google Analytics, you need cookie consent for GDPR Compliance (EU visitors).

  • 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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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

  1. 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.

  2. 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).

  3. 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.

  4. 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

Will code injection slow down my Ghost site?

Code injection adds scripts that must be downloaded and executed. Keep injected code minimal. Use async or defer attributes on script tags. A single analytics script has negligible impact; dozens of scripts can slow down your site.

Can I use different analytics scripts on different pages?

Ghost's code injection applies to all pages or all posts. For per-page differences, use the Post Header/Footer sections with conditional logic in JavaScript, or use Google Tag Manager with triggers based on URL or page type.

Does Ghost have its own analytics feature?

Yes. Ghost provides built-in analytics for member growth, email open/click rates, top content, and per-member engagement. These are available in the Dashboard and do not require any third-party service.

How do I track conversions (member signups) in Google Analytics?

Add event tracking to the Portal signup button. Use JavaScript to listen for clicks on [data-portal] elements and fire a Google Analytics event. Mark these as conversions in your Google Analytics property.

Can I use Ghost without any analytics?

Yes. Analytics are optional. Ghost works perfectly without any tracking scripts. Some users prefer this for privacy-focused sites. You will still have Ghost's built-in member analytics.

Mini Project

Your task: Set up a complete analytics stack for a Ghost site.

  1. Create a Google Analytics 4 property for your site.
  2. Add the GA4 tracking code to Ghost Site Footer.
  3. Verify the tracking code fires using browser developer tools or Google Tag Assistant.
  4. Set up Google Search Console and link it to Google Analytics.
  5. Configure IP filtering to exclude your own traffic.
  6. Create a custom event in Google Analytics to track member signups.
  7. 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:

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro