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.
-
Open your Ghost Admin panel
-
Go to Settings → Code injection
-
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>
-
Click Save
-
The script will automatically appear on all pages
Alternative: Use post-specific code injection by adding the script to individual posts in the post settings, or modify your Ghost theme directly.
For more details, see Ghost's official code injection documentation.
Testing
- Visit your Ghost site with
?atp=test
- Check browser DevTools → Console → type
window.affonso_referral
- Verify the script appears in your page source
- 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 →