# Airbnb Analytics (Analyze Property tab, 2026-10-17)

## What it does

A short-term-rental map tool. The member draws an area (a polygon or a radius) or picks a preset
area, describes the unit (bedrooms, bathrooms, guests, room type, property type, amenities and an
optional purchase price), and gets a report from the nearby Airbnb listings: occupancy, nightly
rate (ADR), trailing-twelve-month revenue, comparable listings and a gross yield. The report
downloads as a PDF. Every figure is gross, before costs. The data is a fixed Airbtics listing
export ("Airbtics-style estimate"), not a live feed.

It sits in the Analyze Property strip right after **Heat Map** (the owner asked for it there; both
read an area rather than a project). Until 2026-10-17 it lived only in the AI Coach staging portal
at `/project-portal-coach/#/str`, behind that portal's reviewer password. That route now redirects
here and keeps its area hash, so the coach's "Open in STR Analytics" links still land on the same
area.

## How it works

- **The page** (`GET /analyze-property/airbnb-analytics`, `main.portal.analyze.airbnb.index`) is
  the usual masthead and `AnalyzeTabs` strip with an **iframe** of the tool. The tool is a
  self-contained ~47 KB vanilla Leaflet app with its own drawing tools and PDF export. Rewriting it
  in Vue would change nothing a member sees, so it is framed as is. The page passes the `#lat=…&lng=…&r=…&bed=…&go=1`
  hash through to the tool, which reads its own hash.
- **The tool** is static: `public/main/tools/airbnb-analytics/` (`index.html`, `app.js`, `app.css`).
  It holds nothing private. `?v=` on the frame URL is the files' mtime (from the controller), and
  the shell appends it to `app.js`/`app.css` so a changed file is never served stale.
- **The data** is one JSON file per market plus `index.json` (each with a `.gz` copy) in
  `storage/app/airbnb-analytics/`. It is **not in git** (storage/app is ignored). Copy the folder to
  a server to give that server the tab. Without `index.json` the page shows a "not loaded" panel
  instead of the frame. Source of the files on wk: `public/project-portal-str/data/`.
- **`GET …/data?idx=1 | ?m={slug}`** is the only way to those files. The slug must match
  `^[a-z_]{2,40}$` before it touches a path. The gzipped copy goes out when the browser accepts gzip.
- **`GET …/map-config`** returns the public Mapbox token for the basemap (streets / dark). Without
  one the tool draws on OpenStreetMap.
- **Gate:** `Feature::AIRBNB_ANALYTICS` (Function access matrix row *Airbnb Analytics*, default
  OPEN like its Analyze siblings) on all three routes. The `analyze-property/*` lockdown applies too.
  The tab itself always shows. A shut gate serves `FeatureLocked`, as on the other Analyze tabs.

## Related files

- [AirbnbAnalyticsController.php](/app/Http/Controllers/Main/Portal/AirbnbAnalyticsController.php)
- [AirbnbAnalytics.vue](/resources/js/Pages/Main/Portal/AnalyzeProperty/AirbnbAnalytics.vue)
- [AnalyzeTabs.vue](/resources/js/Components/Portal/AnalyzeTabs.vue) (`AIRBNB_TAB`, placed after Heat Map)
- [public/main/tools/airbnb-analytics/](/public/main/tools/airbnb-analytics/)
- `routes/main.php`, the `analyze-property/airbnb-analytics` group
- [Feature.php](/src/Membership/Feature.php), `AIRBNB_ANALYTICS`
- Tests: `tests/Feature/Main/Portal/Analyze/AirbnbAnalyticsTest.php`, `AnalyzeTabs.test.js`
