Integrations
Integrating Gooddata with React (Create React App / Vite)
Adding Gooddata to your React (Create React App / Vite) project is a simple, straightforward process. Follow the step-by-step instructions below to start tracking your visitors without compromising their privacy.
Step 1: Copy Your Project ID
Before you begin, you need your unique Gooddata Project ID.
- Log in to your Gooddata Dashboard.
- Select your project from the sidebar.
- Click on the Settings gear icon in the bottom left.
- Copy the
Project IDor the provided tracking snippet block.
Step 2: Add the Script to Your App
For single-page React applications, you can inject the script directly into the document head when your main App component mounts.
- Open your main
App.jsxorApp.tsxfile. - Import the
useEffecthook from React. - Paste the following code inside your App component to dynamically create and append the script.
- Replace
<YOUR_PROJECT_ID>with your actual ID.
import { useEffect } from 'react';
function App() {
useEffect(() => {
const script = document.createElement('script');
script.src = "https://gooddata-fyp.onrender.com/sdk/tracker.js";
script.defer = true;
script.setAttribute('data-project-id', '<YOUR_PROJECT_ID>');
document.head.appendChild(script);
}, []);
return <div>Your App Components</div>;
}
Step 3: Verify the Installation
Once you have added the script and published your changes, it's time to test if Gooddata is receiving data.
- Open your live website in a new incognito/private browsing window.
- Navigate to a few different pages.
- Return to your Gooddata Dashboard and go to the Realtime tab.
- You should see "1 Active Visitor" and your recent page views populating instantly.
Troubleshooting: If you don't see any data, make sure you don't have an adblocker enabled that might be blocking the script, and ensure you replaced <YOUR_PROJECT_ID> with your actual ID.