# Attribute revenue with Ghost

> Credit paid Ghost memberships to the visits that brought the member, through Stripe.

Source: https://metricraven.com/docs/attribution-guide-with-ghost  
Markdown: https://metricraven.com/docs/attribution-guide-with-ghost.md  
Section: Revenue

Ghost sells paid memberships through your Stripe account. Its checkout can't carry the visitor ID, but the member's email can link the Stripe payment to the visit.

> **Note:** First [install MetricRaven on Ghost](https://metricraven.com/docs/install-ghost) and [connect the Stripe account Ghost uses](https://metricraven.com/docs/stripe).

## Add the code with Code injection

1. **Open Settings → Advanced → Code injection**

   In Ghost Admin, open **Code injection** and choose **Site header**.

2. **Paste this code below the MetricRaven tag**

   ```html title="Site header"
   <script>
     window.metricraven = window.metricraven || { q: [] };
     window.metricraven.payment = window.metricraven.payment || function () {
       window.metricraven.q.push(["payment"].concat([].slice.call(arguments)));
     };
   </script>
   <script>
     document.addEventListener("DOMContentLoaded", function () {
       try {
         // Remember the email a visitor signs up with (Ghost's member forms and Portal).
         document.querySelectorAll("[data-members-form]").forEach(function (form) {
           form.addEventListener("submit", function () {
             var input = form.querySelector('input[type="email"]');
             if (input && input.value) sessionStorage.setItem("mr_member_email", input.value);
           });
         });
         // Ghost returns from a paid Stripe checkout with ?stripe=success.
         var params = new URLSearchParams(window.location.search);
         var email = sessionStorage.getItem("mr_member_email");
         if (params.get("stripe") === "success" && email) {
           window.metricraven.payment({ email: email });
           sessionStorage.removeItem("mr_member_email");
         }
       } catch (e) {
         console.error("MetricRaven payment tracking error:", e);
       }
     });
   </script>
   ```

   It keeps the email typed into a member form for this tab only, and sends it once Ghost returns from Stripe with `?stripe=success`.

3. **Save**

   Members who upgrade while signed in pay with their account email, which is the one sent.

> **Verify it works**
>
> Sign up for a paid tier in a private window. Once Stripe sync imports the payment (about a minute), it appears in **Revenue** credited to that visit's source.

## Without code

You can also send paid members from your own backend or an automation (for example a Zapier “new member” trigger) to the [Payments API](https://metricraven.com/docs/payments-api) with their `email`. Don't do this as well as connecting Stripe, or payments count twice.

## Notes

- Free members aren't revenue. Track free signups as a goal instead.
- Renewals keep the same visit through the Stripe customer.
- Matching rules, privacy and the security model: [Attribute by email](https://metricraven.com/docs/attribute-by-email).
