我試圖在我的 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>/span>
</Provider>/span>
);
const rootElement = document.getElementById('app-root') 。
if (rootElement) render(<MGMW />, rootElement) 。
export default MGMW。
uj5u.com熱心網友回復:
你必須使用useEffect掛鉤。
useEffect = () => {/*script to be executed here*/, [] }
這就是React Hooks的componentDidMount版本。更多相關內容請看這里。https://reactjs.org/docs/hooks-effect.html
uj5u.com熱心網友回復:
有一個NPM包可以幫助你解決這個問題。https://www.npmjs.com/package/react-gtm-module
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/331524.html
標籤:
上一篇:下拉選單在顯示設定為無后不能下降
