如何在heroku应用程序中监控网站点击量



我在react.js中开发了一个web应用程序,并部署在heroku平台上。我想跟踪没有点击到我的网站。在赫罗库我该怎么做?

我想实现与谷歌分析类似的功能。

我认为您正在寻找的工具是react-ga。根据文件:

npm i react-ga

然后在你的App.js 中包括以下内容

import ReactGA from 'react-ga';
ReactGA.initialize('<tracking_id>');  // Insert tracking_id from Google Analytics here
ReactGA.pageview(window.location.pathname + window.location.search);

注意:默认情况下,谷歌会给你一个以"G-…"开头的跟踪ID但此react包需要以"UA-…"开头的跟踪ID这篇文章解释了如何获得以"UA-…"开头的跟踪ID

您可以使用谷歌分析跟踪您的网站点击量。你只需要创建谷歌分析账户并获得跟踪id。一旦你获得了跟踪id,请在你的public/index.html下添加以下代码,用谷歌分析的跟踪id替换tracking_id。

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<TRACKING-ID>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<TRACKING-ID>');
</script>

相关内容

最新更新