index.tsx 900 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import Script from 'next/script'
  4. import { IS_CE_EDITION } from '@/config'
  5. export enum GaType {
  6. admin = 'admin',
  7. webapp = 'webapp',
  8. }
  9. const gaIdMaps = {
  10. [GaType.admin]: 'G-DM9497FN4V',
  11. [GaType.webapp]: 'G-2MFWXK7WYT',
  12. }
  13. export type IGAProps = {
  14. gaType: GaType
  15. }
  16. const GA: FC<IGAProps> = ({
  17. gaType,
  18. }) => {
  19. if (IS_CE_EDITION)
  20. return null
  21. return (
  22. <>
  23. <Script strategy="beforeInteractive" async src={`https://www.googletagmanager.com/gtag/js?id=${gaIdMaps[gaType]}`}></Script>
  24. <Script
  25. id="ga-init"
  26. dangerouslySetInnerHTML={{
  27. __html: `
  28. window.dataLayer = window.dataLayer || [];
  29. function gtag(){dataLayer.push(arguments);}
  30. gtag('js', new Date());
  31. gtag('config', '${gaIdMaps[gaType]}');
  32. `,
  33. }}
  34. >
  35. </Script>
  36. </>
  37. )
  38. }
  39. export default React.memo(GA)