跟踪从自定义 HTML5 视频播放器到 Omniture 媒体模块的视频里程碑?

发布于 2024-12-15 05:34:49 字数 663 浏览 0 评论 0原文

我有一个移动 Javascript 应用程序,它偶尔会在屏幕上动态创建 元素。我需要使用 Omniture 跟踪视频播放。我已将 playpauseendingseekingseeked 事件绑定到跟踪用户开始视频、暂停、恢复和停止(或者他们完成观看视频)。这都是通过诸如

s.Media.play("some_video_name", timePosition);

s.Media.stop("some_video_name");

等调用来实现的。目前这一切都有效。

我现在想做的是使用 trackMilestones 选项跟踪 0、25、75 和 100% 的位置里程碑,但我不明白我在网上找到的任何示例是如何实现的实际上通知 Omniture s.Media 对象它们所在的位置。 Omniture 无法神奇地知道我的视频在哪里,除非它将事件处理程序附加到我的视频元素。他们就是这么做的吗?

当我的播放器正在播放视频时,是否有某种方法可以调用 s.Media 对象来通知它我的位置?

I've got a mobile Javascript application that occasionally dynamically-creates a <video> element on the screen. I need to track video plays with Omniture. I have bound the play, pause, ended, seeking and seeked events to track that the user started a video, paused, resumed, and stopped (or that they completed viewing the video). This is all implemented with calls like

s.Media.play("some_video_name", timePosition);

and

s.Media.stop("some_video_name");

Etc. This all currently works.

What I want to now do is track the positional milestones of 0, 25, 75, and 100%, with the trackMilestones option, but I don't understand how any of the examples I've found online actually inform the Omniture s.Media object of where they are. Omniture wouldn't be able to magically know where my video is unless it attaches event handlers to my video element. Is that what they're doing?

Is there some method I can call on the s.Media object to inform it of my position as my player is playing video?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最丧也最甜 2024-12-22 05:34:49

下面是一个跟踪 1/4 里程碑 (25,50,75,100) 的工作示例。

1.确保您的 s_code.js 文件中有以下内容

s.loadModule("Media");
s.Media.autoTrack=false;
s.Media.trackWhilePlaying=true;
s.Media.trackMilestones="25,50,75,100";

s_code 中也需要媒体模块。以下是您需要的内容的摘录

s.m_Media_c="var m=s.m_i('Media');m.cn=function(n){var m=this;return m.s.rep(m.s.rep(m.s.rep(n,\"\\n\",''),\"\\r\",''),'--**--','')};m.open=function(n,l,p,b){var m=this,i=new Object,tm=new Date,a='',"
+"x;n=m.cn(n);if(!l)l=-1;if(n&&p){if(!m.l)m.l=new Object;if(m.l[n])m.close(n);if(b&&b.id)a=b.id;if(a)for (x in m.l)if(m.l[x]&&m.l[x].a==a)m.close(m.l[x].n);i.n=n;i.l=l;i.o=0;i.x=0;i.p=m.cn(m.playerNa"
+"me?m.playerName:p);i.a=a;i.t=0;i.ts=0;i.s=Math.floor(tm.getTime()/1000);i.lx=0;i.lt=i.s;i.lo=0;i.e='';i.to=-1;i.tc=0;i.fel=new Object;i.vt=0;i.sn=0;i.sx=\"\";i.sl=0;i.sg=0;i.sc=0;i.lm=0;i.lom=0;m.l"
+"[n]=i}};m._delete=function(n){var m=this,i;n=m.cn(n);i=m.l[n];m.l[n]=0;if(i&&i.m)clearTimeout(i.m.i)};m.close=function(n){this.e(n,0,-1)};m.play=function(n,o,sn,sx,sl){var m=this,i;i=m.e(n,1,o,sn,s"
+"x,sl);if(i&&!i.m){i.m=new Object;i.m.m=new Function('var m=s_c_il['+m._in+'],i;if(m.l){i=m.l[\"'+m.s.rep(i.n,'\"','\\\\\"')+'\"];if(i){if(i.lx==1)m.e(i.n,3,-1);i.m.i=setTimeout(i.m.m,1000)}}');i.m."
+"m()}};m.stop=function(n,

2.将 HTML5 视频播放器绑定到 Omniture

