Last active
August 7, 2022 01:51
-
-
Save PedramNavid/16f853dbac4e108f0e6c749f79c617ba to your computer and use it in GitHub Desktop.
Gatsby SSR with Jitsu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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