leads: new phone number and an amoCRM lead on every call-button click

The published number becomes +7 927 789-60-71 across all four landings —
`contacts` in each `src/data/content.ts`, plus the fallback messages in the
lead endpoints and `src/lib/lead.ts` that spell it out when amoCRM is down.
The `legacy/` reference pages keep the old number: they are the visual
originals, not something that ships.

Tapping the phone button now also creates a lead. It cannot reuse the form
path: a click carries no name and no number, so `callClickSchema` in
`shared/lead.ts` validates the tracking data alone, `LeadService.submitCallClick`
creates a contactless lead tagged `клик по телефону`, and `AmoClient.createLead`
takes an optional `contactId` for it. The mapper's field/note split moved into
`collect()` so both lead kinds share it.

The browser fires this with `sendBeacon` (falling back to `fetch keepalive`),
because the same click hands the page to `tel:` and a plain fetch would be
cut off mid-flight. Duplicates are held down from both ends: one lead per
browser session on the client, four per IP per 30 minutes on the server.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Yuriy Panov
2026-09-09 00:58:15 +06:00
co-authored by Claude Opus 5
parent e7385e8898
commit e13854e918
39 changed files with 1059 additions and 106 deletions
+6 -2
View File
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState, type FormEvent } from 'react'
import { contacts } from '../data/content'
import { useBodyLock } from '../hooks/useBodyLock'
import { useEscapeKey } from '../hooks/useEscapeKey'
import { submitLead } from '../lib/lead'
import { reportCallClick, submitLead } from '../lib/lead'
import { cx } from '../lib/cx'
import { Button } from './Button'
import { ConsentCheckbox, Honeypot, TextField } from './FormField'
@@ -89,7 +89,11 @@ export function CallbackModal({ open, onClose }: { open: boolean; onClose: () =>
</h3>
<p className="mb-[20px] text-[13px] text-muted">
Оставьте имя и телефон специалист свяжется и ответит на вопросы по зоне восстановления. Или позвоните сами:{' '}
<a className="font-extrabold text-navy underline underline-offset-[3px]" href={contacts.phoneHref}>
<a
className="font-extrabold text-navy underline underline-offset-[3px]"
href={contacts.phoneHref}
onClick={reportCallClick}
>
{contacts.phone}
</a>
.
+4 -1
View File
@@ -1,4 +1,5 @@
import { contacts } from '../data/content'
import { reportCallClick } from '../lib/lead'
import { Container } from './Layout'
export function SiteFooter() {
@@ -11,7 +12,9 @@ export function SiteFooter() {
Российские технологии реабилитации
</div>
<div className="flex flex-wrap gap-[16px] [&>a:hover]:text-white">
<a href={contacts.phoneHref}>{contacts.phone}</a>
<a href={contacts.phoneHref} onClick={reportCallClick}>
{contacts.phone}
</a>
<a href={`mailto:${contacts.email}`}>{contacts.email}</a>
<a href={contacts.siteHref} rel="noopener" target="_blank">
{contacts.site}
+2 -2
View File
@@ -4,8 +4,8 @@ import galleryPt from '../assets/images/gallery-pt-stretch.webp'
import galleryFlagship from '../assets/images/gallery-flagship.webp'
export const contacts = {
phone: '+7 939 717-80-80',
phoneHref: 'tel:+79397178080',
phone: '+7 927 789-60-71',
phoneHref: 'tel:+79277896071',
email: 'info@exotherapy.ru',
site: 'экзотерапия.рф',
siteHref: 'https://экзотерапия.рф',
+79 -3
View File
@@ -1,4 +1,10 @@
import { utmKeys, type LeadFormId, type LeadInput, type LeadResponse } from '../../shared/lead'
import {
utmKeys,
type CallClickInput,
type LeadFormId,
type LeadInput,
type LeadResponse,
} from '../../shared/lead'
const ENDPOINT = '/api/leads/fitness-centers'
const DRAFT_KEY = 'exo_fitness_lead_draft'
@@ -46,7 +52,7 @@ export async function submitLead(form: LeadFormId, values: Omit<LeadInput, 'form
error:
body && !body.ok
? body.error
: 'Не удалось отправить форму автоматически. Данные сохранены в браузере — свяжитесь с нами по +7 939 717-80-80.',
: 'Не удалось отправить форму автоматически. Данные сохранены в браузере — свяжитесь с нами по +7 927 789-60-71.',
fields: body && !body.ok ? body.fields : undefined,
}
}
@@ -61,7 +67,7 @@ export async function submitLead(form: LeadFormId, values: Omit<LeadInput, 'form
return {
ok: false,
error:
'Не удалось отправить форму автоматически. Данные сохранены в браузере — свяжитесь с нами по +7 939 717-80-80.',
'Не удалось отправить форму автоматически. Данные сохранены в браузере — свяжитесь с нами по +7 927 789-60-71.',
}
}
}
@@ -74,6 +80,76 @@ function saveDraft(payload: LeadInput) {
}
}
/* -------------------------------------------------------------------------- */
/* Клик по кнопке звонка */
/* -------------------------------------------------------------------------- */
const CALL_ENDPOINT = `${ENDPOINT}/call`
const CALL_SENT_KEY = 'exo_fitness_call_click_sent'
/** Session-scoped so a visitor who redials is still one lead, not three. */
function callAlreadyReported(): boolean {
try {
return sessionStorage.getItem(CALL_SENT_KEY) === '1'
} catch {
// Private-mode browsers throw on access; one extra lead beats none.
return false
}
}
function markCallReported() {
try {
sessionStorage.setItem(CALL_SENT_KEY, '1')
} catch {
// See above.
}
}
/**
* Registers a tap on the phone button as an amoCRM lead.
*
* Fire-and-forget by necessity: the same click hands the page to `tel:`, so the
* request has to outlive the document. `sendBeacon` queues it in the browser
* process itself; `keepalive` is the fallback for the few browsers without it.
* Nothing here may throw or await — the dialler must open instantly.
*/
export function reportCallClick(): void {
if (callAlreadyReported()) return
markCallReported()
const payload: CallClickInput = {
page: window.location.pathname,
referrer: document.referrer || undefined,
utm: collectUtm(),
}
// A Blob, not a string: it is what gives the beacon its JSON content type.
const beacon = new Blob([JSON.stringify(payload)], { type: 'application/json' })
// sendBeacon returns false when the browser refuses to queue the payload, and
// a few throw instead of returning anything. Either way, fetch picks it up.
let queued = false
try {
queued = navigator.sendBeacon?.(CALL_ENDPOINT, beacon) ?? false
} catch {
queued = false
}
if (!queued) {
void fetch(CALL_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
keepalive: true,
}).catch((error: unknown) => {
console.warn('Call click endpoint error', error)
})
}
window.dataLayer = window.dataLayer ?? []
window.dataLayer.push({ event: 'fitness_call_click' })
}
declare global {
interface Window {
dataLayer?: Record<string, unknown>[]