Source: https://datafa.st/docs/attribution-guide-with-ghost
Markdown source: https://datafa.st/docs/attribution-guide-with-ghost.md
Description: Set up revenue attribution when using DataFast with Ghost CMS. Track membership subscriptions and paid content revenue.

# Attribute revenue with Ghost

← [Revenue attribution guide](/docs/revenue-attribution-guide)

# Attribute revenue with Ghost

> Make sure you've [added DataFast tracking](/docs/ghost-cms) to your Ghost site and [connected your Stripe account](/docs/connect-payment-provider) first.

### 1. Access Ghost Code Injection

1. Log in to your Ghost admin dashboard
2. Go to **Settings** > **Code Injection**
3. This is where you'll add the tracking code

### 2. Add the DataFast tracking code

Paste this JavaScript code in the **Site Header** section:

```html
<script id="datafast-queue">
  window.datafast = window.datafast || function() {
    window.datafast.q = window.datafast.q || [];
    window.datafast.q.push(arguments);
  };
</script>
<script>
try {
  // Track successful member signups and payments
  document.addEventListener('DOMContentLoaded', function() {
    // Check if this is a successful signup/payment page
    if (window.location.href.includes('success') || 
        window.location.href.includes('welcome') ||
        document.querySelector('[data-members-success]') ||
        document.querySelector('.gh-portal-success')) {
      
      // Try to 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.datafast("payment", { email: memberEmail });
      }
    }
    
    // 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("DataFast tracking error:", e);
}
</script>
```

### 3. Save the settings

Click **Save** to apply the code injection.

## Alternative: Use Zapier (No-code option)

For non-technical users, you can use Zapier to connect Ghost and DataFast:

1. Create a Zapier account
2. Set up a "Ghost Member Created" trigger
3. Connect it to [DataFast's Payment API](/docs/api-create-payment) action
4. Map the member email to track revenue attribution

This requires no coding and automatically tracks new member signups.

> After a successful membership signup, you should see revenue data in your DataFast dashboard.
