簡體   English   中英

使用 Google Tag Manager 在另一個網站中嵌入 React 應用程序<script>

[英]Embedding React app in another website with Google Tag Manager using <script>

我已經創建了 React 應用程序。 現在我想使用 Google 標簽管理器將這個應用程序集成到特定路徑上的多個網站中。 即,我創建了<script src="https://myreactapp/bundle.js"></script> 根據 Google 標簽管理器,我已將此標簽添加到我的 GTM 帳戶的自定義 HTML 中以用於特定觸發器(即“https://myanotherwebsite.com/gtmscriptchanges”)。 由於它是一個反應應用程序,我還包括下面的標簽以及上面的腳本標簽

  <div id="root"></div>
   <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
   <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://myreactapp/bundle.js"></script>

除此之外,我還在我的 index.js 文件中包含了https://www.npmjs.com/package/react-gtm-module

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import TagManager from 'react-gtm-module'

const tagManagerArgs = {
  gtmId: 'GTM-*****'
}

TagManager.initialize(tagManagerArgs)

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

reportWebVitals();

完成上述所有步驟后,我應該可以在此位置看到我的 React 應用程序: https : //myanotherwebsite.com/gtmscriptchanges ,但不幸的是我無法! 我沒有收到任何錯誤,而且,我無法在我的另一個網站中看到新的變化。

請幫忙!

我解決了。 我只需要在 React App.js 中添加一個路由

          <Route path='*' exact={true} component={Search} />

其中 Search 是我的基本組件。 詳細信息: https : //www.analyticsmania.com/post/single-page-web-app-with-google-tag-manager/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM