Track dynamically inserted media players
New in 2.0.0. A media player that appears after the page has finished loading, in a popup, a lightbox or a section fetched in the background, is invisible to the media trackers unless you tell them to keep watching. The Track dynamically inserted players option does that.
This page describes GTM4WP 2.0.0 and newer. The option did not exist in the legacy 1.x versions of the plugin.
The option is experimental and carries an Experimental badge in the plugin settings. It is the one media setting with an ongoing cost, so it is worth understanding before you switch it on.
What it fixes
Each media tracker looks through the page once, finds the players that are there and attaches itself to them. That covers a video sitting in your post content, which is how most videos are embedded.
It does not cover a player that arrives later. Common cases are a video that opens in a lightbox when the visitor clicks a thumbnail, a player inside a popup that a marketing plugin shows after a delay, a tab or accordion whose contents are fetched only when opened, a product gallery video on a WooCommerce page, and anything loaded by infinite scroll. In all of those the tracker has already finished looking by the time the player appears, so the play is never measured.
Turn the option on and each enabled tracker keeps watching the page and wires any new player the moment it shows up.
Turning it on
Open the plugin settings, go to the Media events section and expand the Advanced group, which sits below Media players. Check Track dynamically inserted players. The option is switched off by default.
It changes nothing on its own. It only affects the players you have already enabled in the Media players group, so check at least one player option as well.
What it costs
Watching a page for changes is not free. The browser tells the plugin about every element added anywhere on the page, and on a busy site that can be a great many, from sliders and lazy loaded images to any script that builds part of the layout as it goes.
Two design choices keep the cost small.
All the players share one watcher. Enabling ten player options does not create ten watchers competing for the same work. Each tracker registers what it is looking for, and a single watcher checks each new element against every registration at once.
Only the new elements are examined. When something is added, the plugin looks at that element and what is inside it, never at the whole page again. Adding a paragraph does not trigger a fresh search through every iframe on the page.
What remains is a small cost paid on every change to the page, all day, on every page of your site. That is why the option is off by default. If nothing on your site inserts a player after load, you would be paying it for nothing.
It also brings the player API with it
Most players need a player API from the 3rd party service, and the plugin only requests one once it has found an embed of that provider on the page. On a page that loads without any Vimeo video, for example, Vimeo is never contacted.
That raises an obvious question for a video that opens in a lightbox later. The answer is that the first sighting of a provider is what triggers the request, whenever it happens. A player that appears halfway through a visit causes the API to be fetched at that moment, and once it has loaded the tracker looks through the page again and wires the player it was waiting for.
So the first play of a lightbox video can be reported a moment later than it would be on a page that had the embed from the start, because the API has to arrive first. Nothing is lost, it simply takes as long as the download does.
Players already on the page are always tracked
This option only adds the ability to catch later arrivals. Every player present when the page loads is wired whether the option is on or off, so leaving it off never costs you the tracking you already had.
Wistia does not need it
One exception is worth knowing. The Wistia player announces itself to the plugin rather than waiting to be found, so a Wistia video added at any time is tracked without this option. If Wistia is the only player you use, leave the option off. See the Wistia page for how that works.
Nothing is tracked twice
Watching a page for players raises an obvious risk: wiring the same player again and reporting every play twice. The plugin marks each player it has wired and skips anything already carrying that mark, so a player moved elsewhere on the page, or reported twice by the browser, is only ever wired once.
Three players make this harder than it sounds, and all three are handled. Twitch and Dailymotion both build a container and let the provider fill it with its own iframe, which looks like a brand new embed; those containers are marked so their contents are left alone. The Spotify code replaces the iframe it is given with one of its own, which would carry no mark at all; whatever takes the original’s place is marked instead.
You do not have to do anything about any of these. They are listed here because they explain why the option is marked experimental: it interacts with code the plugin does not control.
Should you turn it on
Turn it on if you know your site opens media in a popup or a lightbox, loads content by AJAX or infinite scroll, or shows video inside a tab or an accordion that fetches its contents when opened.
Leave it off if your videos sit in post content, or if Wistia is the only player you track.
If you are not sure, the quickest test is to open Google Tag Manager preview mode, do whatever makes the player appear on your site, and watch for a gtm4wp.mediaPlayerReady event. If it arrives, the player was found without this option. If nothing appears until you switch the option on, you needed it.
Limitations
- It adds a small cost on every change to the page, on every page of your site, for as long as the visitor stays.
- It changes nothing unless at least one player option is also enabled.
- It makes no difference to Wistia.
- The first player of a given provider to appear after load has to wait for that provider’s API to download before it can be wired.
- A player inside an iframe that your site does not control cannot be reached, whatever this option is set to.
Related pages
The overview of media player tracking describes the events, data layer variables and playback milestones that every player shares. See also Wistia, the one player this setting does not affect, and Twitch and Dailymotion, whose embeds are rebuilt.

