# Advertising.net

Marketing site for Advertising.net, on the same stack as Advertising.com: Next.js 16 (App Router, Cache Components), React 19, Prisma on MySQL, ZeptoMail, HubSpot, Slack, PM2.

## Run it

```bash
npm ci
cp .env.example .env        # set DATABASE_URL to this site's own database
npx prisma db push
npm run dev
```

`MAIL_TRANSPORT=log` (the `.env.example` default) writes every email to the console and `.mail-log/` instead of sending it, so no ZeptoMail token is needed locally.

## Deploy

```bash
npm ci && npm run build
npx prisma db push          # only when prisma/schema.prisma changed
pm2 start ecosystem.config.js    # or: pm2 reload ecosystem.config.js
```

This site has its own `advertising_net` database. Only run `prisma db push` against that database, because it drops any table that isn't in this schema. `advertising_dev` belongs to Advertising.com.

Staging runs at `staging.advertising.net` on port 8015, with the DSP at `platform.admedia.advertising.com`. Those hosts are set in the server `.env` only. `NEXT_PUBLIC_*` values are baked in at build time, so rebuild after changing them. Set `ALLOW_INDEXING=true` on production only; without it every page is noindex and `robots.txt` blocks all crawlers.

## How the code is organised

| Path | What it holds |
| --- | --- |
| `src/app/*/page.tsx` | One route per design page. Content pages were converted from the rendered design, so edit their copy directly. |
| `src/app/signup`, `contact`, `blog`, `login`, `forgot-password` | Hand-built pages that read the URL or submit forms. |
| `src/lib/channels.ts` | Channels, goals and sales team used by the header, footer and forms. |
| `src/content/blog-posts.ts` | Blog articles. |
| `src/components/SiteEffects.tsx` | Behaviour for the design markup: menus, tabs, filters, reveal and mock-up rotators. |
| `src/components/FormRuntime.tsx`, `src/lib/form-submit.ts` | Form validation, submission and follow-ups. |
| `src/styles` | Design stylesheets (`an*.css`, `ad-mockups.css`, `utilities-inline.css`) and `forms.css` for live form states. |

Channel names in the content pages are static copies, so a rename needs both `src/lib/channels.ts` and the page.

## Sign up and log in

These follow Advertising.com:

- **Sign up** links go to the white-labeled DSP's create-account page when `NEXT_PUBLIC_PLATFORM_URL` is set, and `/signup` redirects there. With it unset, the local `/signup` form saves an `AccessRequest` and sends the Slack notice, confirmation email and HubSpot contact.
- **Log in** links go to the white-labeled DSP when `NEXT_PUBLIC_PLATFORM_URL` is set, and `/login` and `/forgot-password` redirect there. With it unset, the local pages record the attempt only.
- **Signed-in state** in the header comes from `{platform}/api/auth/me` using the DSP's HttpOnly cookie. That cookie is `SameSite=Lax`, so the DSP must run on an `advertising.net` host. On any other domain, visitors simply appear signed out.
- **White-label:** `platform.advertising.net` and `platform-staging.advertising.net` are the same `ui.dsp.com` and `api.dsp.com` that serve ad.com. The `advertising-net` tenant in `dsp_tenant` sets the branding, and this site's hosts are in `dsp_tenant_domain`, which is what allows its CORS requests.

**Talk to Sales** (`/contact`) saves a `SalesInquiry` and never creates an account. After the response it emails the inquiry to `CONTACT_INBOX` (support requests, `/contact?topic=support`, to `SUPPORT_INBOX` when set), with Reply-To set to the sender. The row is saved first and `mailStatus` records the email: `failed` rows, with the reason in `mailError`, are inquiries the team wasn't told about. The server re-checks every field, drops submissions that fill the hidden `fax` honeypot, and allows 100 inquiries per IP per hour (`RateLimit` table). It then sends the sender a confirmation and creates or updates their HubSpot contact. It sends nothing to Slack.

HubSpot is off until `NEXT_PUBLIC_HUBSPOT_PORTAL_ID` and `HUBSPOT_ACCESS_TOKEN` are set. Each sign-up or inquiry updates the contact with that email, or creates one if none exists. New contacts get Lifecycle Stage Lead. A later form never overwrites a name, company or website the contact already has. First- and last-touch lead source are worked out from their own visits. A HubSpot failure is logged as `hubspot: … not synced` and never fails the form.

Off production, confirmation emails go only to addresses in `PROSPECT_EMAIL_ALLOW`.

**Lead tracking (HUB-753).** Every link to `/contact` or `/support` carries `?from=<page of the click>` (added by `src/components/Link.tsx`), saved on the contact as `ctx_origin_page`; a direct visit leaves it empty. Each lead also gets the button clicked in this site's own `adv_placement` (Contextual.com uses `ctx_placement`, Remarketing.com `rm_placement`, so views never mix sites), plus the shared `ctx_topic` (sales or support), `ctx_role`, `ctx_site` (`advertising.net`), `ctx_environment` and `hs_lead_status` = `NEW` on arrival. Owner and lead status are never overwritten on a later form. The properties must exist in the portal before deploying: `HUBSPOT_ACCESS_TOKEN=... node scripts/hubspot-ctx-properties.mjs --apply` (dry run without `--apply`; safe to run again).

**Test leads never reach people.** The site counts as production only with `ALLOW_INDEXING=true` and `NEXT_PUBLIC_SITE_URL` on advertising.net; anything else sends `ctx_environment` = `staging` or `local`. A lead that picks a rep (`?rep=`) is assigned to that rep on every environment, so QA can test routing on staging; a staging test that picks a rep reaches the real rep. HubSpot workflows that assign owners or send email must enroll only contacts with `ctx_environment` = `production`.

**Google Ads (ARB-274).** On production, the `AW-11246334055` tag loads only for a visit that landed with a valid `gclid`, and stays eligible for that browser session. The lead conversion fires after a successful Send inquiry on `/contact`, not on `/support`.

## Before production

- Publish approved Terms of Use (`/terms` is a placeholder) and have Legal confirm the Privacy Policy and Ad Policies.
- Replace the sample blog posts.
- Confirm that `support@advertising.net` and `sales@advertising.net` exist.
- Set `MAIL_TRANSPORT=zeptomail` with a token for a ZeptoMail agent whose verified domain covers `MAIL_FROM_ADDRESS`.