var html5Player = document.getElementById('video');
html5Player.addEventListener('loadedmetadata',playerHandler,false);
html5Player.addEventListener('play',playerHandler,false);
html5Player.addEventListener('pause',playerHandler,false);
html5Player.addEventListener('ended',playerHandler,false);

    var videoOpened = false;
    var currentTime = 0;

    function playerHandler(e){
        // window.console.log(e);//video meta
        //window.console.log(e.type);
        if (html5Player.currentTime > 0) {
            currentTime = html5Player.currentTime;
        }
        switch(e.type){
            case 'play':
                if(!videoOpened){
                    window.console.log('opened');
                    s.Media.open(videoPageName, html5Player.duration, publicationName);
                    s.Media.play(videoPageName, 0);
                }else{
                    window.console.log('play');
                    s.Media.play(videoPageName, currentTime);
                }
                // alert('currentTime: ' + currentTime);
                // alert('duration: ' + Math.floor(html5Player.duration));
                // alert('videoPageName: ' + videoPageName);
                videoOpened = true;
            break;
            case 'pause':
                window.console.log('pause');
                s.Media.stop(videoPageName,currentTime);
            break;
            case 'ended':
                window.console.log('ended');
                s.Media.stop(videoPageName,currentTime);
                s.Media.close(videoPageName);
            break;
            default:
            break;
        }
    }

Here is a working example that tracks 1/4 milestones (25,50,75,100).

1.Ensure you have the following in your s_code.js file

s.loadModule("Media");
s.Media.autoTrack=false;
s.Media.trackWhilePlaying=true;
s.Media.trackMilestones="25,50,75,100";

Media module is required within s_code as well. Here's an excerpt of what you'll need

s.m_Media_c="var m=s.m_i('Media');m.cn=function(n){var m=this;return m.s.rep(m.s.rep(m.s.rep(n,\"\\n\",''),\"\\r\",''),'--**--','')};m.open=function(n,l,p,b){var m=this,i=new Object,tm=new Date,a='',"
+"x;n=m.cn(n);if(!l)l=-1;if(n&&p){if(!m.l)m.l=new Object;if(m.l[n])m.close(n);if(b&&b.id)a=b.id;if(a)for (x in m.l)if(m.l[x]&&m.l[x].a==a)m.close(m.l[x].n);i.n=n;i.l=l;i.o=0;i.x=0;i.p=m.cn(m.playerNa"
+"me?m.playerName:p);i.a=a;i.t=0;i.ts=0;i.s=Math.floor(tm.getTime()/1000);i.lx=0;i.lt=i.s;i.lo=0;i.e='';i.to=-1;i.tc=0;i.fel=new Object;i.vt=0;i.sn=0;i.sx=\"\";i.sl=0;i.sg=0;i.sc=0;i.lm=0;i.lom=0;m.l"
+"[n]=i}};m._delete=function(n){var m=this,i;n=m.cn(n);i=m.l[n];m.l[n]=0;if(i&&i.m)clearTimeout(i.m.i)};m.close=function(n){this.e(n,0,-1)};m.play=function(n,o,sn,sx,sl){var m=this,i;i=m.e(n,1,o,sn,s"
+"x,sl);if(i&&!i.m){i.m=new Object;i.m.m=new Function('var m=s_c_il['+m._in+'],i;if(m.l){i=m.l[\"'+m.s.rep(i.n,'\"','\\\\\"')+'\"];if(i){if(i.lx==1)m.e(i.n,3,-1);i.m.i=setTimeout(i.m.m,1000)}}');i.m."
+"m()}};m.stop=function(n,

2.Bind HTML5 video player to Omniture

var html5Player = document.getElementById('video');
html5Player.addEventListener('loadedmetadata',playerHandler,false);
html5Player.addEventListener('play',playerHandler,false);
html5Player.addEventListener('pause',playerHandler,false);
html5Player.addEventListener('ended',playerHandler,false);

    var videoOpened = false;
    var currentTime = 0;

    function playerHandler(e){
        // window.console.log(e);//video meta
        //window.console.log(e.type);
        if (html5Player.currentTime > 0) {
            currentTime = html5Player.currentTime;
        }
        switch(e.type){
            case 'play':
                if(!videoOpened){
                    window.console.log('opened');
                    s.Media.open(videoPageName, html5Player.duration, publicationName);
                    s.Media.play(videoPageName, 0);
                }else{
                    window.console.log('play');
                    s.Media.play(videoPageName, currentTime);
                }
                // alert('currentTime: ' + currentTime);
                // alert('duration: ' + Math.floor(html5Player.duration));
                // alert('videoPageName: ' + videoPageName);
                videoOpened = true;
            break;
            case 'pause':
                window.console.log('pause');
                s.Media.stop(videoPageName,currentTime);
            break;
            case 'ended':
                window.console.log('ended');
                s.Media.stop(videoPageName,currentTime);
                s.Media.close(videoPageName);
            break;
            default:
            break;
        }
    }
愿得七秒忆 2024-12-22 05:34:49

