Adobe Analytics getPageVisibility plugin | Community
Skip to main content
Level 2
July 4, 2019
Solved

Adobe Analytics getPageVisibility plugin

  • July 4, 2019
  • 3 replies
  • 4150 views

My goal is to catch the amount of time the page was active within the browser and define this value to eVar

I found this plugin getPageVisibility , but it suggests to define value to events.

Could anyone describe how to config this plugin to push the value (Total Page Visibility Seconds) only in eVar

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by cathyc18262486

Configured. Redesign a little bit plugin (also added s.getVisitStart function, which is missed in documentation)

/* Plugin: Visit Start */

s.getVisitStart = new Function("c", "var s=this,v=1,t=new Date;t.setTime(t.getTime()+1800000);if(s.c_r(c)){v=0}if(!s.c_w(c,1,t)){s.c_w(c,1,0)}if(!s.c_r(c)){v=0}return v;");

/* Page Visibility Plugin 0.1 (BETA) */

s.getPageVisibility=new Function("",""

+"var s=this;if(s.getVisitStart()){s.Util.cookieWrite('s_pvs','');s.U"

+"til.cookieWrite('s_tps','');}if(s.Util.cookieRead('s_pvs')&&s.pvt<1"

+"){if(parseInt(s.Util.cookieRead('s_pvs'))<=parseInt(s.Util.cookieRe"

+"ad('s_tps'))){s.Util.cookie"

+"Write('s_pvs','');s.Util.cookieWrite('s_tps','');}}s.pvi=setInterval(s.pvx,100"

+"0);s.wpvi=setInterval(s.wpvc,5000);");

s.gbp=new Function("",""

+"if('hidden'in document){return null;}var bp=['moz','ms','o','webkit"

+"'];for(var i=0;i<bp.length;i++){var p=bp[i]+'Hidden';if(p in docume"

+"nt){return bp[i];}}return null;");

s.hp=new Function("p",""

+"if(p){return p+'Hidden';}else{return'hidden';}");

s.vs=new Function("p",""

+"if(p){return p+'VisibilityState';}else{return'visibilityState';}");

s.ve=new Function("p",""

+"if(p){return p+'visibilitychange';}else{return'visibilitychange';}");

s.pvx=new Function("",""

+"s.pvt+=1;");

s.wpvc = function(){var tempDate = Date.now();s.Util.cookieWrite('s_tps',

Math.ceil((tempDate - s.totalTime)/1000));s.Util.cookieWrite('s_pvs', s.pvt)}

document.addEventListener('visibilitychange',function(event){if(document.hidden){s.visibility = false;clearTimeout(s.pvi);}else{s.visibility=true;s.pvi=setInterval(s.pvx,1000);}});s.totalTime=new Date();s.pvt=0;s.prefix=s.gbp;s.hidden=s.hp(s.prefix);s.visibility=true;s.visibilityState=s.vs(s.prefix);s.visibilityEvent=s.ve(s.prefix);

and added following rows to doPlugins function

if (s.c_r("s_tps") > 0)

    s.eVar10= s.c_r("s_tps");

s.getPageVisibility();

3 replies

Andrey_Osadchuk
Level 10
July 5, 2019

Hi Cathyc,

The plugins requires 4 variables: one eVar for capturing the pageName value and 3 events (two of them are optional) that will become metrics. If you implement it according to that documentation, all the values will be set automatically.

So in your case the minimal setup will contain one eVar and one event that you need to configure in the report suite manager and also set in the implementation code (see the doc).

Level 2
July 5, 2019

Yes, I see. But we don't need eVar for previous page name. We just want to define Total Page Visibility to eVar (not to events as how in documentation mention s.pvel='event7,event8,event9'), something like this s.pvel=' ,eVar10, '

cathyc18262486AuthorAccepted solution
Level 2
July 19, 2019

Configured. Redesign a little bit plugin (also added s.getVisitStart function, which is missed in documentation)

/* Plugin: Visit Start */

s.getVisitStart = new Function("c", "var s=this,v=1,t=new Date;t.setTime(t.getTime()+1800000);if(s.c_r(c)){v=0}if(!s.c_w(c,1,t)){s.c_w(c,1,0)}if(!s.c_r(c)){v=0}return v;");

/* Page Visibility Plugin 0.1 (BETA) */

s.getPageVisibility=new Function("",""

+"var s=this;if(s.getVisitStart()){s.Util.cookieWrite('s_pvs','');s.U"

+"til.cookieWrite('s_tps','');}if(s.Util.cookieRead('s_pvs')&&s.pvt<1"

+"){if(parseInt(s.Util.cookieRead('s_pvs'))<=parseInt(s.Util.cookieRe"

+"ad('s_tps'))){s.Util.cookie"

+"Write('s_pvs','');s.Util.cookieWrite('s_tps','');}}s.pvi=setInterval(s.pvx,100"

+"0);s.wpvi=setInterval(s.wpvc,5000);");

s.gbp=new Function("",""

+"if('hidden'in document){return null;}var bp=['moz','ms','o','webkit"

+"'];for(var i=0;i<bp.length;i++){var p=bp[i]+'Hidden';if(p in docume"

+"nt){return bp[i];}}return null;");

s.hp=new Function("p",""

+"if(p){return p+'Hidden';}else{return'hidden';}");

s.vs=new Function("p",""

+"if(p){return p+'VisibilityState';}else{return'visibilityState';}");

s.ve=new Function("p",""

+"if(p){return p+'visibilitychange';}else{return'visibilitychange';}");

s.pvx=new Function("",""

+"s.pvt+=1;");

s.wpvc = function(){var tempDate = Date.now();s.Util.cookieWrite('s_tps',

Math.ceil((tempDate - s.totalTime)/1000));s.Util.cookieWrite('s_pvs', s.pvt)}

document.addEventListener('visibilitychange',function(event){if(document.hidden){s.visibility = false;clearTimeout(s.pvi);}else{s.visibility=true;s.pvi=setInterval(s.pvx,1000);}});s.totalTime=new Date();s.pvt=0;s.prefix=s.gbp;s.hidden=s.hp(s.prefix);s.visibility=true;s.visibilityState=s.vs(s.prefix);s.visibilityEvent=s.ve(s.prefix);

and added following rows to doPlugins function

if (s.c_r("s_tps") > 0)

    s.eVar10= s.c_r("s_tps");

s.getPageVisibility();