---
title: "Data and consent rules"
description: "What guest data we collect, what we never collect, how consent is logged, and who owns the data."
url: https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/data-rules
markdown: https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/data-rules.md
---

# Data and consent rules

> **Warning: Not legal advice**
>
>
> Law 2004-63 and the INPDP apply. We are not lawyers. A lawyer checks the consent wording and hosting before the first pilot.

## Ownership

- The hotel owns the guest data. We only process it, and the contract says so.
- Data is stored in our database, per hotel, so our AI can learn from it later.
- We never sell or reuse a raw guest list.
- Anonymous combined stats are ours to use.
- The hotel can export and delete at any time, per guest and per hotel.

## Data tiers

| Tier | Fields |
|---|---|
| Must have | Name, phone, language, consent |
| Optional | Birthday, email |
| Optional with consent | Origin (country, city), stay dates, length of stay, where they go next, survey answers |
| Never | Continuous phone location, passport or ID numbers, payment cards |

Every extra question lowers the number of guests who finish the form, and every field is something we must protect. Do not add a field the hotel would never use.

## Consent

- Consent is logged per channel: email, WhatsApp, and later SMS.
- Each entry records the timestamp, the source, and the wording version.
- When signed-in staff make the change (adding a guest, a CSV import, a consent switch), the entry also keeps their user id (`consent_events.staff_user_id`). It stays empty for the guest's own answers (QR, unsubscribe, STOP) and is cleared if the staff account is deleted. It is not part of the guest export.
- The log is append only. A change of mind is a new entry, never an edit. See [consent log is append only](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/decisions/consent-log-append-only.md).
- WhatsApp and email have separate toggles on the capture page, both off by default, each with the exact logged wording under it.
- Every message carries an unsubscribe link or STOP. Messaging builds them with `packages/common/src/unsubscribe.ts`: `signUnsubscribeToken`, `unsubscribePageUrl`, `listUnsubscribeHeaders` (RFC 8058 one tap, for email) and `unsubscribeFooter` (the line every message ends with). The link opens `/u/<token>` on the web app (en, fr, ar, the hotel's branding): one switch per channel and one tap to stop everything. Each change is a consent event with source `unsubscribe_link`. Email clients that show their own button POST to `/unsubscribe/<token>` on the api.
- An inbound WhatsApp message is checked with `isStopKeyword` (the whole message must be STOP, arrêt, توقف and the like). The webhook then calls `applyStopReply`, which withdraws WhatsApp consent with source `stop_reply`. See [unsubscribe links are signed tokens](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/decisions/unsubscribe-links-are-signed-tokens.md).
- The consent text lives in one place so it can change after legal review: `packages/common/src/consent.ts` (`CONSENT_WORDING` in en, fr and ar, and `CONSENT_WORDING_VERSION`, bumped on every change).
- `/privacy` and `/terms` (en, fr, ar) are short plain-language drafts in `apps/web`, not yet reviewed by a lawyer; the privacy page prints the live `CONSENT_WORDING`, so it can never drift from what the capture page shows.

### Changing the wording

- Edit `CONSENT_WORDING` in `packages/common/src/consent.ts` only. Never copy the text into a component or a translation file.
- Bump `CONSENT_WORDING_VERSION` (`YYYY-MM-<label>-<n>`) in the same change, for any edit, even a typo in one language. Every consent event stores the version the guest saw, so old events stay true.
- Adding a channel or a language is also a bump. Old events are never rewritten.

### The QR capture page

- Guest pages (`/h/...`, `/u/`, `/s/`, `/o/` and `/r/<token>`, in `apps/web/app/(guest)`) share `GuestShell` and ship none of the site chrome (no analytics, consent banner, feedback button or background art) and almost no client code: native radio chips, native toggles, a native `<details>` for the optional part. One small client component holds the form. The header is the hotel's logo (or its initials) and name on a flat tint of its primary color, the perk card uses its accent color, and Ritorno only shows as a "Powered by" line in the footer. A language switcher (en, fr, ar) sits at the inline end and sets `?lang=`; the unsubscribe page has none, because the consent log stores the wording in the guest's language. When a hotel color is under 3:1 on white the focus ring stays ink. Every guest page has the same loading skeleton, error boundary (with retry) and a not valid or expired state.
- Fields: name, phone (searchable list of every country, +216 by default), message language, an optional "when do you leave?" (tomorrow, 2, 3 or 7 nights, or a date up to 90 days ahead, refused outside that range by the api too) with its own `profile` toggle that only shows once a date is chosen, the WhatsApp and email consent toggles, then an "optional" section with birthday and email. The submit button is sticky on phones. Name and phone are checked on blur, so a wrong phone number rarely reaches the api. When the api refuses a sign-up, the error shows on the field it names.
- The button shows a sending state, and success (animated check, the perk, what to do at the front desk) shows only after the api says ok. If the api refuses (invalid, rate limit) or the request never arrives (offline, api down), the form stays with the guest's answers, an error and the button to retry.
- Route `apps/web/app/(guest)/h/[hotelSlug]?src=room|table|desk&loc=<spot>&lang=en|fr|ar`. `src` becomes the guest source (`qr_room`, `qr_table`, `qr_front_desk`), `loc` is stored as `guests.capture_location`.
- Branding comes from `hotel_settings` through `public.hotel`, which returns only the display name, two colors, logo url, default language and slug. Everything else stays behind a session.
- `public.capture` is the one public write. It is scoped by the hotel slug, records `profile` consent only when the guest chose a departure date and switched its toggle on, and goes through the same `upsertGuest` as staff and CSV, so a known phone merges and every answer lands in the consent log with the wording version.
- The page loads in the hotel's default language with a link switcher (no JS needed), is `noindex`, and skips the site chrome (feedback button, consent banner, analytics) to stay small on a weak connection.
- Abuse protection on `public.capture`: 60 sign-ups per ip and hotel per 10 minutes (everyone on the hotel wifi shares one ip) and 200 per hotel per hour (429 over that; survey answers are counted apart, 60 per ip per 10 minutes), a hidden `website` honeypot, and names that are links. A bot caught by the honeypot or a link name gets a normal "ok", nothing is stored, and a `capture discarded` log line records the hotel id and the reason. There is no minimum fill time: autofill makes real guests fast. Only the ip and the hotel id are used as keys, never a phone, email or name. The web app forwards the guest's `x-forwarded-for` so the limit is per guest, not per web server. The ip is the first hop of that header, so the api must sit behind a proxy that sets it (Dokploy, Vercel, Cloudflare do). A client that sends its own header can pick a fresh ip each time, so the per-hotel cap is the real ceiling.
- Welcomes from `public.capture` (`enqueuePublicWelcome`) are capped so a stranger can't spend a hotel's WhatsApp balance: no new welcome when the guest (one per phone and hotel) got one in the last 30 days, and at most 60 per hotel per hour. A skip is logged with the hotel id only, the sign-up still succeeds.
- QR codes: the dashboard page `/qr-codes` prints one code per room, table or front desk (`hotel.qrCodes`, [printing](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/hotels.md#printing-qr-codes)). A `preview=1` try-out of the page saves nothing. Each code is a short link, `/q/<code>`, that leads to `/h/<slug>?src=<room|table|desk>&loc=<spot>` ([short links](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/hotels.md#short-links-behind-the-codes)). The link table holds no guest data and no scan is logged. The source is the guest's `source` and the spot is `guests.capture_location`, set when the guest is first created. `hotel.captureStats` counts guests per source and spot so a hotel sees which code works. Staff add the spots (`101-120`, `T1, T2`). Room and table names are saved per hotel (`capture_spots`) so they can be printed again, see [rooms and tables](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/hotels.md#rooms-and-tables). They are not guest data.
- **Continue on WhatsApp** on the same page opens a chat with Ritorno's shared number. Sending that message is not a consent: see [scan to WhatsApp](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/messaging.md#scan-to-whatsapp) for what is kept and for how long.
- Known limit: a phone number is not verified, so someone could sign up another person's number. Consent is per channel and withdrawable with STOP or the unsubscribe link.

### How it is stored

- `guests` is unique per hotel and phone (`hotel_id`, `phone_e164`). Every row carries `hotel_id`, and the consent tables point at `(guest_id, hotel_id)` so a row can never reference another hotel's guest.
- `guest_consents` holds the current answer per guest and channel. `consent_events` holds every change: channel, granted or not, time, source, wording version, optional ip hash. A first "no" is logged too, an unchanged answer is not.
- `guest_visits` holds one row per visit, at most one per guest per day on the hotel's clock (`recordVisit` in `packages/orpc/src/lib/guests.ts`). It only feeds recognition (visit count, returning badge and filter, first and last visit), never points or tiers. Deleted with the guest. A visit is counted when:
  - a guest signs up or scans the QR again. The public answer is the same for a new and a known phone
  - staff add a guest, also with a phone that is already known
  - staff tap "Mark visit" in the guest finder at the top of the dashboard home, on the guest page, or in quick add once the typed phone is known (source `staff`)
  - a guest's offer code is redeemed (source `staff`). A promo code belongs to no guest and counts nothing
- Imports by csv count no visit. A wrong tap can be taken back for 10 minutes: "Undo" on the "Visit saved" toast (`guests.undoVisit`), or "Undo" on the redeem result (`offers.undoRedeem`, which also removes the visit that redemption counted).
- Adding a phone that is already known shows whose it is while staff type. After saving it lists what was updated and what was kept: name, email, birthday, country and city only fill gaps.
- Channels are `email`, `whatsapp` and `profile`. `profile` is the consent for the optional tier (country, city, stay dates, next destination): those fields are refused without it and cleared when it is withdrawn. On the capture page the `profile` toggle only shows once the guest answers the optional "when do you leave?". The page only collects the departure date, but switching the toggle on grants the whole `profile` channel, so staff can then record the other details too. With the toggle off, the date is not stored and no consent is granted.
- Deleting a guest is a hard delete: the guest, its consents and its events go together, and the staff notes on their [feedback cases](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/surveys.md#feedback-inbox) are erased in the same transaction, so nothing personal is left. The audit log keeps only a row without personal data: `guest.delete` with the SHA-256 of the guest id (`hashGuestId`) and the hotel id. Earlier audit rows (export, consent change) keep the opaque guest id, which names nobody once the guest row is gone. See [guest delete is a hard delete](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/decisions/guest-delete-is-a-hard-delete.md).
- Export and delete, per guest and per hotel, are in the dashboard under Guest data (owner and manager only, staff cannot). Export is JSON (every field, the full consent log and the feedback follow-up with its notes, `guests.export`, `guests.exportAll`) or CSV (one row per guest, feedback follow-up in `feedback_follow_up`, consent log in the last column, `guests.exportCsv`; cells starting with `=`, `+`, `-`, `@` are neutralised against spreadsheet formulas). Delete all (`guests.removeAll`) needs the exact guest count, so a stale screen can't delete guests added since. Every export and delete writes an audit entry.

### Phone numbers and duplicates

- Phones are stored as E.164 (`+21620123456`). `parsePhone` in `packages/common/src/phone.ts` accepts the Tunisian local 8 digits, `+216…`, `00216…`, other international numbers, separators and Arabic-Indic digits. Tunisian landlines (starting 3, 7, 8) are valid but can't take WhatsApp, so a WhatsApp consent is refused for them.
- The phone field (`PhoneInput`, `packages/common/src/dial.ts`) reads a leading `+` or `00`, typed or pasted, and switches the country. The default is always +216 and the country changes only when it is picked from the list or typed with `+` or `00`. The browser locale is deliberately not used: it says how a phone is set up, not whose number is typed, and a Tunisian mobile read under a foreign code (`20123456` under +49) can be a valid number belonging to a stranger, who would then be messaged. It is used by the capture page, the demo form and staff quick add, which returns to +216 after each guest. Guest search ignores a leading `0` or `00`, so `06 12…` finds `+336 12…`. CSV import reads numbers without a country code as Tunisian.
- Same hotel and same phone is the same guest. A second capture (`guests.create`) merges into the existing guest: name, email, birthday, country and city only fill gaps, language and stay details take the latest value. A rescan of the public form is the exception: it never changes a check-out that is today or later (staff may have set it), and never sets one earlier than the check-in.
- Merging only adds consent and fills gaps. A "no" from any source, a QR rescan included, never withdraws an existing "yes" and never clears the optional details, since anyone who knows a phone can rescan the public form. Withdrawal goes through the unsubscribe link, a STOP reply or a staff consent change (`guests.setConsent`), each logged.
- A CSV import never re-grants a withdrawn channel. When a guest said yes to a channel and later withdrew it (unsubscribe, STOP or staff), a "yes" in an imported row is ignored for that channel and nothing is added to the consent log: an old list must not override a withdrawal. The import summary counts these rows (`consentKept`). The guest can opt in again from the QR page or the unsubscribe page, and staff can grant it back on the guest page (logged with the staff source).

## Isolation

- Every guest row and every query is scoped by hotel id. See [hotel is an organization](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/decisions/hotel-is-organization.md).
- Guests are not auth users. See [guests are not auth users](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/decisions/guests-are-not-auth-users.md).
- Files live in one bucket with a prefix per hotel. See [one bucket, prefix per hotel](https://pr-403-docs.preview-ritorno.findmalek.engineer/docs/decisions/one-bucket-prefix-per-hotel.md).

## Logging and non-production

- Never log a phone, email or name in plain text. Use the logger redaction.
- Previews, tests, local and staging never send real messages. Providers are log-only there.
- Seeds, previews and tests use fake data only, never real guests.

## Parked: location tracking

Dawarich or any location tracking is parked. If it ever returns it is opt in, one time, on guest request, and only after a legal check.
