teqo/src/utilities/campaignHomeTracking.ts
Francisco Solla e339ceec9f
All checks were successful
CI (PR) / checks (pull_request) Successful in 19m11s
PR Ready + auto-merge / ready-automerge (pull_request) Successful in 19m30s
Promote plan-issue Related on main merge / plan-issue-ready (pull_request) Has been skipped
Main merge flips claimed issues to done + in-prod / issue-done (pull_request) Successful in 8m12s
feat(S10): pixel do Meta na página pública de campanha (campo admin em SiteSettings + PageView na home + Lead no sucesso da captura)
Campo tracking.facebookPixelId no global SiteSettings (mesma validação/normalização do precedente Petition, regra centralizada em facebookPixel.ts); home (grupo (home)) injeta o base code + PageView quando o ID está configurado (fail-closed) e o CampaignNewsletterForm dispara exatamente um Lead no sucesso do S9. Migration 20260819_213947_add_site_settings_facebook_pixel_id. Closes #94
2026-08-19 19:27:00 -03:00

15 lines
676 B
TypeScript

import 'server-only'
import { normalizeFacebookPixelId } from '@/lib/facebookPixel'
import { getCachedGlobal } from '@/utilities/globalReads'
/**
* S10 — the Meta pixel configured in `SiteSettings.tracking` for the public
* campaign page. Cached under `global_site-settings`, so an admin edit of the
* global already revalidates the home (the `afterChange` hook busts the tag).
* Fail-closed: no configured ID → null → nothing renders on the page.
*/
export const getCampaignHomeMetaPixelId = async (): Promise<string | null> => {
const settings = await getCachedGlobal('site-settings')()
return normalizeFacebookPixelId(settings.tracking?.facebookPixelId)
}