Skip to content
ComponentsGatedFrame

GatedFrame for Nuxt

Markdown
Loading…

Show a third-party iframe only after the visitor consents, with a placeholder until then.

What it does

Renders a placeholder instead of the iframe until its category is granted. The placeholder says which cookies are needed and has a button that opens the preferences dialog. Once the visitor agrees, the iframe appears in its place, without a reload.

Use it for embeds that set cookies: YouTube, Vimeo, Google Maps, Spotify, social posts, Calendly. For iframes in HTML you do not render yourself, such as CMS or Markdown content, use Block embeds.

Add it

app/components/VideoEmbed.vue
<template>
  <GatedFrame
    src="https://www.youtube.com/embed/dQw4w9WgXcQ"
    category="functional"
    :width="560"
    :height="315"
    title="Product tour"
  />
</template>

GatedFrame is auto-imported, and so is your VideoEmbed component: use <VideoEmbed /> in any page.

Video and map embeds are usually functional; social and ad embeds are usually advertisement. The category must exist in your categories list.

Props

NameTypeDefaultDescription
srcrequiredstringNone

The iframe URL, used once category is allowed. Kept separate from ...rest because it is always required, unlike the other native iframe attributes.

If omitted: Required. Omitting it is a type error under vue-tsc and a Vue warning in development: there is no default.

categoryrequiredConsentCategoryNone

The consent category that gates rendering the real iframe.

If omitted: Required. Omitting it is a type error under vue-tsc and a Vue warning in development: there is no default.

#placeholderoptional() => unknownNone

Slot with custom content shown instead of the iframe until consent for category is granted, replacing our default placeholder text and button entirely.

If omitted: Shows our own default placeholder (translatable via the gatedFrame.placeholder and gatedFrame.action keys) and a button that opens preferences.

...restoptionalOmit<IframeHTMLAttributes, "src" | "category">None

Every other standard <iframe> attribute (width, height, title, allow, sandbox, and so on, other than src, documented above). They are applied to the <iframe> once it is allowed to render.

If omitted: No extra iframe attributes are applied beyond src.

Every other <iframe> attribute (width, height, title, allow, ...) is passed to the iframe once it appears.

Change the placeholder

Fill the placeholder slot with your own content. It is rendered inside the placeholder box, .cy-frame-placeholder:

app/components/VideoEmbed.vue
<script setup lang="ts">
const { showPreferences } = useConsentActions();
</script>

<template>
  <GatedFrame
    src="https://www.youtube.com/embed/dQw4w9WgXcQ"
    category="functional"
    :width="560"
    :height="315"
    title="Product tour"
  >
    <template #placeholder>
      <div class="video-placeholder">
        <p>This video is hosted by YouTube and needs functional cookies.</p>
        <button type="button" @click="showPreferences">Cookie settings</button>
      </div>
    </template>
  </GatedFrame>
</template>

To only change the default text, set gatedFrame.placeholder and gatedFrame.action in i18n; see Translations. To style the default placeholder, target .cy-frame-placeholder in your CSS.

Good to know

Give the placeholder the same size as the iframe, or the page jumps when it swaps. Once the iframe has appeared, withdrawing consent does not remove it in the current page; it is blocked again on the next page load.

Common mistakes

The embed never appears, even after accepting. The category is not in your categories list, or the visitor granted a different one. A development build names an unknown category in the console.

The placeholder flashes on every load, even after consent. Expected: consent is only known in the browser, so the placeholder renders first. Give it the iframe's size so nothing moves.

Next steps

On this page