Black Friday sale: 25% off your first year on annual plans. Ends Dec 6. Start your trial

Setup & Installation

Configure SmartVideo with swarmoptions

Updated November 23, 2026

swarmoptions is the settings object every SmartVideo player on the page reads. It is where you set your Swarm CDN Key, choose which videos SmartVideo takes over, and style the player to match your brand.

It applies to the page it is on. Because the snippet normally lives in a shared site template or theme header, that usually means every page of your site — but if you paste it into a single page, only that page is affected.

You don’t have to write this by hand. The Player page in your dashboard provides the Global install snippet and player settings. This article is the reference for what those settings produce, so you can read the generated code, extend it with options the configurator doesn’t cover, or write it yourself.

If you only want to change one video, use the data-swarm-setup attribute instead.

On this page

Where swarmoptions goes

Declare it in your site’s <head>, above the loader script:

<script data-cfasync="false">
    var swarmoptions = {
        swarmcdnkey: "YOUR_SWARM_CDN_KEY",
        iframeReplacement: "iframe",
        autoreplace: {
            youtube: true,
            vimeo: true
        }
    };
</script>
<script async data-cfasync="false" src="https://assets.swarmcdn.com/swarmcdn.js"></script>

Replace YOUR_SWARM_CDN_KEY with the API key from the Profile section of the Account page in your dashboard.

Keep data-cfasync="false" on both tags. It tells Cloudflare’s Rocket Loader to leave them alone, which has broken playback on customer sites in the past.

If you are installing SmartVideo for the first time, start with the installation guide for your platform — this article is the reference for what you can put inside the object once it is there.

How the options are organized

Options include your account options (swarmcdnkey, iframeReplacement) and five optional groups: autoreplace, theme, player, plugins, and ga. swarmcdnkey is the only one you always need — the rest are optional, though a feature you do turn on may have required fields of its own (a watermark needs a file, for example).

<script data-cfasync="false">
    var swarmoptions = {
        swarmcdnkey: "YOUR_SWARM_CDN_KEY",   // your account key
        autoreplace: { },                    // which videos SmartVideo takes over
        theme: { },                          // how the player looks
        player: { },                         // control bar and playback speed
        plugins: { },                        // keyboard, watermark, banners, ads
        ga: { }                              // Google Analytics events
    };
</script>

Option names are case-sensitive. primaryColor works; primarycolor is ignored.

Account options

Option Type Default What it does
swarmcdnkey string — Your Swarm CDN Key. Required — without it the player never starts.
iframeReplacement "video" or "iframe" "video" How a replaced YouTube embed is rebuilt. The name has no YouTube prefix for backward compatibility; for Vimeo embeds use vimeoIframeReplacement under autoreplace (below). For supported YouTube and Vimeo embeds, the per-element form, iframeReplacement inside a data-swarm-setup attribute, overrides the replacement mode.

Choose which videos SmartVideo takes over

These live under autoreplace.

Option Type Default What it does
smartvideotag boolean true Scan the page for <smartvideo> tags. On unless you turn it off.
youtube boolean false Replace YouTube and Vimeo embeds with a SmartVideo player. YouTube conversion is best-effort — see the note below.
vimeo boolean false Replace YouTube and Vimeo embeds with a SmartVideo player.
youtubecaptions boolean false Import the caption track from the source video. Confirmed for Vimeo; for YouTube, see the note below.
videotag boolean false Accelerate plain <video> tags — this is how you speed up background and hero videos.
vimeoIframeReplacement "video" or "iframe" "video" How a replaced Vimeo embed is rebuilt. "video" swaps in a real SmartVideo player. "iframe" keeps an iframe wrapper, which some page builders need.

youtube and vimeo work as one switch: turning on either one replaces both YouTube and Vimeo embeds, which is why the dashboard sets both together. To keep a single embed as it is, add class="swarm-exclude" to its iframe.

Accelerating plain <video> tags with videotag is available on the Growth and Pro plans. See plans and pricing.

Note on YouTube: YouTube conversion is best-effort: YouTube’s download restrictions mean the fetch can fail, so some videos convert and some don’t. For playback you can rely on, download the file and upload it to your SmartVideo library through your SmartVideo dashboard. Whether captions come across for a YouTube video that did convert is not something we can promise today. See Can I use YouTube videos? for the full picture.

