# Add emoji reactions to a Gatsby site

> Add live emoji reactions to a Gatsby blog: the loader in gatsby-ssr.js, a floating bar in the blog-post template, an inline bar per post on the index keyed to fields.slug. No plugin, no backend.

A Gatsby site gets live emoji reactions from three edits: the loader in `gatsby-ssr.js`, a floating bar in your blog-post template, and an inline bar for each post on the index, keyed to `fields.slug`. No Gatsby plugin and no server — the bar loads in the reader's browser after your static build.

## Before you start

You need a Tapbar: the reactions, the look, and a publishable key (`pk_live_…`). [Sign up](https://app.tapback.party), create a Tapbar with your site as an allowed site (add `http://localhost:*` too, to try it on a dev server), and open its **Embed** panel — the loader tag there already carries your key. Your AI agent can do this part for you; see [the last section](https://docs.tapback.party/install/gatsby/#let-your-agent-do-it).

## Add the loader once

The loader goes in `gatsby-ssr.js` (`onRenderBody` → `setHeadComponents`), so it lands in every page's `<head>` at build. It defines the `<tapback-bar>` element and starts every bar on the page, however many there are:

```javascript
// gatsby-ssr.js — the starter's file is CommonJS and already sets lang; merge into it
const React = require("react")

exports.onRenderBody = ({ setHtmlAttributes, setHeadComponents }) => {
  setHtmlAttributes({ lang: `en` })
  setHeadComponents([
    <script key="tapback" type="module" async
      src="https://api.tapback.party/loader.js"
      data-key="pk_live_…" data-api="https://api.tapback.party" />,
  ])
}
```

Swap `pk_live_…` for your own key, or paste the tag from the Embed panel as it is.

## Put a floating bar on each post

In `src/templates/blog-post.js`, add one bar with `layout="float"`, keyed to the same `fields.slug`. It docks in the bottom corner wherever it sits in the markup, and it connects live, so readers see each other's reactions fall.

```jsx
// src/templates/blog-post.js
<tapback-bar entity={post.fields.slug} layout="float" />
```

## Add an inline bar to each post in the list

In `src/pages/index.js`, give every post its own bar, keyed to `node.fields.slug`:

```jsx
// src/pages/index.js
{posts.map((post) => (
  <article key={post.fields.slug}>
    <h2><Link to={post.fields.slug}>{post.frontmatter.title}</Link></h2>
    <p>{post.excerpt}</p>
    <tapback-bar entity={post.fields.slug} layout="inline" live="off" />
  </article>
))}
```

`entity` names the counter. On a list page it has to be set by hand: a bar without it infers the list page's own URL, so every blurb would share one tally. Emit the same value the post page uses and a reaction on the blurb lands on the same count as one on the post.

`live="off"` shows each blurb's count without opening a live socket for it; the falling reactions stay on the post page. Bars that load together share one session request (up to 50 bars each), so a reader can reload a 50-post index about ten times a minute; past a few hundred bars on one page, paginate — see [Troubleshooting](https://docs.tapback.party/troubleshooting/#a-long-list-page-loses-some-bars).

## Different reactions per post (Plus)

By default every post shows your Tapbar's reactions. On [Plus](https://docs.tapback.party/plans/), a post can carry its own: add a named set in the console's Reactions card (say `spooky`, with a ghost and a skull), then point the post's bar at it.

```jsx
// src/templates/blog-post.js
<tapback-bar entity={post.fields.slug} layout="float" set={post.frontmatter.tapback_set} />
```

Add `tapback_set: spooky` to the post's front matter and select `frontmatter { tapback_set }` in the template's page query. Gatsby infers the schema from your content, so until some post has the field the query fails. The blog starter's `gatsby-node.js` already declares a `Frontmatter` type in `createSchemaCustomization`: add `tapback_set: String` to it. Only on a site without that function, declare it with `exports.createSchemaCustomization = ({ actions }) => actions.createTypes(`type MarkdownRemark implements Node { frontmatter: Frontmatter } type Frontmatter { tapback_set: String }`)`. React leaves the attribute off when the value is null or undefined. To list reactions on the bar instead of naming a set, use `reactions="ghost,skull"`; the keys have to be on the Tapbar or in its palette.

The list-page bars need no `set`. A `live="off"` bar that declares nothing never decides a post's reactions, so the post page's attribute decides them however readers arrive. The attribute applies the first time anyone loads the post; to change a post that's already live, use the ☰ picker in the console's **Pages** tab or the `set_entity_reactions` MCP tool. [Changing reactions on live pages](https://docs.tapback.party/live-pages/) has the full rules.

To choose a post's reactions by looking at the draft instead, add the [in-page picker](https://docs.tapback.party/authoring/) to the draft render: gate the editor `<script>` on `process.env.NODE_ENV === 'development'` and render `<tapback-editor>` alongside the bar in `src/templates/blog-post.js` in the same branch.

## Check it works

1. Deploy to a site on the Tapbar's allowed list (or run your dev server, with `http://localhost:*` allowed). The bar only runs on allowed sites.
2. Open a post, tap a reaction, and reload. The count is still there.
3. Open the post list. That post's blurb shows the same count.

If no bar appears, check that the loader tag is in that page's `<head>` and that the page's origin is allowed — `www` and the bare domain are separate entries. [Troubleshooting](https://docs.tapback.party/troubleshooting/) maps each symptom to its fix.

## Notes for Gatsby

- `node.fields.slug` is the id your `gatsby-node.js` already uses for each page's path, so the index and the post template match by construction. Both page queries have to select it: the starter's index query does, but the `src/templates/blog-post.js` query doesn't, and the build fails until you add `fields { slug }` there.
- Appending an ESM `export const onRenderBody` to the starter's CommonJS `gatsby-ssr.js` fails the build (it mixes CommonJS and ES modules), and replacing the file drops the starter's `lang` attribute, hence the merged version above.

## Let your agent do it

Connect your agent to the Tapback MCP server — in Claude Code, `claude mcp add --transport http tapback https://api.tapback.party/mcp`; in Claude Desktop or claude.ai, **Add custom connector** with `https://api.tapback.party/mcp` — then paste this prompt:

```
Add Tapback live reactions to my Gatsby site.

1. Connect to the Tapback MCP server at https://api.tapback.party/mcp and let me approve the sign-in.
2. Ask me for my site's domain, then create a Tapbar with that domain as its allowed site. Give it a heart, a star, and a smile to start — I can change these later.
3. Show me the embed snippet and tell me exactly where it goes in Gatsby: the loader `<script>` in `gatsby-ssr.js` (`onRenderBody` → `setHeadComponents`), so it lands in every page's `<head>` at build; an inline bar (`layout="inline"`, `live="off"`) in `src/pages/index.js`, keyed to `node.fields.slug`; and a floating bar (`layout="float"`) in `src/templates/blog-post.js`, keyed to the same `fields.slug`. The Gatsby guide is at https://docs.tapback.party/install/gatsby/ (as markdown: https://docs.tapback.party/install/gatsby/index.md).
4. Once I've deployed, post a test reaction and read the count back so we know it's working.
```

[Set up with your agent](https://docs.tapback.party/agent-setup/) has the same prompt for every stack, with an optional step for the in-page picker. [Manage from your agent](https://docs.tapback.party/mcp/) lists everything the agent can reach.
