Spoar

Migrating from 1.x

Where each 1.x function went.

1.x2.0
<Analytics projectId="my-app" /> from the root entrycreateAnalytics({ project, key, endpoint }) once, AnalyticsProvider client={analytics}, and <Analytics /> from ./next
NEXT_PUBLIC_ANALYTICS_URL / VITE_ANALYTICS_URL, posting to {url}/eendpoint, usually /_ra behind createProxy, or the API's /v2/events; NEXT_PUBLIC_RA_CONFIG holds JSON options
@remcostoeten/analytics/browserThe 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 propanalytics.captureError(error) and the errors() plugin
trackClick, observeClicks, data-analyticsTrackClick, or the clicks() plugin with data-ra-click
observePerformancespeedInsights()
observeScroll, observeTimeOnPagescrollDepth(), engagement()
observeOutboundLinks, observeFormsoutboundLinks(), forms()
identifyUser(properties)analytics.identify(userId, traits)
setExperiment(id, variant)The experiments({ id: variant }) plugin
trackTransaction, trackSearchanalytics.track with your own event names
consentRequired, consentGranted, setConsentGrantedconsent: "required" and analytics.consent.grant()
resetVisitorId(), resetSessionId()analytics.reset()
AnalyticsErrorBoundaryErrorBoundary from ./react
useTrack()useAnalytics<Events>()
trackServer, trackServerEvent, createServerTrackcreateServerAnalytics<Events>()
flushOfflineQueueAutomatic; analytics.flush() sends now
CommonJS and ESM buildsESM 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.