<script data-cfasync="false">
    var swarmoptions = {
        swarmcdnkey: "YOUR_SWARM_CDN_KEY",
        autoreplace: {
            vimeo: true,
        }
    };
</script>

Style the player

These live under theme and apply to every player on the page. To style one video differently, put a theme object with the same keys in that video’s data-swarm-setup attribute; keys it leaves out keep the values set here.

Option Type Default What it does
primaryColor any CSS color player default Accent color: play button, progress bar, active controls. See customize player color.
secondaryColor any CSS color player default Companion color used against the primary.
glassTint whole number 0–15 3 How much of your primaryColor is mixed into the frosted-glass control bar. 0 leaves it neutral, 15 is the strongest tint. Because it tints toward your own color, a light primaryColor makes the bar lighter, not darker.
cornerRadius CSS length player default Rounds the corners of the player itself, e.g. "24px" or "0px".
button string or object "hexagon" Play button shape. See customize play button shape.
button.shape "hexagon", "rectangle", or "circle" "hexagon" Shape, when you pass an object.
button.borderRadius CSS length 16px for hexagon and circle, 8px for rectangle Rounds the button’s own corners.

button accepts a bare shape name (button: "circle") when you don’t need to set the radius.

<script data-cfasync="false">
    var swarmoptions = {
        swarmcdnkey: "YOUR_SWARM_CDN_KEY",
        theme: {
            primaryColor: "#ffde17",
            glassTint: 3,
            cornerRadius: "24px",
            button: {
                shape: "hexagon",
                borderRadius: "16px"
            }
        }
    };
</script>

A numeric glassTint outside 0–15 is pulled back to the nearest end of the range silently. A glassTint that isn’t a number falls back to 3, and an unrecognized shape falls back to hexagon; both of those write a warning to your browser console rather than failing.

Player controls and playback speed

These live under player and apply to every player on the page. The Player page in your dashboard has controls for playbackRates, skipSeconds and hideControls under Playback and adds your choices to the snippet. doubleTapSeek has no control there — add it to the snippet by hand.

Option Type Default What it does
playbackRates array of numbers [0.5, 0.75, 1, 1.25, 1.5, 2] The speeds the playback-rate button steps through, in the order you list them.
skipSeconds number 10 How far the skip-back and skip-forward buttons jump. One number, used by both.
hideControls array of strings nothing hidden Removes controls from the control bar. See Hidden controls for the accepted names.
doubleTapSeek boolean on The touch double-tap seek on the left and right of the picture. Set it to false to turn the gesture off. See Double-tap seek.
<script data-cfasync="false">
    var swarmoptions = {
        swarmcdnkey: "YOUR_SWARM_CDN_KEY",
        player: {
            playbackRates: [1, 1.25, 1.5, 2],
            skipSeconds: 15,
            hideControls: ["pictureInPicture"]
        }
    };
</script>

All four can also be set one video at a time with data-swarm-setup, where the per-video value replaces the site-wide one for that key.

Playback speeds

There is no list to pick from. The playback-rate button steps to the next rate in your list on each click and wraps around at the end, so the order you write is the order viewers get.

  • Include 1 in the list. Playback starts at 1x. When the current rate isn’t in your list, the button returns to 1 if present, or otherwise jumps to the first entry; a list without 1 can never get back to normal speed.
  • Don’t repeat a rate. The button jumps to the entry after the first match, so a duplicate traps the cycle — with [1, 1, 2] the button never leaves 1x.
  • Rates closer together than 0.01 are treated as the same rate.
  • An empty list, or any value that isn’t an array of numbers, is ignored and the six built-in speeds come back. playbackRates: [] is not a way to switch the control off — use hideControls: ["playbackRate"] for that.

Skip seconds

skipSeconds moves both skip buttons together and updates the number printed on each one.

  • It changes those two buttons only. Arrow-key seeking is plugins.keyboard.seekStep (5 seconds), J and L are seekStepLarge (10 seconds), and the mobile double-tap gesture always jumps 10 seconds (you can turn that gesture off — see Double-tap seek).
  • 0 is treated as unset and gives you 10 back.
  • A negative number is not rejected. -5 makes the forward button seek backward and prints -5 on it.
  • If you hide one of the two skip buttons, only the remaining one is relabeled.

