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.
- Seeking and resuming. A timed card appears as soon as the position is at or past the point, however it got there: normal playback, a seek, or a position restored by saved-position. Seeking back does not repeat it.
- Start card and saved position. When playback begins further in than 2 seconds (a restored position, a deep link), the start card is dropped for that playback, so it never interrupts the middle of the video.
- Autoplay preview. While
preview.enabledplays the main video muted (nopreview.src), start and timed cards wait; they apply once the viewer unmutes or starts the video with sound. - Email gate. The gate sits above the card. When both are due at once, the viewer passes the gate first and then sees the card, with the video still paused.
- Frequency.
"playback"(default for start and timed cards) shows the card once per loaded source."session"shows it once per browser tab session for the samesrc(sessionStorage; without storage it behaves like"playback"). End cards appear on everyendedunlessfrequencyis set.
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:
--ps-accent— button background--ps-bg-opacity— overlay backdrop opacity
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.
- Allowed elements:
a,b,br,code,em,h3–h6,i,li,ol,p,small,span,strong,sub,sup,u, andul. - Allowed attributes on those elements:
class(except names starting withplayerstack),aria-*, androle; anchors may also havehref.data-*attributes are removed, because scripts on the host page may act on them. Event attributes (on*),style,id, and other attributes are removed. - Anchor
hrefmust parse as an absolute HTTP(S) URL. Other values, including relative URLs and fragments, losehref. Anchors with an acceptedhrefgettarget="_blank"andrel="noopener noreferrer". - The walk removes comments. When it encounters a disallowed element,
script,style,iframe,noscript,object, andembedare removed with their contents; other disallowed elements are replaced by a plain text node containing theirtextContent.
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.