跟踪了多少次的HTML5音频元素玩过吗? [英] Tracking how many times an HTML5 audio element is played?

查看:168
本文介绍了跟踪了多少次的HTML5音频元素玩过吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是跟踪一个HTML5音频元素多少次打出了最好的方法是什么?

What is the best way to track how many times an HTML5 audio element is played?

(我们可以使用谷歌分析过,如果这是最好的办法)

(we can use Google Analytics too, if that is the best approach)

推荐答案

HTML5音频元素的有基本的回调。

HTML5 Audio elements have basic callbacks.

您可以再加上一个基本的事件回调库像jQuery默认情况下附加这些事件:

You can combine that with a basic event callback library like jQuery to attach these events by default:

$("audio").bind("play", function(){
_gaq.push(["_trackEvent","Audio", "play", $(this).attr('src')]);
});

您也可以做跟踪类似事件,当人们完成音频:

You can also do similar events for tracking when people finish the audio:

$("audio").bind("ended", function(){
_gaq.push(["_trackEvent","Audio", "ended", $(this).attr('src')]);
});

这可以通过将合并成一个单一的呼叫进行更简洁:

This can be made more concise by combining them into a single call:

$("audio").bind("play ended", function(e){
_gaq.push(["_trackEvent","Audio", e.type, $(this).attr('src')]);
});

您还可以添加在&LT的事件;音频> 标记属性为 onplay onended ,但是,我不会推荐这种方法。

You can also add the events on the <audio> tag attributes as onplay and onended, but, I wouldn't recommend that approach.

这篇关于跟踪了多少次的HTML5音频元素玩过吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