/vivreal-knowledge:vivreal-analytics-knowledgefrom vivreal-knowledge
Use when working on Vivreal's first-party analytics, VR_Analytics_API (the collect→store→rollup pipeline), the Templates SiteBeacon, or the per-site traffic dashboard (VR_Secure_API read route + portal AnalyticsPanel). Covers the CloudFront+WAF → Lambda Function URL ingest chain (X-Origin-Verify, bot filter, Joi, per-IP rate limit, daily-salt visitor hash), the analytics_rollup DynamoDB design, the daily rollup cron into mainDb.site_traffic_daily, the LIVE auto-deploy status (GitHub Actions → CloudFormation) plus the W4 CDN egress meter (runs unconditionally), and where increment 2 lives. Triggers on: analytics, site traffic, beacon, SiteBeacon, visitor stats, page views, unique visitors, analytics_rollup, site_traffic_daily, first-party analytics, per-site dashboard, collect.vivreal.io, visitor hash, rollup cron, CDN egress meter, VR_Analytics_API. Source of truth: `VR_Analytics_API` `CLAUDE.md` (and the docs it links) at `origin/main`.
Ships in vivreal-knowledge. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Cross-repo flows, decisions and maps: the vivreal-hq dev docs under ${VIVREAL_REPOS}/vivreal-hq/docs/dev-docs/, starting at 02-architecture/platform-and-services.md; npm run docs:route -- "analytics" from vivreal-hq names the rest. This skill and the repo's CLAUDE.md own the repo's internals.
Source of truth: VR_Analytics_API CLAUDE.md (and the docs it links) at origin/main.
Last synced: 2026-10-21 against origin/main at 13c0763 (#25, the v7 release; deploys on push to main, which has no stable)
Vivreal's first-party, privacy-first web-analytics pipeline. Increment 1 (this repo) is collect → store → rollup only; increment 2 (the read API + dashboard) lives in VR_Secure_API + the portal. Node 22 (nodejs22.x), AWS SAM, webpack, same conventions as the other backends. Read CLAUDE.md at origin/main first (added 2026-09-23); README.md's status header may still say DEPLOY-GATED, which is stale. The full design is Vivreal_Portal_Mobile/docs/projects/vivreal-first-party-analytics/design.md + cost-analysis.md.
Status: LIVE (base pipeline). .github/workflows/lambda_api.yml auto-deploys every push to main (and workflow_dispatch) via aws cloudformation package/deploy to stack vr-analytics-api (us-east-1). Secrets are per-service <secret-prefix>/analytics resolved as CloudFormation dynamic references (ORIGIN_VERIFY_SECRET, VISITOR_SALT_SECRET, CLUSTER_URL, a missing key fails the deploy itself; no separate secrets preflight) plus SSM <ssm-prefix>/shared/*. @hillbombcreations/schemas comes from the registry (read the pin from package.json; the old file:../Vivreal-Schemas ref is gone), alongside @aws-sdk/client-cloudwatch. Deployed shape (read template.yaml; all arm64): the CDN log meter CdnLogMeterFunction (CloudFront access logs to groups.cdnUsage, the second half of CDN metering, reserved concurrency 1 because two overlapping runs would double count) beside IngestFunction (ingest.handler, public Function URL AuthType: NONE, reserved-concurrency capped) + RollupCronFunction (rollupCron.handler, EventBridge cron(0 6 * * ? *), reserved concurrency 1).
Observability + hardening (added this window): Sentry DSN is now wired for both Lambdas, plus alarms for swallowed errors, missed rollup cron runs, and throttles. The repo also picked up Atlas connection/teardown hardening (part of the cross-repo half-open-connection fix) and joined the testing campaign, 100%-coverage test suite, ESLint, and a husky pre-push gate.
The W4 CDN egress meter runs unconditionally. src/rollupCron/cdnRollup.js + src/shared/cloudwatchClient.js $inc cdnUsage.totalBytes per group from AWS/AmplifyHosting BytesDownloaded, as a guarded sibling pass in rollupCron/main.js that runs even when the traffic rollup throws, and whose own failure is logged and never rethrown. It was safe to enable because VR_Client_API's CDN quota gate no longer 402s (it meters and falls through), so metering cannot take a site down. A third sibling pass, searchRollup, rolls product_search_terms into product_search_dailies.
The traffic-multiple watch (V7.284, v7). A fourth guarded sibling, src/rollupCron/trafficMultipleCheck.js, runs after the CDN rollup and LOGS one warn line, rollupCron: group over traffic multiple, for each group with pay as you go off that is at or over TRAFFIC_ALERT_MULTIPLE times its plan's monthly traffic allowance (a literal in template.yaml; a missing or bad value falls back to 3). It never blocks or bills: VR_Client_API keeps serving over-cap sites on purpose. The allowance comes from @hillbombcreations/tier-quotas, never from the stale groups.cdnUsage.quota. TrafficMultipleMetricFilter counts that line into Vivreal/Analytics GroupsOverTrafficMultiple, and TrafficMultipleAlarm (<stack>-groups-over-traffic-multiple) fires at 1 or more. Every run ends with rollupCron: traffic multiple check complete carrying checked, over and multiple; over: 0 with checked equal to the live group count is the proof the watch ran and found nobody, not silence.
Indexes are built by an explicit step (V7.307, v7). src/shared/mongo.js sets autoIndex: false and autoCreate: false, so a cold start no longer creates collections or indexes. scripts/build-indexes.js checks (default, read only) or --builds missing indexes through tenant-db's buildIndexes; --placements is required and must name stored tenant dbKeys, and --new-placement <pod> pre-builds the next pod (vivreal-tenancy). indexes.snapshot.json plus its test fail when the declared index set changes without a reviewed snapshot.
Vivreal_Templates/src/components/SiteBeacon/index.tsx, mounted in layout.tsx. Fires only on real deployed sites (SITE_ID set and ≠ 'preview'); on by default for every site. Sends { s, h, p, r, w } (siteId, hostname, path, referrer, screen width) as text/plain via sendBeacon (keepalive-fetch fallback) to POST https://collect.vivreal.io/e, no custom headers, no application/json (would trigger a CORS preflight). Do NOT confuse with <SiteAnalytics>, which reads siteData.analytics and emits the customer's own third-party tag (GA/Plausible/Fathom).CachingDisabled, optional WAFv2 WebACL (EnableWaf, default on: 3000 req/5min per-IP rate rule + AWS IP-reputation group). Injects the X-Origin-Verify shared-secret header via OriginCustomHeaders. Chosen over API Gateway purely on cost (~$150/mo saved at scale, README "Endpoint choice").AuthType: NONE, reserved concurrency cap (src/ingest/main.js). Order: origin-verify check → 4KB body cap → UA bot filter → Joi validate → per-IP rate limit (120/min default, atomic DDB) → siteId→groupID resolve → daily-salt visitor hash → atomic DynamoDB writes. Every application-level outcome returns 204 (bot, invalid, rate-limited, unknown site, error), no prober can distinguish "processed" from "dropped"; only infra-layer checks return 403/404/405/413.AnalyticsRollupTable, PK=bucket/SK=sk, PAY_PER_REQUEST, TTL'd. Atomic ADD counters per pv/page/ref/device/country; uniques via conditional-put dedup marker (2-day TTL) + total; an active#{date} site index so the cron Queries active sites instead of Scanning. ~7-8 writes/pageview.cron(0 6 * * ? *) daily (src/rollupCron/main.js): Query the active-site index, cap top-20 pages/referrers + fold overflow into (other), write one bounded doc per (siteId, date) to mainDb.site_traffic_daily. Concurrency capped at 5 (mainDb maxPoolSize: 3). The physical collection is site_traffic_dailies (src/shared/mainDb.js pins collectionName); a query on the singular name is a false zero.visitorHash = HMAC-SHA256(dailySalt, ip|ua|siteId) where dailySalt = HMAC-SHA256(VISITOR_SALT_SECRET, <UTC date>), Plausible's method. Raw IP is never stored (in-memory HMAC input only; Sentry sendDefaultPii: false). Salt rotates every UTC day → cross-day correlation impossible. Cookieless, no client storage. Owner action before pitching EU customers: a privacy-policy/DPA line describing the pseudonymization (flagged in design.md §9 + visitorHash.js header).
groups.dbKey (src/shared/placements.js, TEN-10), cached briefly per container, so a new placement is seen without touching this repo. The old ANALYTICS_TENANT_DB_KEYS list is now only an operator override for a local run and is deliberately NOT set in template.yaml (a stored value would outrank the registry). Every failure path THROWS rather than returning a short list (zero groups read, zero routable placements, a bad override), and both callers turn the throw into a Sentry event without taking ingest down. The retired database names are refused by tenant-db's isRoutablePlacement.{{resolve:...}} at deploy time.sendBeacon cannot send. Direct-to-Function-URL callers bypass WAF but still hit every Lambda-side defense.nodejs22.x since 2026-10-02 (c23f0d0), moved with the rest of the fleet.VR_Secure_API: GET /analytics/site/traffic (src/getGroupInformation/api/index.js), tenant-gated, not admin-gated: active_ctx groupID + a site-ownership check scoping {_id, groupID} so a foreign siteId 404s identically to a missing one (services/getSiteTrafficReport.js). Reads site_traffic_daily, top-10, cached via siteAnalyticsCache. Distinct from the /admin/analytics/google-analytics/* GA4 admin routes.src/app/api/proxy/analytics/site-traffic/route.ts; dashboard src/components/Sites/SiteDetail/AnalyticsPanel.tsx (AnalyticsEditor.tsx alongside it edits the third-party tag, not this pipeline).vivreal-templates-knowledge (beacon host), vivreal-secure-api-knowledge (read route), vivreal-portal-knowledge (proxy + panel), vivreal-db (mainDb rules), vivreal-iam-secrets (<secret-prefix>/* secrets layout).
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub hillbombcreations/vivreal-skills --plugin vivreal-knowledgeOther plugins' skills for the same job
27 skills in this plugin
/sentry-tracerUse when investigating what happened during a Vivreal user action across the stack, tracing an error end-to-end, validating a deploy, or doing tenant-scoped triage with Sentry. Teaches WHEN to trace cross-stack (frontend spans ↔ backend logs ↔ WebSocket events) and HOW (trace-ID propagation, the standard tag set, request_id fallback, service.* breadcrumbs). Triggers on: "what happened when I did X", "why did this error", trace this request, Sentry issue, deploy validation, "everything's broken for this group", crash, error timeline. For the full investigation agent with Sentry MCP tools wired in, dispatch the `sentry` agent / `/sentry-trace` (both in the `vivreal-sentry` plugin); this skill is the passively-loaded knowledge layer. Also covers the step from a Sentry error to the AWS and Atlas metric that confirms an infrastructure cause (502 with no backend event, Lambda timeout, Mongo connect-hang, throttling, OOM, stalled deploy)./vivreal-accounts-and-writesUse before filming, walking or capturing anything in the Vivreal portal or on vivreal.io, and before any write a capture or walk makes. Carries which login to use for which business (the demo account, the QA scratch owner, the owner session), the eight-step owner-approved write protocol (named approval, snapshot, write through the UI, fresh-process read-back, restore, manifest entry), the never-list (Post, Publish, Schedule, Connect and the rest), and the rules for stills that fill vivreal.io marketing slots (pair by what the slot says, no demo site has its own web address, mask comped plan figures). Shared by footage-recorder, tutorial-maker, help-page-producer, qa-walker and marketing-auditor. Triggers on: which login, demo account, QA scratch-2, test account, switch business, owner-approved write, write protocol, snapshot and restore, mutations, marketing still, screenshot swap, vivreal.io slot, walk harness, write guard, POST allow list, PRO badge.