# Install on Ghost

> Add MetricRaven to a Ghost site with Code injection, or in your theme.

Source: https://metricraven.com/docs/install-ghost  
Markdown: https://metricraven.com/docs/install-ghost.md  
Section: Installation guides

Ghost's site-wide Code injection adds the tag to the head of every page and post.

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

   In Ghost Admin, choose the gear icon, then find **Code injection** under **Advanced**.

2. **Paste the snippet into Site header**

   Replace `YOUR_SITE_ID` with the public site ID from your site's **Settings → Install** card. The site ID is public and safe in browser code; never put your secret key in a page.

   ```html title="Site header"
   <script
     defer
     src="https://metricraven.com/js/script.js"
     data-site-id="YOUR_SITE_ID"
   ></script>
   ```

   Use **Site header**, not **Site footer** or the code injection on a single post.

3. **Save and open your site**

   Open a page on your public domain in a private window.

> **Verify it works**
>
> Open your live website in a normal browser window (not an automated or embedded one). In the browser's Network panel, look for `script.js` and then a request to `/api/v1/collect` whose response contains `ok: true`. Open your site's **Traffic** tab and choose **Refresh**; the selected dates must include your visit.
>
> Nothing showing? See [Troubleshooting](https://metricraven.com/docs/troubleshooting).

## Alternative: add it to your theme

On a self-hosted Ghost, or a plan that allows custom themes, you can put the tag in your theme's `default.hbs` instead, before `{{ghost_head}}`. Re-add it when you switch or update the theme.

```xml title="default.hbs"
{{!-- default.hbs in your theme --}}
<head>
    ...
    <script defer src="https://metricraven.com/js/script.js" data-site-id="YOUR_SITE_ID"></script>
    {{ghost_head}}
</head>
```

## Notes

- Only hostnames listed in your site's **Settings → General → Site** domains (and their subdomains) are accepted. To also count visits on a platform address such as `your-site.ghost.io`, add it there; otherwise those requests are refused with `domain_not_allowed`.
- Your own visits to the public site count like anyone else's. To leave them out, see [Exclude your visits](https://metricraven.com/docs/exclude-visits).
- Pair it with `data-goal` attributes on your signup buttons to count member signups as goals.
- If you use a cookie banner, connect it with [Consent & visitor IDs](https://metricraven.com/docs/consent).

## Attribute sales

To credit Ghost sales to the visits that brought the buyer, connect Stripe and follow [Attribute revenue with Ghost](https://metricraven.com/docs/attribution-guide-with-ghost).

Optional script attributes are listed in [Install & verify](https://metricraven.com/docs/install). To exclude your own visits, see [Exclude your visits](https://metricraven.com/docs/exclude-visits).
