Background
⌘K

Ghost Integration

Complete guide to integrating Affonso with Ghost, including basic tracking and advanced member signup attribution

Silvestro
Written by Silvestro
Updated more than a month ago

Ghost's code injection feature makes it simple to add tracking scripts globally across your entire website or blog, perfect for SaaS companies using Ghost for their content marketing and knowledge base.

Add tracking script to your Ghost site

Ghost's recommended approach is to use the site-wide code injection settings, which applies the script to all pages automatically without needing to modify themes.

  1. Open your Ghost Admin panel

  2. Go to Settings → Code injection

  3. In the Site Header section, add your tracking script:

    <script
      async
      defer
      src="https://affonso.io/js/pixel.min.js"
      data-affonso="YOUR_PUBLIC_PROGRAM_ID"
      data-cookie_duration="YOUR_COOKIE_DURATION"
    ></script>
  4. Click Save

The script will automatically appear on all pages and start tracking affiliate referrals.

Track Member Signups (Optional)

If you're using Ghost's built-in membership features and want to track when referred visitors become members, add this enhanced tracking code to your Site Header:

<script
  async
  defer
  src="https://affonso.io/js/pixel.min.js"
  data-affonso="YOUR_PUBLIC_PROGRAM_ID"
  data-cookie_duration="YOUR_COOKIE_DURATION"
></script>

<script>
try {
  // Track successful member signups
  document.addEventListener('DOMContentLoaded', function() {
    // Check if this is a successful signup page
    if (window.location.href.includes('success') || 
        window.location.href.includes('welcome') ||
        document.querySelector('[data-members-success]') ||
        document.querySelector('.gh-portal-success')) {
      
      // Get member email from various sources
      const memberEmail = document.querySelector('[data-member-email]')?.textContent ||
                         document.querySelector('.member-email')?.textContent ||
                         localStorage.getItem('ghost_member_email');
      
      if (memberEmail && window.Affonso) {
        window.Affonso.signup(memberEmail.trim());
      }
    }
    
    // Store member email when they sign up for future tracking
    const memberForms = document.querySelectorAll('[data-members-form]');
    memberForms.forEach(form => {
      form.addEventListener('submit', function(e) {
        const emailInput = form.querySelector('input[type="email"]');
        if (emailInput && emailInput.value) {
          localStorage.setItem('ghost_member_email', emailInput.value);
        }
      });
    });
  });
} catch (e) {
  console.error("Affonso tracking error:", e);
}
</script>

Note: This enhanced tracking automatically notifies affiliates when their referrals sign up for memberships.

For more details, see Ghost's official code injection documentation.

Find your Program ID →

Testing

  1. Visit your Ghost site with ?atp=test
  2. Check browser DevTools → Console → type window.affonso_referral
  3. Verify the script appears in your page source
  4. For enhanced tracking: Test a member signup and check your Affonso dashboard
  5. Check tracking in your Affonso dashboard

Note: Code injection changes apply immediately without needing to republish.

Multi-Domain Setup

If you're using Ghost only for your blog/content (e.g., blog.yourcompany.com) while your main application runs elsewhere (e.g., app.yourcompany.com), make sure to install the Affonso tracking script on both domains.

Affonso works seamlessly across subdomains - the same affiliate cookie will be shared between domains. See our multi-domain setup guide for more details on cross-domain tracking.

Next Steps

Once installed, you can access affiliate referral data and pass it to your payment provider. Connect your payment provider →

Was this article helpful?

If you still need help, our support team is here for you.

Contact Support
bg

Ready to Scale Your SaaS?

Affonso is the easiest way to launch your own affiliate program. We take care of the technical stuff, so you can focus on growing your business.