cta-end

Package: @playerstack/plugin-cta-end (source), not published to npm yet

When the video ends (or at the start or at a set time), render an overlay with optional title, custom HTML, anchor button (label + URL + UTM), and replay. Hook into the event bus for analytics.

Quickstart

<player-stack
  src="https://youtu.be/dQw4w9WgXcQ"
  data-config='{
    "ctaEnd": {
      "enabled": true,
      "title": "Want the deep dive?",
      "button": {
        "label": "Get the course",
        "url": "https://example.com/course",
        "utm": "utm_source=playerstack&utm_medium=video"
      },
      "showReplay": true
    }
  }'
>
</player-stack>

When the card appears

By default the card appears when the video ends. Despite the package name, it can also appear at the start or during playback:

Setting The card appears
none, at: "end" When the video ends
at: "start" When playback starts from the beginning (within the first 2 seconds)
at: 90 When playback reaches second 90
atPercent: 50 When playback reaches half of the duration (ignored when at is also set)

"start" and timed cards pause the video, hold it paused while the card is open (also if the email gate or the page calls play()), and add a skip button; skip and Escape close the card and resume playback.

The standalone script downloads playerstack-cta-end-timed.js only when at, atPercent or frequency is set. If that download fails, the error is logged and no card is shown; playback continues.

{
  "ctaEnd": {
    "enabled": true,
    "at": 90,
    "frequency": "session",
    "title": "Halfway there",
    "button": {
      "label": "Get the course",
      "url": "https://example.com/course"
    },
    "skipLabel": "Keep watching"
  }
}

Config

config.ctaEnd:

Field Type Description
enabled boolean Plugin is a no-op unless true
title string? Heading text inside the overlay
html string? HTML filtered through core sanitizeHtml before rendering (see rules below)
button.label string Visible button text
button.url string Destination URL
button.utm string? Query string appended to URL (e.g. utm_source=...)
showReplay boolean? Render a “Replay” button that re-plays the video and dismisses the overlay
at “start” | “end” | number? When to show the card (see above); a number is seconds. Default "end"
atPercent number? Show at this percent (0-100) of the duration; ignored when at is set
frequency “playback” | “session”? How often the card may appear
skipLabel string? Skip button text on start and timed cards (default "Skip")

Events

Name Payload When
cta:show { at } or { atPercent } The card appears; only when at, atPercent or frequency is set
cta:skip { at } or { atPercent } The viewer skips a start or timed card
cta:click { label: string, url: string } User clicks the CTA button
cta:replay undefined User clicks the replay button

analytics forwards all four by default. To count plain end cards too, set at: "end".

ctx.events.on("cta:click", ({ label, url }) => {
  navigator.sendBeacon(
    "/api/track",
    JSON.stringify({
      event: "cta_click",
      label,
      url,
    }),
  );
});

Styling

The overlay uses CSS variables you can override:

Use controls-policy to set these per-player, or define them globally in your stylesheet.

HTML rendering rules

html passes through core’s sanitizeHtml before the resulting fragment is assigned to innerHTML.

This is a browser DOM-based rendering allowlist; without document, the helper returns an empty string. URL host policy and server-side validation remain the integrator’s responsibility.

Scrolling content

Buttons are at least 44 px tall. The main button text is white or black, whichever contrasts better with --ps-accent. While the email form covers the player, the card is hidden and appears when the form closes.

End cards are bounded by the player height and scroll inside their own overlay when content is too tall. Content stays centered when it fits and begins at the top when it overflows. Keyboard focus and pointer/touch scrolling do not move the player content.