About five minutes, on the free plan, without a credit card.
1
Install the SDK
React SPAs use the web SDK directly. There is no separate React package.
npm install @openpanel/web
2
Create a shared instance
Point apiUrl at Privytics. Without it the SDK sends events to OpenPanel's own hosted API. trackScreenViews, trackOutgoingLinks and trackAttributes all default to false, so set the ones you want explicitly; add trackHashChanges: true if you use a hash based router.
// src/openpanel.ts
import { OpenPanel } from '@openpanel/web';
export const op = new OpenPanel({
clientId: 'YOUR_CLIENT_ID',
apiUrl: 'https://api.privytics.com',
trackScreenViews: true,
trackOutgoingLinks: true,
trackAttributes: true,
});
3
Track an event
Import the instance anywhere and call op.track with an event name and optional properties.
import { useEffect } from 'react';
import { op } from '@/openpanel';
function SignupButton() {
useEffect(() => {
op.track('my_event', { foo: 'bar' });
}, []);
return (
<button
type="button"
onClick={() => op.track('button_click', { button: 'signup' })}
>
Sign up
</button>
);
}
4
Identify signed in users
Optional. Passing your own user id as profileId links sessions into one profile. Call op.clear() on logout to drop the current user and group.
import { op } from '@/openpanel';
function LoginComponent({ user }: { user: User }) {
const handleLogin = () => {
op.identify({
profileId: user.id, // Required
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
properties: {
tier: 'premium',
},
});
};
return (
<button type="button" onClick={handleLogin}>
Login
</button>
);
}