1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-25 03:14:01 +01:00
blog/gatsby-ssr.tsx

27 lines
706 B
TypeScript

import React from 'react'
import { GatsbySSR } from 'gatsby'
import { UMAMI_SCRIPT_URL, UMAMI_WEBSITE_ID } from './src/helpers/umami'
import wrapPageElementWithLayout from './src/helpers/wrapPageElement'
export const wrapPageElement: GatsbySSR['wrapPageElement'] =
wrapPageElementWithLayout
export const onRenderBody = ({ setPostBodyComponents, setHtmlAttributes }) => {
setHtmlAttributes({ lang: 'en' })
const isEnabled = process.env.NODE_ENV === 'production'
if (!isEnabled) {
return null
}
const umamiOptions = {
src: UMAMI_SCRIPT_URL,
'data-website-id': UMAMI_WEBSITE_ID
}
setPostBodyComponents([
<script key="umami-script" async defer {...umamiOptions} />
])
}