Lesson 2 of 4
Wistia Video
① Connect your GTM container
Paste your container ID to load it into this page. It only ever runs here.
Advanced: use a specific environment
Wistia uses a global _wq queue instead of a normal API object, so you register a handler by pushing an onReady callback. Use the id _all and it attaches to every Wistia video on the page.
Inside the handler you bind play, pause and end and push dataLayer events, starting with wistia_play. Wistia also exposes percentwatchedchanged, which the snippet turns into 25/50/75% progress milestones so you can measure drop-off, not just plays.
Goal
Use the _wq queue to push wistia_play / wistia_complete to the dataLayer.
Build it in GTM
Add the listener as a Custom HTML tag
Paste this into a Custom HTML tag firing on All Pages (or Initialization). It turns Wistia's signals into dataLayer events:
<script> window._wq = window._wq || []; window._wq.push({ id: '_all', onReady: function (video) { window.dataLayer = window.dataLayer || []; var meta = { video_id: video.hashedId(), video_title: video.name() }; video.bind('play', function(){ dataLayer.push(Object.assign({ event: 'wistia_play' }, meta)); }); video.bind('pause', function(){ dataLayer.push(Object.assign({ event: 'wistia_pause' }, meta)); }); video.bind('end', function(){ dataLayer.push(Object.assign({ event: 'wistia_complete' }, meta)); return video.unbind; }); // Percent-watched milestones. [0.25, 0.5, 0.75].forEach(function(p){ video.bind('percentwatchedchanged', function(percent){ if (percent >= p && !video['_seen'+p]) { video['_seen'+p] = 1; dataLayer.push(Object.assign({ event: 'wistia_progress', percent: p * 100 }, meta)); } }); }); }}); </script>Create a Custom Event trigger on
wistia_playGo to Triggers → New → Custom Event, set the event name towistia_play, name it for the widget and Save.Fire a tag on it
Add a GA4 Event tag (or theCustom HTML - Teststand-in) firing on that trigger, so the captured event reaches your analytics.Go deeper
Want the full production script, a walkthrough video and a downloadable GTM recipe? DumbData: Wistia listener script, video + GTM recipe.
Debug in Tag Assistant
Copy this lesson's live URL and paste it into GTM Preview, that is the page Tag Assistant connects to. It has the clickable elements, so this page stays clean for reading.
- In your GTM, click Preview.
- Paste the live URL above and click Connect.
- Interact with the live page and watch your tag fire in Tag Assistant.
What you should expect to see
wistia_play, and your tag fires on it in Tag Assistant.Verify your container
Built it? Export your container, Admin → Export Container, choose your workspace, then drop the JSON here to check it against this lesson.
Drop your container .json here
or browse · checked in your browser, nothing is uploaded