Skip to content
GuidesChecked 18 November 2026

Add a feedback button to your Astro site

Put the script in a layout, call the popup from a module script and handle Astro page transitions.

Free for one project and 100 votes. Paid plans start with a 14 day trial, no card.

The tag

Astro bundles the plain script tags it finds. A tag with any attribute besides src is treated as inline and passed through untouched.

Astro leaves a script alone when it carries extra attributes.

The VoteFirst tag has two data attributes, so it is never bundled.

The Astro documentation says that adding any attribute other than src to a script tag implies the is:inline directive. Writing the directive out costs nothing and tells the next reader why this one tag is not processed.

VoteFirst reads its slug and key from the tag that loaded it. A bundled copy would lose that tag, which is the reason the hosted file is used as it is. Your project's Share and Embed screen shows both values.

src/layouts/Layout.astro, in the head
<script is:inline src="https://app.votefirst.app/embed/votefirst.js" data-project="your-slug" data-key="your-key"></script>

The call

Scripts you write in an Astro component become module scripts, and modules wait until the document is ready. The button is there and the tag has loaded before your call runs.

A plain script in the layout runs after the page is parsed.

No event listener is needed on a site without page transitions.

Astro scripts are TypeScript, which is why the window cast is there. Without it the type checker complains that VoteFirst is not a property of window, although the page works either way.

Because the script sits in the layout, Astro includes it once on every page that uses that layout, and bundles it into one small file.

src/layouts/Layout.astro, in the body
<button id="suggest-btn" type="button">Feedback</button>
<slot />
<script>
  (window as any).VoteFirst.suggest({ trigger: '#suggest-btn' });
</script>

Page transitions

Astro's client router swaps pages without a reload, and a bundled script runs only once. The page load event is the place for code that has to run for each page.

With view transitions on, rebind on every page load.

Astro names astro:page-load as the replacement for DOMContentLoaded.

The Astro documentation states that bundled module scripts execute one time and are ignored after a transition, even when the same script is on the next page. A call made once at load would point at a button that the swap has since replaced.

Calling destroy on the previous popup before binding the new one removes the old listener and closes a dialog that was open during the swap, so one click always opens one dialog.

src/layouts/Layout.astro, with the client router
<script>
  let popup: { destroy: () => void } | undefined;
  document.addEventListener('astro:page-load', () => {
    popup?.destroy();
    popup = (window as any).VoteFirst.suggest({ trigger: '#suggest-btn' });
  });
</script>

The board

The popup takes an idea. A public board shows all of them, each with a status and a vote count, and visitors vote without registering.

Link a board where each idea is counted.

A suggestion stays hidden until you approve it.

Astro suits docs, blogs and marketing sites, where visitors read more than they sign in. A footer link to the board gives them a way to say what is missing without an account, and a vote costs one click.

Cards that repeat each other can be merged, and the votes of both land on the card you keep. Someone who voted on each is counted once. A subdomain of your own can serve the board on the Free and Pro plans.

If it fails

Run a build and open the output page. The VoteFirst tag should appear exactly as written, with both data attributes.

Look at the built HTML before the console.

A missing attribute means the tag was processed.

If the attributes are gone, the tag lost its inline status, so add is:inline. If the tag is there and the click does nothing, read the console for a refused origin, reported as origin_not_allowed.

Add each address you use on Share and Embed, including localhost with the port Astro's dev server prints, which is 4321 by default. A preview deployment on a host such as a branch address counts as one more origin, so list it for as long as you test there.

Open the built page source and look for the script tag before you open the console. Astro can move or bundle scripts you write in a component, and the built output is the only place that shows what a visitor receives. If the tag is there and the popup still does not open, look at the order: the call has to run after the library has loaded, and again on every page load when transitions are on.

What an Astro site gains

No extra bundle weight

The hosted file loads from VoteFirst and your own call is a few lines.

Correct after a swap

The page load event rebinds the button and removes the old listener.

Visitors with a voice

A reader of a static page can suggest and vote without making an account.

Add it in five steps

One tag and one script in the layout cover the whole site.

Get the slug and key

Start a Free project and find both under Share and Embed.

Add the tag

Put the inline script in the head of your layout.

Add the button and the call

Place the button in the body and a plain script below it.

Handle transitions

If the client router is on, move the call into the page load listener.

List your origins

Add your production address and your dev address to the key.

Testing on the built site

Run the production build and open the result, since a dev server and a built site can treat scripts differently. Check the page source for one script tag, then navigate to a second page and open the popup there to prove the listener survives page transitions.

Add the production address to the list of origins before launch, and keep the dev address in it only while you work.

What to know before you set this up

  • Astro changes between major versions, so read its directives and view transitions pages for the version you run.
  • The form opens only from listed origins, so a dev server on a new port must be added.
  • With the client router on, the call has to live in the page load listener.
  • A Free board holds 100 votes, and a vote taken back keeps using its slot.

What Astro developers ask

Does the tag need is:inline?

Astro implies it for a tag with extra attributes, so the page works without it. The directive makes the intent plain to the next person who edits the layout.

Is there an npm package for Astro?

No. VoteFirst is one hosted file, so the site gains no dependency and no integration.

Does it work with server output as well as static output?

Yes. The tag and the call are browser code, and they behave the same wherever the HTML comes from.

Can the button live in a framework island?

Yes. Follow the guide for that framework, since the island is a Vue, Svelte or React component, and keep the tag in the layout.

What does destroy do?

It lifts the click listener off the button and closes a dialog that is open.

Does the key have to stay private?

No. The key is written to be seen in the page, and it only lets listed origins load the form and send votes.

Do visitors need an account to vote?

No. Anyone can vote on a fresh board, and the visitor's browser storage tells the board they have been before. Switch on required sign in if votes must name a person.

Can the board sit on a subdomain of my site?

Yes, on the Free and Pro plans. Point a name such as feedback.yoursite.com at the board.

Where do new suggestions show up?

Your dashboard lists each one as a card to approve, and one email a day at most tells the owner about new ones.

What does it cost to start?

Free covers one project and 100 votes. Lite is $9/mo and Pro is $39/mo, and each begins with a 14 day trial that takes no card.

Give readers a way to report gaps

Free costs nothing for one project and 100 votes, and Lite or Pro can be tried for 14 days with no card.