React

Add the Lienks snippet to the index.html of your React app.

Before you start

Create your site and copy its site ID first (see Quick start).

Add the snippet

With Vite, index.html is in the project root; with Create React App it is public/index.html. Add the snippet there, inside the <head>:

<script defer src="https://app.lienks.com/a.js" data-site="YOUR_SITE_ID"></script>

Page views in your app

React Router and similar routers use the History API, so page changes are counted automatically. Apps with a hash router (HashRouter) show up as a single page (see Troubleshooting).

Track a custom event

Call window.lienks?.event('signup_clicked') wherever something should be counted. More in Custom events.

<button onClick={() => window.lienks?.event('signup_clicked')}>Sign up</button>

In TypeScript projects, declare window.lienks as described in Custom events.

Check that it works

Open your site. The first pageview shows up in the dashboard. If nothing arrives, see Troubleshooting.

Good to know

  • If you use React inside a framework such as Next.js, read that framework’s page instead: Next.js.