Pre-Requisites

Before proceeding, ensure you:

1

Have installed React

Get started here

2

Get your project ID

Sign up on Litlyx Dashboard and create a new project.

0. Create Project

In this example, we used Vite as a local development server.

npm
npm create vite@latest my-app --template react-ts
Feel free to use your favorite development server tool, but to reproduce this example, you should use Vite to have the same structure.

1. Install

Choose your package manager & install the library.

2. Import

Now import Litlyx in your entry-point file. The easiest way in React is in the file App.tsx.

javascript
import { Lit } from "litlyx-js"
If you have an advanced React project or you are a senior developer, import it in the chosen path where you configure the entire application.

3. Initialize

Next, initialize the Litlyx library with your project in your entry-point file (always App.tsx in this example) as follow:

javascript
function App() {
    Lit.init("your_project_id");
    /* previously existing code */
}

This line will already collect more than 10 KPIs for you such as Page Visits, Referrers, Countries, Unique Sessions and many more.

If you have an advanced React project or you are a senior developer, remember not to show hardcoded IDs. Use a more secure pattern, for example, using an .env file and reading from it “your_project_id”.

4. Collect Custom Events

To customize your experience, add the following line in each function you desire. There is no limit to the number of events.

If you want to test if it works and everything is well configured, import the useEffect hook in the entry-point file (always App.tsx in this example):

javascript
useEffect(() => {
    Lit.event("your_event_name");
}, [count])

If you want to exercise more control over your events, you can use the metadata field.

javascript
useEffect(() => {
    Lit.event(
        "your_event_name", {
        metadata: {
            "functional-component": "App",
            value: count
        }
    });
}, [count])

In your dashboard, you can group them in the Events tab with the Event Metadata Analyzer.

Remember that count is a variable declared in App.tsx in the default structure if you used Vite. Otherwise, create your custom variable to listen to the click event.