index.tsx 919 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React, { FC } from 'react'
  2. import Script from 'next/script'
  3. export enum GaType {
  4. admin = 'admin',
  5. webapp = 'webapp',
  6. }
  7. const gaIdMaps = {
  8. [GaType.admin]: 'G-DM9497FN4V',
  9. [GaType.webapp]: 'G-2MFWXK7WYT',
  10. }
  11. export interface IGAProps {
  12. gaType: GaType
  13. }
  14. const GA: FC<IGAProps> = ({
  15. gaType
  16. }) => {
  17. return (
  18. <Script
  19. id="gtag-base"
  20. strategy="beforeInteractive"
  21. dangerouslySetInnerHTML={{
  22. __html: `
  23. (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  24. new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  25. j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
  26. 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  27. })(window,document,'script','dataLayer', '${gaIdMaps[gaType]}');
  28. `,
  29. }} />
  30. )
  31. }
  32. export default React.memo(GA)