我正在使用重定向转到我网站的最后一页。在这个重定向中,我向它提供了一堆 url 参数,这些参数告诉我用户在那之前做了什么。
问题是,当我添加 Google Analytics 时,它没有接收到我希望能够收集数据的任何参数。这是 index.js 中的代码:
import Analytics from 'react-router-ga';
import ReactGA from 'react-ga';
ReactGA.initialize('UA-11111111111-1');
ReactGA.pageview(window.location.pathname + window.location.search);
const allGiftsPage = () => { return ( <Results quizType="allgifts" title="All Gifts" /> )}
const popularGiftsPage = () => { return ( <Results quizType="populargifts" title="Popular Gifts" /> )}
const quizResultsPage = () => { return ( <Results title="Results" /> )}
ReactDOM.render(
<Fragment>
<title>Find Their Gifts</title>
<BrowserRouter>
<Analytics id='UA-111111111-1'>
<Route exact path="/" component={App}></Route>
<Route path="/results" component={quizResultsPage}></Route>
<Route path="/allgifts" component={allGiftsPage}></Route>
<Route path="/populargifts" component={popularGiftsPage}></Route>
</Analytics>
</BrowserRouter>
</Fragment>
, document.getElementById('root')
);
这是调用重定向的代码:
<Redirect to={`/results?`+
`quizType=romanticquiz` +
`&age=${this.state.age}`+
`&gender=${this.state.gender}`+
`&color=${this.state.color}`+
`&vacation=${this.state.vacation}`+
`&word=${this.state.word}`+
`&prison=${this.state.prison}`
}
在 Google Analytics 中,使用所有这些参数访问此页面的用户只会显示“/results”,但如果您在结果页面上刷新,您将获得包含所有参数的完整 URL。
有没有一种好方法可以让我在不修改大部分代码的情况下让这个功能正常工作?
谢谢!