How to add an AI chatbot to Gatsby

On Gatsby, a chat widget is installed through gatsby-ssr.js, via onRenderBody. Applies on your next build and deploy. None.

Where it goes

gatsby-ssr.js, via onRenderBody

Availability: None.

Adding the chatbot to Gatsby

  1. 1

    Open or create gatsby-ssr.js at your project root.

  2. 2

    Export onRenderBody and call setPostBodyComponents with the script element.

  3. 3

    Rebuild and deploy.

  4. 4

    Applies on your next build and deploy.

The snippet you paste

<script src="https://rubyrep.com/rubyrep.js" data-rubyrep="rr_your_public_key" defer></script>

Your own key replaces rr_your_public_key — you get it after training RubyRep on your site.

Worth knowing on Gatsby

  • setPostBodyComponents places the tag at the end of <body>, which is where a widget belongs.

  • Gatsby's client-side router keeps the page alive across navigation, so the widget mounts once.

Gatsby questions

Where does the code go on Gatsby?
gatsby-ssr.js, via onRenderBody. Applies on your next build and deploy.
Do I need a paid Gatsby plan?
None.
Will a Gatsby update remove it?
setPostBodyComponents places the tag at the end of <body>, which is where a widget belongs.
Does it slow Gatsby down?
No measurable effect. The snippet is deferred, so it loads after your page has rendered, and the chat interface itself is only fetched when a visitor opens it.

Related

Get your snippet.

Enter your Gatsby site and RubyRep reads it, builds your representative, and hands you the exact line to paste.

https://

Takes about a minute. No credit card.

Using something else? See all platforms.