Add Datasense to React, Vite and React Router
How to add Datasense to a React single-page app built with Vite, Create React App or React Router.
Add the tag to index.html, not to a component, so it loads once:
- Open
index.htmlat the root of your project. - Paste the script inside
<head>.
index.html
<script
defer
data-website-id="YOUR_SITE_ID"
src="https://usedatasense.com/js/script.cookies.js"
></script>Replace
YOUR_SITE_IDwith your site ID from the dashboard.
Verify installation
After you deploy:
- Visit your live website.
- Open the Realtime page of your Datasense dashboard. Your visit shows up within a second, and the setup page says "Receiving events".
Datasense ignores localhost so you don't count your own development traffic. Add
data-allow-localhost="true"to the tag to test locally. More options are in the script configuration reference.