我正在研究這個問題,並提出了一個解決方案。它有點冒險,但確實符合我的需求。
它需要一個黑客以wpincludes/mediaelements/MediaElement的-和player.min.js(我計劃的創建一個插件在某個時候做到這一點...)
查找劇中的部分按鈕添加一個新的ID和類到按鈕。該ID由谷歌標籤管理器抓取,並且該類用帖子標題更新。
('<div class="mejs-button mejs-playpause-button mejs-play" ><button id="perplay" class="playername" type="button" aria-controls="'+g.id+'" title="'+h.playText+'" aria-label="'+h.playText+'"></button></div>').
在每一個wordpress主題內容頁(content.php,內容的single.php,內容front.php等)
查找的音頻/視頻部分
<div class="entry-content video">
<!-- Underneath it add the following code -->
<!-- hack to add podcast name (post title) to the player button class -->
<?php $x = get_the_title(); // gets post title ?>
<script>
<!-- js to find element with class name of playername and append the class name with the post title -->
document.addEventListener('DOMContentLoaded', function() {
document.getElementsByClassName('playername')[0].className = " <?php echo $x; ?>";
})
</script>
我的情況是,我可以獲取Google標籤管理器中的element.css值,並使用它來跟蹤播放的音頻文件以及播放的頁面。
如果您需要跟蹤每個帖子的多個音頻文件,您可能會獲得媒體ID,並使用它來代替帖子標題 - GA中的tho,如果您有很多ID,則需要查找表。
沒有什麼特別的gtm.click事件,因爲按鈕被點擊的不是音頻元素本身,它保存了mp3的src路徑,並且按鈕沒有類或id,如上所示。這表示我需要將類或id用作GTM的標籤,因此Unique需要可識別(即歌名或mp3名稱等)。),因此,在查看報告時,我可以看到的不僅僅是點擊次數。謝謝 –