我正在研究这个问题,并提出了一个解决方案。它有点冒险,但确实符合我的需求。
它需要一个黑客以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名称等)。),因此,在查看报告时,我可以看到的不仅仅是点击次数。谢谢 –