feat: support csp (#9111)

Co-authored-by: Joel <iamjoel007@gmail.com>
This commit is contained in:
NFish
2024-10-11 16:14:56 +08:00
committed by GitHub
parent 7c6ae96a09
commit f4ce08211d
10 changed files with 148 additions and 62 deletions

View File

@@ -1,6 +1,7 @@
import type { FC } from 'react'
import React from 'react'
import Script from 'next/script'
import { headers } from 'next/headers'
import { IS_CE_EDITION } from '@/config'
export enum GaType {
@@ -23,9 +24,16 @@ const GA: FC<IGAProps> = ({
if (IS_CE_EDITION)
return null
const nonce = process.env.NODE_ENV === 'production' ? headers().get('x-nonce') : ''
return (
<>
<Script strategy="beforeInteractive" async src={`https://www.googletagmanager.com/gtag/js?id=${gaIdMaps[gaType]}`}></Script>
<Script
strategy="beforeInteractive"
async
src={`https://www.googletagmanager.com/gtag/js?id=${gaIdMaps[gaType]}`}
nonce={nonce!}
></Script>
<Script
id="ga-init"
dangerouslySetInnerHTML={{
@@ -36,6 +44,7 @@ gtag('js', new Date());
gtag('config', '${gaIdMaps[gaType]}');
`,
}}
nonce={nonce!}
>
</Script>
</>