Astro SDK
Add FlashAnalytics to Astro with the dedicated Astro integration package.
The Astro package is built on top of the Web SDK and provides Astro components plus browser-side helpers for tracking, identity, experiments, remote config, and session access.
Install
npm install @flash-analytics/astro@2.1.8pnpm add @flash-analytics/astro@2.1.8Component setup
---
import { FlashAnalyticsComponent } from '@flash-analytics/astro';
---
<FlashAnalyticsComponent
appId="YOUR_APP_ID"
endpoint="https://api.flashanalytics.app"
capturePageViews
captureErrors
captureVariants
/>Auto capture
page_viewviacapturePageViewsjs_errorandunhandled_promise_rejectionviacaptureErrors- Experiment auto-assignment via
captureVariants
Browser helpers
import {
track,
identify,
getSession,
assignExperiment,
autoAssignExperiments,
fetchRemoteConfig,
} from '@flash-analytics/astro';Manual server error tracking
Astro server errors are manual. Track them from middleware or API routes.
import { trackServerError } from '@flash-analytics/astro';
try {
await riskyOperation();
} catch (err) {
await trackServerError(err, {
clientId: import.meta.env.FLASH_CLIENT_ID,
clientSecret: import.meta.env.FLASH_CLIENT_SECRET,
apiUrl: 'https://api.flashanalytics.app/track',
});
}Session access
import { getSession } from '@flash-analytics/astro';
const session = getSession();
console.log(session?.id);
console.log(session?.estimatedExpiresAt);
console.log(session?.estimatedTtlMs);