React Scripts and embeds
Embeds
Pick a method
| Method | Use it when |
|---|---|
ConsentGate | You render the iframe in a React component and want a placeholder until the visitor allows its category. |
| The iframe blocker | The iframe comes from markup you do not render with React, such as CMS or Markdown content. |
Both keep the iframe's src out of the page until the category is allowed, so
the embed's host receives no request before consent.
Gate an embed with ConsentGate
Wrap the iframe in ConsentGate anywhere inside ConsentProvider:
The iframe is absent from the page until the visitor allows measurement. The
placeholder shows a message and a
ConsentDialogLink
until then. When the visitor withdraws measurement, React removes the iframe.
Pick the category that matches what the embed does. The example uses measurement for YouTube because its player measures views. A map or chat widget usually belongs under functionality or experience. ConsentGate documents the built-in placeholder and every prop.
Gate an iframe with the iframe blocker
ConsentProvider runs the iframe blocker by default. Give an iframe
data-src instead of src, and a data-category:
c15t sets src from data-src when the category is allowed and removes src
when the category is withdrawn. It watches the page, so iframes added later
are handled too. Add data-vendor with a vendor ID to also block the iframe
while the visitor has turned that vendor off.
To turn the blocker off, set iframeBlocker: false in the provider options.
Verify the embeds
Open the production build in a private window with DevTools open, under a policy that asks for consent.
- No iframe has a
srcpointing atyoutube-nocookie.comorgoogle.com/maps, and the Network panel shows no request to them. - Allow the embed's category and save. The iframe loads.
- Withdraw the category and save. The page reloads without the embed.
The YouTube and Google Maps guides cover sizing and titles.