01
Register once
pnpm add @pact/web @pact/runtimetypescript
import { definePactElements } from '@pact/web'
definePactElements()02
Gate purpose-bound content
html
<pact-gate purpose="analytics">
<analytics-dashboard></analytics-dashboard>
</pact-gate>
<pact-preferences-button>
Privacy choices
</pact-preferences-button>03
Style the privacy control
The preference button exposes a button part, so your CSS can own its complete presentation.
css
pact-preferences-button::part(button) {
min-height: 44px;
border: 1px solid currentColor;
border-radius: 999px;
padding: 0 1rem;
font: inherit;
}04
Handle initialization failures
typescript
document.addEventListener('pact-error', (event) => {
const error = (event as CustomEvent<Error>).detail
reportIntegrationFailure(error)
})