Migrating from 1.x
Where each 1.x function went.
| 1.x | 2.0 |
|---|---|
<Analytics projectId="my-app" /> from the root entry | createAnalytics({ project, key, endpoint }) once, AnalyticsProvider client={analytics}, and <Analytics /> from ./next |
NEXT_PUBLIC_ANALYTICS_URL / VITE_ANALYTICS_URL, posting to {url}/e | endpoint, usually /_ra behind createProxy, or the API's /v2/events; NEXT_PUBLIC_RA_CONFIG holds JSON options |
@remcostoeten/analytics/browser | The root entry, which has no React dependency |
trackEvent(name, meta), track(type, meta) | analytics.track(name, props), typed by your Events |
trackPageView() | analytics.page(), or automatic |
trackError(error), observeErrors, trackErrors prop | analytics.captureError(error) and the errors() plugin |
trackClick, observeClicks, data-analytics | TrackClick, or the clicks() plugin with data-ra-click |
observePerformance | speedInsights() |
observeScroll, observeTimeOnPage | scrollDepth(), engagement() |
observeOutboundLinks, observeForms | outboundLinks(), forms() |
identifyUser(properties) | analytics.identify(userId, traits) |
setExperiment(id, variant) | The experiments({ id: variant }) plugin |
trackTransaction, trackSearch | analytics.track with your own event names |
consentRequired, consentGranted, setConsentGranted | consent: "required" and analytics.consent.grant() |
resetVisitorId(), resetSessionId() | analytics.reset() |
AnalyticsErrorBoundary | ErrorBoundary from ./react |
useTrack() | useAnalytics<Events>() |
trackServer, trackServerEvent, createServerTrack | createServerAnalytics<Events>() |
flushOfflineQueue | Automatic; analytics.flush() sends now |
| CommonJS and ESM builds | ESM only |
The 1.x visitor id, opt-out, identity, traits and experiments in localStorage are read on first load and move into the single __ra key once consent allows storing, so returning visitors keep their id.