# Send leads and activity to your CRM

Source: https://help.ruuster.com/idx/crm-overview

> How a registration, tour request or question on your site reaches your own CRM through a short server route, which events and fields it sends, and what Ruuster does with the lead once it is in a CRM connected to Ruuster.

Your site owns its forms and its leads. Every form on your site posts to a route on your own server,
and that route sends the lead to your CRM with your CRM's own key. This page explains the loop once.
The pages for [Follow Up Boss](https://help.ruuster.com/idx/crm-follow-up-boss),
[Sierra Interactive](https://help.ruuster.com/idx/crm-sierra) and
[Sure Send](https://help.ruuster.com/idx/crm-sure-send) give the exact route, the exact request
and a test you can run in five minutes.

## The loop, step by step

1. **A visitor fills in a form on your site.** The recipe forms (`RegistrationForm`, `TourForm` and
   `ContactForm`, see [Registration, tour and contact forms](https://help.ruuster.com/idx/recipe-forms))
   show your consent sentence beside an unchecked box, and a separate unchecked box for listing
   alerts. The send button stays off until the visitor checks the contact box.
2. **The form posts JSON to your own server route.** The body is a `LeadSubmission`: the kind of
   form (`registration`, `tour` or `contact`), the visitor's name, email and phone, their message,
   the tour time they asked for, the listing they were looking at, both consent boxes and the exact
   consent wording they saw, the page they sent it from, and where the visitor came from: the
   visit's UTM values and ad click ids (gclid, fbclid, msclkid), its landing page and outside
   referrer, and their first and latest visit. A form can also name the agent and whether the lead
   is a buyer, a seller or both.
3. **Your route checks the request.** It accepts posts only from your own site (the `Origin` header
   must match `SITE_ORIGIN`). It drops anything that filled the hidden honeypot field. It asks for an
   email or a phone number and for the checked contact box, and answers the form with a plain
   sentence when something is missing.
4. **Your route looks up the listing with the Listings API.** That gives the CRM the real price,
   city, state, ZIP and MLS number. When the listing's address is hidden, the street is never sent.
5. **Your route sends the lead to your CRM** with `@ruuster/idx/crm`, using your CRM key from your
   server's environment. The source is your site's name (`SITE_NAME`).
6. **Your CRM creates or updates the person.** Your agents see the lead, the request, the listing
   and where the lead came from in the CRM they already use. The agent the form named gets the lead;
   without one, your CRM's own lead routing assigns it.
7. **Your agents follow up from your CRM.** The Listings API stores no leads and sends no listing
   alert emails in version 1. Saved searches and alerts are coming later.
8. **Only for a brokerage also on the Ruuster Platform:** when that CRM is connected to Ruuster,
   Ruuster reads the lead there. With the alerts box checked, the AI Nurture tags start listing
   alerts (see [AI Nurture tags](https://help.ruuster.com/idx/crm-ai-nurture)).

## What each CRM receives

| Form | Follow Up Boss | Sierra Interactive | Sure Send |
|---|---|---|---|
| Registration | A `Registration` event with the person | A new lead, then its site visit | The person, new or matched by email, then a note |
| Tour request | A `Property Inquiry` event with the listing | A new lead with the listing as a property view and the tour request in its note, then its site visit | The person, then a note with the tour request |
| Question about a listing | A `Property Inquiry` event with the listing | A new lead with the listing as a property view and the question in its note, then its site visit | The person, then a note with the question |
| Question without a listing | A `General Inquiry` event (`Seller Inquiry` for a seller) | A new lead with the question in its note, then its site visit | The person, then a note with the question |
| A registered visitor opens a listing | A `Viewed Property` event, once per person, listing and day | | |

Every request carries the visitor's first and last name, email and phone, your site name as the
source, and the AI Nurture tags only when the visitor checked the alerts box. Each CRM also gets the
request in plain words: the tour time, the listing (address, MLS number and price), your page for
that listing, the page the form was sent from, the consent sentence the visitor agreed to, and where
the visitor came from.

What each CRM takes beyond that, as its own API documents it:

| | Follow Up Boss | Sierra Interactive | Sure Send |
|---|---|---|---|
| The agent the form names | `assignedUserId` (user id) or `assignedTo` (full name) | `assignTo` by user id or email | `assignedUserId` (user id) |
| Buyer, seller or both | `Seller Inquiry` for a seller question without a listing | `leadType` 1, 2 or 3 | in the note |
| UTM values | `campaign` (source, medium, campaign, term, content) | in the note | in the note |
| Ad click ids, landing page, referrer, first and latest visit | `pageUrl`, `pageReferrer`, and all of it in `description` | a site visit (landing page and referrer), and all of it in the note | in the note |
| Listing details | `property` with your page, type, beds, baths, square feet and lot | `session.propertyViews` by MLS number | in the note |

Leave the agent out and each CRM's own routing assigns the lead.

## What your route does, in order

The example's `lib/crm.ts` holds one handler that every CRM route calls. Build yours the same way:

1. **Check the origin.** The `Origin` header must equal `SITE_ORIGIN`; otherwise answer 403.
2. **Read the body.** It must be a `LeadSubmission` (`kind` is `registration`, `tour` or `contact`).
   Trim every text field and cap its length. Anything else answers 400.
3. **Call `assertSendable(lead)`.** For a filled honeypot, answer 200 as if it worked and send
   nothing. For a missing email and phone or an unchecked contact box, answer 422 with the error's
   `message`. Sierra Interactive also needs an email, so its route answers 422 for a phone-only lead.
4. **Look up the listing** with `idx.get(lead.listing.id)` when the form names one. Build
   `listingUrl` as `SITE_ORIGIN` plus `listingPath(listing)`, or use the URL the form sent only when
   it is on `SITE_ORIGIN`.
5. **Build and send** with the helpers for your CRM, with `source` set to `SITE_NAME`. For Sure Send,
   pass one of your Sure Send stage names as `stage` (for example the stage new website leads start
   in), or null to leave the stage to Sure Send.
6. **Answer the form with a sentence it shows.** The example's sentences, which you may reword:

| When | Status | Sentence |
|---|---|---|
| Sent | 200 | Thanks. We got your request and will be in touch soon. |
| Posted from another site | 403 | Please send this form from our website. |
| Not a form the route can read | 400 | We couldn't read this form. Please refresh the page and try again. |
| A missing CRM key, or `SITE_NAME` empty or reserved | 500 | This form isn't set up yet. Please call or email us instead. |
| The CRM asked you to wait | 429, with `Retry-After` | We're getting a lot of requests right now. Please try again in 30 seconds. |
| The CRM refused the request | 502 | We couldn't send your request just now. Please try again in a minute. |

The CRM's own error goes to your server log, never to the visitor, and it never contains your key.
The helpers and their options are listed in [the SDK guide](https://help.ruuster.com/idx/guide-sdk).
To test a route without a real CRM, pass your own `fetch` as the sender's third argument.

## Listing views (Follow Up Boss only)

Listing views are a separate, optional route: `POST /api/activity/fub`, which the listing page calls
through the `ReportListingView` component. Build it when you use Follow Up Boss and want agents to see
which homes a registered visitor opens. It needs `FUB_COOKIE_SECRET`, because the registration route
sets a signed `fub_person` cookie that the listing-view route checks. Sierra Interactive and Sure Send
have no listing-view route.

## The source rule

Set `SITE_NAME` to your site's name, for example `Peach Realty`. It becomes the lead source your CRM
shows and the name Ruuster credits for the activity. The names `Ruuster` and `App` are reserved for
Ruuster's own activity, so the senders refuse them and your route answers that the form is not set
up yet.

## One listing view per person, listing and day

A visitor who registered can keep sending listing views to Follow Up Boss as they browse. The example
route sends at most one `Viewed Property` per person, listing and day, and only for a visitor whose
registration your site has already sent. Anonymous visitors send nothing to your CRM.

## Consent

Both boxes start unchecked. The contact box is required to send anything. The alerts box is separate
and optional: show it only when something sends those emails, such as your CRM's own listing emails
or AI Nurture for a brokerage also on the Ruuster Platform. When it is checked, the lead carries the
AI Nurture tags. Your own wording goes beside each box, and the exact wording the visitor
saw is saved with the lead in Follow Up Boss and Sierra Interactive. See
[Privacy and consent](https://help.ruuster.com/idx/privacy-consent) for the sentences to start from.

## Other CRMs

The same route can post to any CRM with an API. See [Other CRMs](https://help.ruuster.com/idx/crm-other).