您似乎错过了通知 s.Media 持续时间的呼叫:

    s.Media.open("some_video_name", videoDuration, videoSrc);

这与播放/暂停/搜索事件相结合,应该让他们知道视频在总播放量中所占百分比的大致位置。

我说大约是因为我怀疑他们基本上是在运行自己的内部秒表,该秒表仍然可能会偏离视频播放头。例如,在 HTML5 视频中,除了暂停之外,您还需要捕获“等待”事件。秒表将假定实时播放速率,并且不处理视频可以播放但不能及时前进的其他非事件触发原因(浏览器可能会由于视频已经在页面中的其他位置播放而拒绝播放/地点 )。想必他们的秒表足以满足他们的追踪目的。

You seem to be missing a call which informs s.Media of the duration:

    s.Media.open("some_video_name", videoDuration, videoSrc);

This, in combination with the play/pause/seek events, should let them know approximately where the video is as a percent of total playback.

I say approximately because I suspect they're basically running their own internal stopwatch which can still drift from the video playhead. For example,in HTML5 video you'd need to catch the "waiting" event in addition to pause. The stopwatch would assume a real-time playback rate, and not handle other, non-event firing reasons why a video can be playing but not advancing in time (the browser could refuse to play due to a video already playing elsewhere in the page/site ). Presumably their stopwatch is good enough for their tracking purposes.

月亮邮递员 2024-12-22 05:34:49

我不确定您是否已经找到解决方案。但要跟踪里程碑,您可以在代码的媒体监视器代码中添加以下代码。

var tracked10=false; //Variables used as "flags" to prevent the same code from running
var tracked90=false; //twice in the same video play.
s.Media.monitor = function (s,media) {

//Use this code with either JavaScript or Flash.
// eVar1 = Media Name
// event1 = Video Begins
// event2 = Reached 10%
// event3 = Reached 90%
// event4 = Reached 100%
if (media.event == "Open") { //Executes when the video opens.
s.Media.trackVars = "eVar1,events";
s.Media.trackEvents = "event1";
s.events="event1";
s.eVar1 = media.name;
s.Media.track(media.name);
}
if ((!tracked10) && (media.percent >= 10) { //Executes at 10% complete.
s.Media.trackVars = "eVar1,events";
s.Media.trackEvents = "event2";
s.events="event2"
s.eVar1 = media.name;
s.Media.track(media.name);
tracked10 = true;
}
if ((!tracked90) && (media.percent >= 90)) { //Executes at 90% complete.
s.Media.trackVars = "eVar1,events";
s.Media.trackEvents = "event3";
s.events="event3"
s.eVar1 = media.name;
s.Media.track(media.name);
tracked90 = true;
}
if (media.event == "CLOSE") { //Executes when the video completes.
s.Media.trackVars = "eVar1,events";
s.Media.trackEvents = "event4";
s.events="event4"
s.eVar1 = media.name;
s.Media.track(media.name);
var tracked10=false; //Reset flags values at Media.close if visitors can play
var tracked90=false; //additional videos without reloading the page.
}
};

I am not sure whether you already figured out the solution for this. But to trackMilestone's you can add the following piece of code in your scode's Media monitor code.

var tracked10=false; //Variables used as "flags" to prevent the same code from running
var tracked90=false; //twice in the same video play.
s.Media.monitor = function (s,media) {

//Use this code with either JavaScript or Flash.
// eVar1 = Media Name
// event1 = Video Begins
// event2 = Reached 10%
// event3 = Reached 90%
// event4 = Reached 100%
if (media.event == "Open") { //Executes when the video opens.
s.Media.trackVars = "eVar1,events";
s.Media.trackEvents = "event1";
s.events="event1";
s.eVar1 = media.name;
s.Media.track(media.name);
}
if ((!tracked10) && (media.percent >= 10) { //Executes at 10% complete.
s.Media.trackVars = "eVar1,events";
s.Media.trackEvents = "event2";
s.events="event2"
s.eVar1 = media.name;
s.Media.track(media.name);
tracked10 = true;
}
if ((!tracked90) && (media.percent >= 90)) { //Executes at 90% complete.
s.Media.trackVars = "eVar1,events";
s.Media.trackEvents = "event3";
s.events="event3"
s.eVar1 = media.name;
s.Media.track(media.name);
tracked90 = true;
}
if (media.event == "CLOSE") { //Executes when the video completes.
s.Media.trackVars = "eVar1,events";
s.Media.trackEvents = "event4";
s.events="event4"
s.eVar1 = media.name;
s.Media.track(media.name);
var tracked10=false; //Reset flags values at Media.close if visitors can play
var tracked90=false; //additional videos without reloading the page.
}
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文