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

Setup & Installation

Install SmartVideo with Google Tag Manager

Updated October 19, 2026

If your site already runs Google Tag Manager (GTM) and you can’t edit the site’s <head>, you can load SmartVideo from a GTM Custom HTML tag. This article covers that route. If you can edit the head, paste the snippet there instead (see Using SmartVideo with Shopify, Squarespace, Wix, and other platforms); it has fewer moving parts.

On WordPress? Use the SmartVideo plugin instead. Follow Install SmartVideo on WordPress.

Step 1: Get your SmartVideo snippet

Log in to the SmartVideo Dashboard, open Account, and copy your API key from the Profile section. Don’t have an account yet? Create one first.

The GTM version of the snippet looks like this. Replace YOUR_SWARM_CDN_KEY with your key:

<script data-cfasync="false">
    window.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>

It differs from the standard snippet in one place: it sets window.swarmoptions instead of var swarmoptions, because the player reads that page-level object. Keep data-cfasync="false" on both script tags and async on the loader tag. The player keeps checking for your settings until your Swarm CDN Key appears, so the order of the two scripts inside the tag doesn’t matter.

Step 2: Create the tag in Tag Manager

  1. In your GTM workspace, go to Tags and click New.
  2. Choose the Custom HTML tag type and paste the snippet from Step 1. Google’s rule for this tag type is to always place JavaScript inside <script></script> tags, which the snippet already does. See Google’s Custom HTML tag documentation.
  3. Under Triggering, choose Initialization - All Pages. Google says Initialization triggers fire before all other triggers except Consent Initialization (trigger types).
  4. Name the tag (for example, “SmartVideo”) and save it.

Step 3: Test it with Preview

  1. In the workspace, click Preview. This opens Tag Assistant.
  2. Enter your site’s URL and click Connect. Your site opens and shows “Connected” in the bottom right.
  3. Go back to the Tag Assistant tab and click Continue.

The debug view shows which tags fired and in which order, so confirm your SmartVideo tag fired. Then follow How do I know SmartVideo is working? on a page that has a video. Google’s steps: Preview and debug containers.

Step 4: Submit and publish

When Preview looks right, click Submit in the workspace and publish the container. Once the container version is published to your live environment, the SmartVideo tag starts loading for your visitors.

What happens after I install?

SmartVideo can start after your page has finished loading, and it still finds your videos: if the page has already been parsed when SmartVideo starts, it scans straight away, and it keeps scanning as the page changes.

YouTube and Vimeo embeds are swapped for the SmartVideo player once the page document is complete. With the iframeReplacement: "iframe" setting used in the snippet above, an embed can be swapped slightly before that point. Vimeo videos switch once their conversion is ready; see Automatic Vimeo conversions. To place a video with a SmartVideo tag, see How to add a video to a non-WordPress website.

Things that can stop it working

  • Consent settings on the tag. If you set the tag to Require additional consent, it fires only when all the consent types you specify are granted at the moment it triggers. With the default, Not set, GTM makes no additional consent checks. See Google’s consent documentation. A visitor who hasn’t granted the required consent won’t load SmartVideo.
  • A Content Security Policy. If your site sends a Content-Security-Policy header, follow Google’s CSP guide and use the nonce-aware container snippet it describes. Preview mode also needs https://www.googletagmanager.com and https://tagmanager.google.com allowed in script-src-elem, and Tag Assistant lists CSP problems under Page issues. Google says Tag Manager passes the nonce to the scripts it adds to the page; test the tag in Preview on a page that has the policy.
  • Ad blockers. If a blocker in a visitor’s browser stops your Tag Manager container from running, the SmartVideo tag inside it won’t run either. Keep that in mind if SmartVideo works for you but not for a visitor, or if it fails in your own browser; try the page with your blocker turned off.

Still stuck? The video not playing troubleshooting guide covers the usual causes, or email support@swarmify.com with the page URL. To send playback events to GA4, see Track SmartVideo events in GA4 and Google Tag Manager.

Keywords: Google Tag Manager, GTM, Custom HTML tag, Initialization trigger, Tag Assistant, Preview mode, install without editing head, tag manager snippet, swarmoptions

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