SmartVideo sends playback events to Google Analytics 4 (GA4) by calling your page’s window.gtag function. Install the Google tag (gtag.js) on the page; a Google Tag Manager (GTM) container alone doesn’t create window.gtag, so SmartVideo has nothing to send events to. SmartVideo does not install your Google tag for you.
This guide’s optional customization limits tracking to starts, resumes, pauses, progress, and completions. It uses SmartVideo’s built-in integration, not a custom listener on the player’s internal objects.
Before you begin
You need a working SmartVideo installation, a GA4 web data stream, and access to your website’s head code.
On WordPress, the SmartVideo plugin’s Legacy player (the default in plugin 2.4) sends events only to the retired Universal Analytics, so GA4 receives none. Switch the plugin’s player to the new player to use this guide.
Copy the Measurement ID from GA4: open Admin → Data streams, select your web stream, and copy the ID under Stream details. It starts with G-. Replace G-XXXXXXXXXX below with that ID. Keep your site’s consent settings in place; this setup does not replace consent management.
1. Install the Google tag on the page
If the Google tag is already installed directly and configured for your GA4 stream, keep that installation and go to step 2. Do not add a second Google tag.
If your site uses only GTM for GA4, there is no window.gtag for SmartVideo to call, and SmartVideo has no setting that routes events to a GA4 Measurement ID. Use the Google tag (gtag.js) configured on the page for SmartVideo events.
Have your site developer switch the GA4 stream to a single direct Google tag installation rather than keeping both a direct tag and a GTM Google tag for the same stream. GTM can continue managing your other tags. Do not rely on a GTM YouTube Video trigger for SmartVideo playback.
Add this to the page’s <head>, above the SmartVideo snippet. Replace the Measurement ID in both places:
<script async data-cfasync="false" src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script data-cfasync="false">
window.dataLayer = window.dataLayer || [];
function gtag() { window.dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
See Google’s Google tag setup guide for installation details.
2. Customize SmartVideo’s playback events (optional)
SmartVideo tracks playback whenever window.gtag is available to the player, even without a ga block. By default all nine events are enabled (video_start, video_play, video_pause, video_progress, video_complete, video_seek, video_volume, video_fullscreen, video_error), progress is reported every 10%, and console debugging is off. Each event is sent when its action happens in the player.
Add the ga block below to limit tracking to the five events in this guide and report progress every 25%. Add it to your existing swarmoptions configuration before swarmcdn.js loads. Keep your current key and other settings. The complete manual-installation example is:
<script data-cfasync="false">
var swarmoptions = {
swarmcdnkey: "YOUR_SWARM_CDN_KEY",
iframeReplacement: "iframe",
autoreplace: {
youtube: true
},
ga: {
eventsToTrack: [
"video_start",
"video_play",
"video_pause",
"video_progress",
"video_complete"
],
percentsPlayedInterval: 25,
debug: false
}
};
</script>
<script async data-cfasync="false" src="https://assets.swarmcdn.com/swarmcdn.js"></script>
Replace YOUR_SWARM_CDN_KEY with your Swarm CDN Key. If SmartVideo is already installed, edit the existing configuration instead of adding a second loader. For this optional customization, if a plugin or site builder generates the configuration, have your site developer apply the ga settings before the player initializes.
While testing, set debug: true to log SmartVideo’s analytics activity to the browser console; it does not enable GA4 DebugView by itself. The GA4 destination comes from the Google tag configuration in step 1, not a destination setting in swarmoptions.ga.
The configuration above sends:
| Event | When it is sent | Additional parameters |
|---|---|---|
video_start | The first play of a playback session, including a replay after completion. | None |
video_play | Playback resumes within that session; the initial play sends video_start instead. | video_current_time |
video_pause | Playback pauses before the end. | video_current_time |
video_progress | Reports 25%, 50%, or 75% milestones once per playback session with this configuration. Seeking ahead can suppress milestones; progress events do not measure how much content was actually watched. | video_percent, video_current_time |
video_complete | The player reaches the end. | video_duration |
Each event also includes video_provider: "swarmify" and video_title, which is the original video source URL. Time values are rounded seconds. These playback events are separate from SmartVideo’s billable view count; do not use a GA4 event total to calculate plan usage.
3. Verify before publishing
- For console messages, temporarily set
debug: truein thegablock ofswarmoptions(if you skipped step 2, addga: { debug: true }) and reload the page. Connect the page through Google Tag Assistant. Allow analytics consent for your test if your site requires it. - In GA4, open Admin → Data display → DebugView and select your test device. Tag Assistant enables debug mode for your test; see Google’s DebugView guide.
- Play a video from the beginning. Expect
video_start. Pause and resume to checkvideo_pauseandvideo_play. Let it play through the milestones without seeking, then to the end, to checkvideo_progressandvideo_complete. - Open an event in DebugView and check
video_provider,video_title, and the relevant time or percentage parameter. In the browser console, SmartVideo’s[videojs-ga] Sent:messages confirm it calledgtag; DebugView confirms GA4 received the events. - After verification, set
debugback tofalse(or remove aga: { debug: true }block you added only for testing) and publish your website-code changes through your normal process. If you changed the GTM container to remove a duplicate Google tag, Submit and Publish those changes as well.
If events are missing or duplicated
- No SmartVideo events: in the browser console, run
typeof window.gtag. It should return"function". Check that the Google tag is in place before playback. Withdebug: true, a[videojs-ga] Skipping event (no GA4)message meansgtagwas missing when the event fired. Events skipped whilegtagis missing are not replayed later. If only some events are missing, check that their names are listed ineventsToTrack. - No events from replaced YouTube or Vimeo embeds: a player that replaces an embed in iframe mode (
iframeReplacement: "iframe"for YouTube,vimeoIframeReplacement: "iframe"for Vimeo) runs inside its own frame, where your page’sgtagisn’t available, so it sends no GA4 events. Players SmartVideo places directly in your page, such as<smartvideo>tags, send events normally. - Console says sent, but GA4 shows nothing: check the Measurement ID in the Google tag’s
configcall, thatgtag.jsloads, and that analytics requests are not blocked by consent settings or a browser extension. If only a GTM container is installed, use the direct Google tag setup in step 1. A console message alone is not proof of delivery. - Progress is missing after a seek: seeking ahead can suppress milestones. Test normal playback through the milestone instead. A percentage milestone is sent once per playback session, not on every time update.
- Duplicate events: check for a second Google tag installation or custom tracking code that also sends the same video events.
If the setup still fails, email support@swarmify.com with the page URL, whether you use GTM or a direct Google tag, and the console messages from a test play. Do not send account passwords.