Mixcloud tracking in Google Tag Manager
New in 2.0.0. Google Tag Manager for WordPress reports how your visitors listen to the Mixcloud shows embedded on your site. Starting, pausing, buffering and reaching the end become data layer events that you can use as triggers in Google Tag Manager.
This page describes GTM4WP 2.0.0 and newer. Mixcloud tracking 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. Mixcloud gives away less about a show than most players do, so read the section on what is reported before you plan your tags.
Turning Mixcloud tracking on
Open the plugin settings, go to the Media events section, expand the Media players group and check Mixcloud events. The option is switched off by default.
Which embeds are detected
The tracker wires every iframe whose src contains mixcloud.com. A Mixcloud embed identifies its show through a feed parameter in that address, which holds the path of the show, and the plugin reads it from there.
Tracking depends on the Mixcloud Widget API, which is only requested once the tracker has actually found a Mixcloud embed on the page. That deferral is worth more here than for any other player: the Mixcloud API is by a wide margin the largest of the media dependencies, around 190 KB, so a site that carries one Mixcloud show on one page no longer pays for it everywhere else.
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 show 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.
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 show. |
ended | The show reaches its end. |
buffering | The widget starts buffering. |
There is no seeked state, because the widget reports no seek event.
Player events
The only value gtm4wp.mediaPlayerEvent reports for Mixcloud is error, and it carries no mediaPlayerEventParam, so it tells you that something went wrong without saying what.
What mediaData holds for a Mixcloud show
| Variable | Contents |
|---|---|
mediaData.id | The feed path of the show, for example /someartist/some-show/. |
mediaData.author | Always empty. The widget exposes no artist name. |
mediaData.title | The feed path again, the same value as the ID. The widget exposes no title. |
mediaData.url | The public Mixcloud address of the show, built from the feed path. |
mediaData.duration | The length in seconds, once it is known. See below. |
The mediaType variable is mixcloud in every event.
The feed path is at least readable, unlike the opaque IDs some of the other players report. It usually contains the artist and the show name, so a report built on it is not unusable, though it is not a clean title either.
The duration starts at zero
The Mixcloud widget does not offer the length of a show up front. It only arrives with the first progress report, which happens once playback has actually begun.
Until then the plugin has nothing to report, so gtm4wp.mediaPlayerReady carries a duration of 0. That is not an error and it does not mean the show is empty. Do not build a tag that treats a zero duration on the ready event as a failure, and read the duration from a later event if you need the real value.
Google Tag Manager built-in Video variables
Every Mixcloud media event also populates the built-in Video variables of Google Tag Manager, with Video Provider set to mixcloud. 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 Mixcloud show:
- 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 identify the show, create a second Data Layer Variable named
mediaData.id.
Limitations
- The title is the feed path of the show rather than a proper title, and
mediaData.authoris always empty. - The duration is 0 on the ready event and only becomes real once playback has started.
- There is no
seekedstate. - The
errorevent carries no detail. - 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 Mixcloud Widget API does not: it is fetched from
widget.mixcloud.comonly on pages that actually contain a Mixcloud 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, SoundCloud and Spotify.

