Add DataEasy to a React or Vite app
For Vite, Create React App and other single-page apps, add the snippet to the <head> of your index.html. Route changes made with React Router (or any router using the History API) are tracked as pageviews automatically.
index.html
<script
defer
data-website-id="YOUR_WEBSITE_ID"
data-domain="yourdomain.com"
src="https://dataeasy.app/js/script.js"
></script>Developing locally? The script ignores localhost by default so your dev sessions don't pollute your stats. To test the integration, temporarily add data-allow-localhost="true" and data-debug="true".
Goals from React
function UpgradeButton() {
return (
<button onClick={() => window.dataeasy?.("upgrade_clicked", { plan: "pro" })}>
Upgrade
</button>
);
}
// โฆor without any JavaScript:
<button data-dataeasy-goal="upgrade_clicked" data-dataeasy-goal-plan="pro">Upgrade</button>