我正在尝试在我的react应用程序中实现window.data.layer.push,这样我就可以在Google Tag Manager中使用它,但我不确定它会去哪里。这是我的基本app.js文件
// import the GTM Module so you can access it
import TagManager from "react-gtm-module";
const tagManagerArgs = {
gtmId: "GTM-P8J3MKF"
};
TagManager.initialize(tagManagerArgs)
const { persistor, store } = configureStore();
const MGMW = () => (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
{/*<LoginScene className='main-background' />*/}
<LayoutBase />
<GlobalModals />
</PersistGate>
</Provider>
);
const rootElement = document.getElementById('app-root');
if (rootElement) render(<MGMW />, rootElement);
export default MGMW;发布于 2021-09-21 22:50:54
您必须使用useEffect挂钩。
useEffect = () => {/*script to be executed here*/, []}这是React Hooks的componentDidMount版本。有关这个主题的更多信息,请访问:https://reactjs.org/docs/hooks-effect.html
发布于 2021-09-21 23:09:20
有一个NPM包可以帮助你做到这一点:https://www.npmjs.com/package/react-gtm-module
https://stackoverflow.com/questions/69276337
复制相似问题