【问题标题】:How to rewrite google Tag Manager Args from typescript to reactHow to rewrite google Tag Manager Args from typescript to react
【发布时间】:2022-12-27 13:33:29
【问题描述】:

I am trying to insert google tags into my react site so I copied a code from a typescript code I have but I get the error Type annotations can only be used in TypeScript files. so now I have no idea on how to rewrite this code in an acceptable format in reactjs. Please help using the code below

_app.js

import React, {useEffect} from 'react'
import TagManager, {TagManagerArgs} from 'react-gtm-module'
import { Toaster } from 'react-hot-toast'
import './Product.scss'
import {Layout} from '../components'
import '../styles/globals.css'
import { StateContext } from '../context/StateContext'

function MyApp({ Component, pageProps }) {
  const gtmId = process.env.NEXT_PUBLIC_GTM_ID || "";

  const tagManagerArgs: TagManagerArgs = {
    gtmId,
  }

  useEffect(() => {
    TagManager.initialize(tagManagerArgs)
  }, [])

  return (
    <StateContext>
      <Layout>
        <Toaster />
        <Component {...pageProps} />
      </Layout>
    </StateContext>
  )
}

export default MyApp

【问题讨论】:

    标签: reactjs typescript google-tag-manager


    【解决方案1】:

    You can remove the type annotation and update like the following code.

    const tagManagerArgs = {
        gtmId,
      }
    

    【讨论】:

      猜你喜欢
      • 2022-11-01
      • 2023-01-29
      • 2022-12-01
      • 2022-12-01
      • 2022-12-27
      • 2022-12-27
      • 2022-12-26
      • 2022-12-19
      • 2022-12-02
      相关资源
      最近更新 更多