SoundCloud audio tracking in Google Tag Manager
Google Tag Manager for WordPress reports how your visitors listen to the SoundCloud tracks embedded on your site. Playing, pausing, seeking and finishing a track become data layer events, and so do the download, buy and share buttons inside the player.
This page describes GTM4WP 2.0.0 and newer. Features introduced by that release are marked New in 2.0.0. Where the legacy 1.x versions of the plugin behaved differently, the older behavior is marked with a bold GTM4WP 1.x: lead-in.
SoundCloud tracking is stable, so the option carries no badge in the plugin settings.
Turning SoundCloud tracking on
Open the plugin settings, go to the Media events section, expand the Media players group and check Soundcloud events. The option is switched off by default.
Which embeds are detected
The tracker wires every iframe whose src contains soundcloud.com. That covers the embed code you copy from SoundCloud, the SoundCloud block of the block editor and a plain SoundCloud URL pasted on its own line, because WordPress turns all of them into the same widget iframe.
Tracking depends on the SoundCloud Widget API, which is only requested once the tracker has actually found a SoundCloud embed on the page, so a page without one never contacts SoundCloud. The tracker also checks that the API is present before it wires each iframe, so a consent manager, an ad blocker or a network error that keeps it from loading leaves the track unmeasured rather than throwing an error on your page.
A player that is in the page when it loads is wired straight away. One inserted later, for example in a popup, a lightbox or a section loaded by AJAX, needs the Track dynamically inserted players option in the Advanced group as well.
SoundCloud reports milliseconds
This is the one thing to get right before you build anything. The SoundCloud Widget API reports positions and durations in milliseconds, and the plugin passes them through unchanged, so mediaData.duration and mediaCurrentTime are in milliseconds for this player and in seconds for every other one. A three minute track reports a duration of 180000.
The built-in Video variables of Google Tag Manager are the exception: Video Current Time and Video Duration are converted to whole seconds, because Google Tag Manager expects seconds there. Divide by 1000 in your tag if you need seconds from the gtm4wp variables.
Playback states
The gtm4wp.mediaPlayerStateChange event fires with these values in the mediaPlayerState variable:
| mediaPlayerState | Fires when |
|---|---|
play | Playback starts. |
pause | The visitor pauses the track. |
ended | The track reaches its end. |
seeked | The visitor jumps to another position. |
The SoundCloud widget reports no buffering signal, so there is no buffering state for this player.
Player events
The gtm4wp.mediaPlayerEvent event carries the name of the event in the mediaPlayerEvent variable. SoundCloud is the only player whose event set covers actions on the player chrome rather than playback itself:
| mediaPlayerEvent | Fires when |
|---|---|
click-download | The visitor clicks the download button inside the player. |
click-buy | The visitor clicks the buy button inside the player. |
open-share-panel | The visitor opens the share panel inside the player. |
error | The widget reports an error. |
None of these carry a mediaPlayerEventParam. The SoundCloud widget reports the fact that something happened without any accompanying detail, and that includes the error event, which does not say what went wrong.
What mediaData holds for a SoundCloud track
| Variable | Contents |
|---|---|
mediaData.id | The numeric SoundCloud ID of the track. |
mediaData.author | The user name of the account that uploaded the track. SoundCloud is one of only four players that report this. |
mediaData.title | The title of the track. |
mediaData.url | The public SoundCloud address of the track. |
mediaData.duration | The length of the track in milliseconds. |
The mediaType variable is soundcloud in every event.
Playlists
A SoundCloud widget can hold a whole playlist. The plugin reads which track is playing when the widget becomes ready and again whenever playback starts, so every event reports the track the visitor is actually listening to rather than the first one in the list. Playback milestones are counted per track, so each track in a playlist reports its own progress.
Google Tag Manager built-in Video variables
New in 2.0.0. Every SoundCloud media event also populates the built-in Video variables of Google Tag Manager, with Video Provider set to soundcloud. The section on built-in Video variables explains how to enable and use them. They are named for video, but they work the same way for audio, and Video Visible is measured on the widget iframe.
Building a trigger in Google Tag Manager
To fire a tag when a visitor starts a SoundCloud track:
- Create a Data Layer Variable named
mediaPlayerState. - Create a Custom Event trigger whose event name is
gtm4wp.mediaPlayerStateChange. - Add the condition
mediaPlayerStateequalsplayto the trigger. - Attach the trigger to your tag. To send the track and the artist along with it, create Data Layer Variables named
mediaData.titleandmediaData.author.
To measure the buy button instead, build a Custom Event trigger on gtm4wp.mediaPlayerEvent and add the condition mediaPlayerEvent equals click-buy.
Limitations
mediaData.durationandmediaCurrentTimeare in milliseconds, unlike every other player. Convert them in your tag if you report seconds.- There is no
bufferingstate, because the widget does not report one. - The player events carry no parameter, so the
errorevent tells you that something failed but not what. - There is no 100 percent milestone. Measure a full listen with the
endedstate, as described under playback percentage milestones. - The tracker script loads on every page of your site when the option is on. The SoundCloud Widget API does not: it is fetched from
w.soundcloud.comonly on pages that actually contain a SoundCloud embed, so treat it like any other 3rd party script when you plan your consent setup for those pages.
Related pages
The overview of media player tracking describes the events, data layer variables and playback milestones that every player shares. See also the two other audio players, Mixcloud and Spotify.

