Skip to content

Commit 8f5b77c

Browse files
committed
Added Google Tag Manager's Spotify Audio Tag actual implementation code and GTM's artifacts as JSON, and also a concise description the tag's features.
1 parent 5a5b671 commit 8f5b77c

File tree

2 files changed

+545
-19
lines changed

2 files changed

+545
-19
lines changed

gtm/spotify-audio.json.md

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
# [Spotify](https://www.spotify.com) Audio Tag for [Google Tag Manager](https://tagmanager.google.com)
1+
# [`Spotify`](https://www.spotify.com) Audio Tag for [Google Tag Manager](https://tagmanager.google.com)
22

33
## Description
44

5-
- **Custom HTML Tag** for [***Google Tag Manager***](https://tagmanager.google.com) which is able detect which content is being played and how far it's been played, as integer percentage values between 1 and 99;
5+
- **Custom HTML Tag** for [***Google Tag Manager***](https://tagmanager.google.com) which is able detect which content is being played and how far it's been played, as integer values between 1 and 99 in percentage and as floting point values as seconds;
66
- No actual human friendly information is availabe *(no **episode**, **track**, **artist**, **album**, **playlist** or **show name** will be captured even though it might be viable via **DOM Scraping**)*:
7-
- Each content is identified by a [`Spotify URI`](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids), which consist of three parts:
7+
- Each content is identified by a [`Spotify URI`](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids), which consists in three parts:
88
- `{platform}` **:** `{content type}` **:** `{identifier}`;
99
- ***Examples:***
1010
- `spotify` **:** `album` **:** `7Ff0Q5oeEoVKHtxJJoXyId`;
1111
- `spotify` **:** `artist` **:** `1on7ZQ2pvgeQF4vmIA09x5`;
1212
- `spotify` **:** `episode` **:** `5DVGuabuaHaC9UxQodcyvf`;
1313
- `spotify` **:** `playlist` **:** `0E6htK22DGE5d4jj3r6dmS`.
14-
- Different ***tracks*** executed within a ***playlist*** are identified only by their **duration** *(no human-readable identifiers were available in the event data)*:
15-
- This allows us to count how many tracks where executed (*partially or completely*) within a grouped content (*playlist, artists or album*).
14+
- Different ***tracks*** executed within a ***playlist*** are identified only by their **duration**:
15+
- This allows us to count how many **tracks** where executed (*partially or completely*) within a grouped content (*playlist, artists or album*).
1616
- **Show URLs** (*i.e. [`open.spotify.com/show/3bdzILat9px7eH27ziXl8K`](https://open.spotify.com/show/3bdzILat9px7eH27ziXl8K)*) redirect to the show's last episode;
17-
- Any URI can be transformed into a [`open.spotify.com`](https://open.spotify.com) link following the **template** below:
18-
- **`URI`**:
19-
- `spotify` **:** `album` **:** `7Ff0Q5oeEoVKHtxJJoXyId`.
20-
- **`URL`**:
21-
- `https://open.spotify.com` **/** `album` **/** `7Ff0Q5oeEoVKHtxJJoXyId`.
2217

2318
---
2419

@@ -29,18 +24,35 @@
2924
- `audio_playback_resumed`;
3025
- `audio_complete`;
3126
- `audio_progress`:
32-
- ***Detected percentages*** values are **configured** and **validated** in the `Spotify audio Custom HTML tag` (i.e. `[ 25, 50, 75 ]`).
27+
- ***Detected percentages values*** are **configured** and **validated** in the `Spotify audio Custom HTML tag` (i.e. `[ 25, 50, 75 ]`).
28+
29+
---
30+
31+
## Tag Parameters
32+
33+
- `audio_content`;
34+
- `audio_current_time`;
35+
- `audio_duration`;
36+
- `audio_percent`;
37+
- `audio_provider`;
38+
- `audio_status`.
3339

3440
---
3541

3642
## `JavaScript` function to convert **Spotify's** ***URI*** into ***URL***
3743

44+
- Any URI can be transformed into a [`open.spotify.com`](https://open.spotify.com) link by following the **template** below:
45+
- **`URI`**:
46+
- `spotify` **:** `album` **:** `7Ff0Q5oeEoVKHtxJJoXyId`.
47+
- **`URL`**:
48+
- `https://open.spotify.com` **/** `album` **/** `7Ff0Q5oeEoVKHtxJJoXyId`.
49+
3850
```javascript
3951
(function getSpotifyUrlfromUri(uri) {
40-
var reSpotifyURI = /spotify:(album|arist|episode|playlist|show|track):([^:\/?#&]+)/i;
52+
var reSpotifyUri = /spotify:(album|arist|episode|playlist|show|track):([^:\/?#&]+)/i;
4153
var result = { spotify_uri: uri, spotify_url: '' };
42-
if (reSpotifyURI.test(uri)) {
43-
var matches = reSpotifyURI.exec(uri);
54+
if (reSpotifyUri.test(uri)) {
55+
var matches = reSpotifyUri.exec(uri);
4456
var contentType = matches[1];
4557
var contentId = matches[2];
4658
result.spotify_url = `https://open.spotify.com/${contentType}/${contentId}`;
@@ -51,22 +63,39 @@
5163
);
5264
```
5365

54-
### Output
66+
### Expected Output
5567

5668
```javascript
5769
{
58-
spotify_uri: 'spotify:album:7Ff0Q5oeEoVKHtxJJoXyId',
59-
spotify_url: 'https://open.spotify.com/album/7Ff0Q5oeEoVKHtxJJoXyId'
70+
spotify_uri: 'spotify:album:7Ff0Q5oeEoVKHtxJJoXyId',
71+
spotify_url: 'https://open.spotify.com/album/7Ff0Q5oeEoVKHtxJJoXyId'
6072
}
6173
```
6274

6375
---
6476

65-
## Importing **Tags**, **Triggers** and **Variables**
77+
## Pre-Configuration: Spotify's IFrame
78+
79+
```html
80+
<iframe src="https://open.spotify.com/embed/track/3qN5qMTKyEEmiTZD38CmPA" width="300" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>
81+
<script>
82+
// Send a message to the Spotify player to let it know our domain
83+
var spotifyPlayer = document.querySelector('iframe[src^="https://open.spotify.com"]');
84+
spotifyPlayer.contentWindow.postMessage({
85+
type: 'listeningOn',
86+
domain: window.location.hostname,
87+
gtmId: 'YOUR-GTM-CONTAINER-ID'
88+
}, 'https://open.spotify.com');
89+
</script>
90+
```
91+
92+
---
93+
94+
## Importing **Tags**, **Triggers** and **Variables** in `Google Tag Manager`
6695

6796
- Save the `JSON` below to a file and **import** it in [*Google Tag Manager*](https://tagmanager.google.com):
6897
- [`Admin`](https://tagmanager.google.com/#/admin) > `Import Container`.
69-
- Add a constant named `{{GA - Property ID}}` with your **[Google Analytics 4](https://analytics.google.com)'s Property ID**.
98+
- Add a constant named `{{GA4 - Property ID}}` with your **[Google Analytics 4](https://analytics.google.com)'s Property ID**.
7099

71100
### Google Tag Manager Exported Container `JSON` file
72101

0 commit comments

Comments
 (0)