Skip to content

Instantly share code, notes, and snippets.

@PedramNavid
Last active August 7, 2022 01:51
Show Gist options
  • Save PedramNavid/16f853dbac4e108f0e6c749f79c617ba to your computer and use it in GitHub Desktop.
Save PedramNavid/16f853dbac4e108f0e6c749f79c617ba to your computer and use it in GitHub Desktop.
Gatsby SSR with Jitsu
// https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/
import React from "react";
export function onRenderBody({ setHeadComponents }, pluginOptions) {
const host = 'https://t.jitsu.com/s/lib.js'
const key = process.env.GATSBY_JITSU_API_KEY
const snippet = `window.jitsu = window.jitsu || (function(){(window.jitsuQ = window.jitsuQ || []).push(arguments);})`
// only render snippet if write key exists
if (key) {
setHeadComponents([
<script key="plugin-jitsu" defer src={host} data-key={key} data-init-only="false"></ script>,
<script dangerouslySetInnerHTML={{ __html: snippet }}></script>
]);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment