- Convert MDX CodeBlock components to standard markdown code fences - Add rehype-mdx-code-props to pass filename meta to code components - Custom pre/code MDX components map fences to CodeBlock - Add brand color badges (product + category) matching /learn layout - Match prose styling: orange inline code, orange links, white strong - Remove brand color background glow (not in /learn)
57 lines
1.3 KiB
Plaintext
57 lines
1.3 KiB
Plaintext
---
|
|
title: "Gatsby"
|
|
description: "Add Pulse analytics to your Gatsby site using gatsby-ssr or the Gatsby Head API."
|
|
category: "ssg"
|
|
brandColor: "#663399"
|
|
officialUrl: "https://www.gatsbyjs.com/docs"
|
|
relatedIds: ["react", "nextjs", "hugo"]
|
|
date: "2026-03-28"
|
|
---
|
|
|
|
Use the Gatsby SSR API or the Gatsby Head API to add Pulse to your site.
|
|
|
|
---
|
|
|
|
## Method 1: gatsby-ssr.js
|
|
|
|
Use the `onRenderBody` hook to inject the Pulse script into every page's `<head>`.
|
|
|
|
```jsx filename="gatsby-ssr.js"
|
|
import React from "react"
|
|
|
|
export const onRenderBody = ({ setHeadComponents }) => {
|
|
setHeadComponents([
|
|
<script
|
|
key="pulse-analytics"
|
|
defer
|
|
data-domain="your-site.com"
|
|
src="https://pulse.ciphera.net/script.js"
|
|
/>,
|
|
])
|
|
}
|
|
```
|
|
|
|
## Method 2: Gatsby Head API (v4.19+)
|
|
|
|
If you're on Gatsby 4.19 or later, you can use the Head export in any page or template component.
|
|
|
|
```tsx filename="src/pages/index.tsx"
|
|
import React from "react"
|
|
|
|
export function Head() {
|
|
return (
|
|
<script
|
|
defer
|
|
data-domain="your-site.com"
|
|
src="https://pulse.ciphera.net/script.js"
|
|
/>
|
|
)
|
|
}
|
|
|
|
export default function IndexPage() {
|
|
return <h1>Hello World</h1>
|
|
}
|
|
```
|
|
|
|
For more details, see the [Gatsby Head API docs](https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-head/).
|