Ghost Pixel Installation
Install the Ghost Pixel once, place it in your site template, and it will begin capturing visits automatically.
๐ Basic Installation
Add the Ghost Pixel script tag with your `data-site-id`.
HTML
<script defer src="https://analytics.ghostid.ai/api/script.js" data-site-id="YOUR_SITE_ID"></script>Place it in the `<head>` of your site whenever possible.
The `defer` attribute ensures the Ghost Pixel loads without blocking the page.
โ๏ธ Configuration Options
| Attribute | Default | Description |
|---|---|---|
| data-site-id | required | Your Ghost ID site identifier |
| data-namespace | ghost-id | Custom namespace for multi-instance setups |
๐งฉ JavaScript API
Use these methods to attach identity and custom actions to the current visitor session.
GHOST.identify(email, traits)
JavaScript
GHOST.identify("user@example.com", {
name: "Jane Smith",
plan: "pro"
});GHOST.track(event, props)
JavaScript
GHOST.track("cta_clicked", {
location: "pricing_hero",
variant: "B"
});๐ Privacy & Opt-Out
Users can opt out locally with:
JavaScript
localStorage.setItem("disable-ghost-id", "1")Or globally with:
JavaScript
window.__GHOSTID_OPTOUT__ = trueโ ๏ธ
When opted out, all Ghost Pixel tracking methods become no-ops.
๐งช Verifying Installation
JavaScript
// Check if Ghost Pixel is loaded
console.log(window.GHOST); // Should show the API object
console.log(GHOST.getVisitorId()); // Should return a visitor ID like "gv_abc12345_xyz98765"