Skip to content

Instantly share code, notes, and snippets.

@kenakingkong
Last active April 12, 2022 10:46
Show Gist options
  • Save kenakingkong/3421735068e3ccc8a552ed33cb19284c to your computer and use it in GitHub Desktop.
Save kenakingkong/3421735068e3ccc8a552ed33cb19284c to your computer and use it in GitHub Desktop.
import type { AppProps } from 'next/app'
import Script from 'next/script'
import * as snippet from '@segment/snippet'
function App({ Component, pageProps }: AppProps) {
const loadSegment = () => {
const options = {
apiKey: process.env.NEXT_PUBLIC_SEGMENT_WRITE_KEY
}
if (process.env.NEXT_PUBLIC_NODE_ENV) {
return snippet.max(options)
} else {
return snippet.min(options)
}
}
return (
<>
<Script dangerouslySetInnerHTML={{ __html: loadSegment() }} id="segmentScript" />
<Component {...pageProps} />
</>
)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment