npm / Astro
The @moszaic/tracker-astro package runs as server-side middleware — it captures every request before your app code runs, including all bot traffic regardless of JavaScript execution.
The package is distributed via a private registry. Your MOSZAIC write key is the only credential you need — no AWS access required.
Step 1: Get a token
Section titled “Step 1: Get a token”Exchange your write key for a short-lived registry token. Replace wk_your_write_key_here with your write key from Settings → Properties:
curl -s \ -H "X-Moszaic-Write-Key: wk_your_write_key_here" \ https://api.moszaic.ai/npm/tokenResponse:
{ "token": "...", "registry_url": "https://moszaic-714412036813.d.codeartifact.us-east-2.amazonaws.com/npm/moszaic-npm/", "expires_in": 43200}The token is valid for 12 hours and is only needed at install time — it never touches your live site.
Step 2: Install
Section titled “Step 2: Install”Use the token to install the package from the private registry:
TOKEN=$(curl -s \ -H "X-Moszaic-Write-Key: wk_your_write_key_here" \ https://api.moszaic.ai/npm/token | jq -r '.token') && \NPM_CONFIG_@moszaic:registry=https://moszaic-714412036813.d.codeartifact.us-east-2.amazonaws.com/npm/moszaic-npm/ \NPM_CONFIG_//moszaic-714412036813.d.codeartifact.us-east-2.amazonaws.com/npm/moszaic-npm/:_authToken=$TOKEN \npm install @moszaic/tracker-astroStep 3: Use in your app
Section titled “Step 3: Use in your app”Create src/middleware.ts in your Astro project. Your Settings → Instrumentation → npm tab has this pre-filled with your credentials:
import { createMoszaicMiddleware } from '@moszaic/tracker-astro';
export const onRequest = createMoszaicMiddleware({ propertyId: 'your-property-id', writeKey: 'wk_your_write_key_here', apiUrl: 'https://tracker.moszaic.ai',});Store your write key as MOSZAIC_WRITE_KEY in your repository secrets, then add these steps to your pipeline:
- name: Set up MOSZAIC registry run: | TOKEN=$(curl -s \ -H "X-Moszaic-Write-Key: ${{ secrets.MOSZAIC_WRITE_KEY }}" \ https://api.moszaic.ai/npm/token | jq -r '.token') npm config set @moszaic:registry https://moszaic-714412036813.d.codeartifact.us-east-2.amazonaws.com/npm/moszaic-npm/ npm config set //moszaic-714412036813.d.codeartifact.us-east-2.amazonaws.com/npm/moszaic-npm/:_authToken "$TOKEN"
- name: Install dependencies run: npm ciVerify
Section titled “Verify”After deploying, visit your site and check the MOSZAIC dashboard. Bot and human events should appear within seconds.