Hidden controls

hideControls takes an array of strings, and only these five names do anything:

Name Control
skipForward Skip-forward button
skipBackward Skip-back button
playbackRate Playback-speed button
fullscreen Fullscreen button
pictureInPicture Picture-in-Picture button
  • Names are case-sensitive, and anything else in the list is ignored without a warning — check the spelling first if a control stays put. A value that isn’t an array of strings is rejected outright with a console message, and nothing is hidden.
  • fullscreen, playbackRate, and pictureInPicture are removed from the three-dot overflow menu on narrow players as well. skipForward and skipBackward only ever appear on the control bar, so there is nothing to remove from the menu.
  • Hiding a control removes the button, not the feature. With fullscreen hidden, the F key still works and so does double-clicking the player (double-tapping the middle of it on touch).
  • The three-dot overflow button itself can’t be hidden.
  • The overflow menu’s Picture-in-Picture item is only built when the browser supports Picture-in-Picture and the video plays through a real <video> element, so it is absent on YouTube and Vimeo embeds whether or not you hide it.

Double-tap seek

On a touchscreen, a double-tap on the left third of the picture goes back 10 seconds and a double-tap on the right third goes forward 10 seconds. It is easy to set off by accident when tapping twice to show and hide the controls — see Why does my video jump forward 10 seconds?. doubleTapSeek: false turns it off.

  • Only the boolean false turns it off. Any other value, including the string "false", leaves the gesture on, and no console message tells you so.
  • A double-tap in the middle of the picture still enters or leaves fullscreen.
  • A mouse is unaffected: a double-click toggles fullscreen and never seeks, with or without this setting.
  • On phones and tablets the skip buttons aren’t shown on the control bar, so with the gesture off the progress bar is how viewers move through the video there.

Keyboard shortcuts

Keyboard shortcuts are on by default — you only need plugins.keyboard to change or disable them.

Option Type Default What it does
enabled boolean true Set to false to turn all shortcuts off.
seekStep seconds 5 How far the left and right arrow keys jump.
seekStepLarge seconds 10 How far the J and L keys jump.
volumeStep 0–1 0.05 Volume change per up/down arrow press.
frameStep seconds 0.04 Frame-step size, roughly one frame at 25fps.
enableMute boolean true The M key.
enableFullscreen boolean true The F key.
enableNumbers boolean true Keys 0–9 jump to that percentage of the video.
enableCaptions boolean true The C key.
restoreFocus boolean true Return keyboard focus to the player after a control is clicked.
<script data-cfasync="false">
    var swarmoptions = {
        swarmcdnkey: "YOUR_SWARM_CDN_KEY",
        plugins: {
            keyboard: {
                seekStep: 10,
                enableNumbers: false
            }
        }
    };
</script>

To switch shortcuts off entirely:

plugins: {
    keyboard: { enabled: false }
}

Google Analytics

These live under ga, at the top level of swarmoptions, not inside plugins. SmartVideo sends events through your site’s existing gtag function; these options do not install Google Analytics. Tracking is on by default: all nine event types below are enabled without any ga settings, and SmartVideo sends each event when its action occurs and gtag is available in the player’s window. YouTube and Vimeo embeds replaced in iframe mode run in their own frame, so a gtag loaded on your page doesn’t reach them. To stop SmartVideo sending events, set eventsToTrack: [].

Option Type Default What it does
eventsToTrack array of strings all nine events below Which video events to send. Unknown names are dropped without a warning unless debug is on; [] sends nothing.
percentsPlayedInterval number 10 Percentage-point interval between playback progress milestones. Use a positive number. 0 is treated as unset: a per-video interval is used if present, otherwise the interval is 10 percentage points.
debug boolean false Log analytics detection and event activity to the browser console.

The supported events are video_start, video_complete, video_progress, video_play, video_pause, video_seek, video_volume, video_fullscreen, and video_error.

ga: {
    eventsToTrack: ["video_start", "video_complete", "video_progress"],
    percentsPlayedInterval: 25,
    debug: false
}

Add a brand watermark

Available on the Pro plan. See plans and pricing.

plugins.watermark puts your logo over every player.

Option Type Default What it does
file image URL — Required. The logo to display. Nothing renders without it.
xpos 0, 50, or 100 0 Horizontal position: 0 left, 50 center, 100 right.
ypos 0, 50, or 100 0 Vertical position: 0 top, 50 middle, 100 bottom.
opacity 0–100, or 0–1 100 How solid the logo is. Both scales are accepted.

The two values combine into nine positions:

ypos / xposxpos: 0xpos: 50xpos: 100
ypos: 0top-lefttoptop-right
ypos: 50leftcenterright
ypos: 100bottom-leftbottombottom-right
<script data-cfasync="false">
    var swarmoptions = {
        swarmcdnkey: "YOUR_SWARM_CDN_KEY",
        plugins: {
            watermark: {
                file: "https://your-site.example.com/logo.png",
                xpos: 100,
                ypos: 0,
                opacity: 75
            }
        }
    };
</script>

The watermark appears over the poster image before playback starts and stays for the whole video.

Add a promo banner

Available on the Growth and Pro plans. See plans and pricing.

plugins.overlay shows timed HTML over the player — a discount, a link, a call to action. Each entry in overlays is one banner.

Option Type What it does
content HTML string What the banner shows.
align top, bottom, top-left, top-right, bottom-left, bottom-right, center Where it sits.
start seconds, or "play" When it appears.
end seconds When it disappears. Leave it out to keep the banner up.
<script data-cfasync="false">
    var swarmoptions = {
        swarmcdnkey: "YOUR_SWARM_CDN_KEY",
        plugins: {
            overlay: {
                overlays: [
                    {
                        content: "<a href='https://your-site.example.com/sale'>Limited time: 20% off</a>",
                        align: "bottom",
                        start: 3,
                        end: 15
                    }
                ]
            }
        }
    };
</script>

content is raw HTML, so mind your quotes: the example uses single quotes for the link’s href because the whole string is already wrapped in double quotes. If your banner text contains an apostrophe, that is fine here — but see the per-video article before copying banner HTML into a data-swarm-setup attribute, where apostrophes need more care.

Watermarks and banners share one overlay layer, so you can use both at once.

Run video ads

Available on the Pro plan. See plans and pricing.

plugins.swarmads takes a VAST or VPAID tag URL. Setup and ad-network specifics are covered in ad network integration.

plugins: {
    swarmads: {
        adTagUrl: "https://your-ad-server.example.com/vast.xml"
    }
}

Worked example: brand the player and take over every embed

<script data-cfasync="false">
    var swarmoptions = {
        swarmcdnkey: "YOUR_SWARM_CDN_KEY",
        iframeReplacement: "iframe",
        autoreplace: {
            youtube: true,
            vimeo: true,
            vimeoIframeReplacement: "iframe",
            videotag: true
        },
        theme: {
            primaryColor: "#e63946",
            secondaryColor: "#3a0e11",
            glassTint: 12,
            cornerRadius: "0px",
            button: {
                shape: "circle"
            }
        },
        plugins: {
            watermark: {
                file: "https://your-site.example.com/logo.png",
                xpos: 100,
                ypos: 0,
                opacity: 60
            }
        }
    };
</script>
<script async data-cfasync="false" src="https://assets.swarmcdn.com/swarmcdn.js"></script>

When an option doesn’t take effect

  1. Check your browser console. Some bad values warn by name and fall back to the default; others fail silently (each option’s section above says which), so a clean console doesn’t prove a value was accepted. To open it, press F12 (Command-Option-I on a Mac) and choose the Console tab. If a message mentions SmartVideo and you’re not sure what it means, send it to us and we’ll read it for you.
  2. Check the nesting. glassTint belongs inside theme, not at the top level. seekStep belongs inside plugins.keyboard; playbackRates, skipSeconds, hideControls, and doubleTapSeek belong inside player; and ga sits at the top level of swarmoptions, not inside plugins.
  3. Check the capitalization. Option names are case-sensitive, and the object itself is all lowercase: swarmoptions, not swarmOptions.
  4. Check that the key is set. Without a valid swarmcdnkey the player never starts, so no other option applies.

Get SmartVideo live on your site

Set it up on WordPress, Shopify, Squarespace, or any platform in a few minutes.

14-day free trial · Card required, no charge until day 15