Hi Ankit,
Please use version v2.01 of getpercentpageviewed() analytics plugin , Also Please find attached documentation for the same.
How To Implement
• Copy + Paste the minified code (see below) to anywhere within the Plugins section of the AppMeasurement code
• Run the getPercentPageView function as needed within the doPlugins function (see sample calls below)
Parameters
pid (optional): current page identifier. Defaults to s.pageName OR, if s.pageName is not set, the URL
change (optional): set equal to '0' if you do not want to track dynamic changes to the page length
Returns
The getPecentPageViewed plugin returns an array of identifiers mentioned below.
• array[0] contains the identifier (e.g. the previous s.pageName value)
• array[1] contains the highest percent viewed of the previous page
• array[2] contains the percent of the previous page viewed on its initial load
• array[3] contains the highest number of vertical pixels viewed of the previous page
If pid is equal to "-", will return only the highest percent viewed of the previous page in a non-Array JavaScript variable (not recommended)
Sample Calls
Example #1
If… Previous pageName is “shop|buyflow|customize” and current pageName is “shop|buyflow|customer info”
…and the following code runs on the current page…
if(s.pageName){
var ppvArray = s.getPercentPageViewed();
}
if(typeof ppvArray != 'undefined' && typeof ppvArray[1] != 'undefined')
{
s.prop1 = 'initialpercent=' + ppvArray[2]
s.prop2 = 'highestpercent=' + ppvArray[1];
s.prop3 = ppvArray[0];
}
else{
s.prop1 = s.prop2 = s.prop3 = "";
}
… the final value of s.prop1, s.prop2,prop3 will be:
s.prop1="initialpercent=60"
s.prop2="heighestpercent=100"
s.prop3="shop|buyflow|cusotmize"
Example #2
If… Previous pageName is “shop|buyflow|customize” and current pageName is “shop|buyflow|customer info”
…and the following code runs on the current page…
if(s.pageName){
var ppvArray = s.getPercentPageViewed('','0');
}
if(typeof ppvArray != 'undefined' && typeof ppvArray[1] != 'undefined')
{
s.prop1 = 'initialpercent=' + ppvArray[2]
s.prop2 = 'highestpercent=' + ppvArray[1];
s.prop3 = ppvArray[0];
}
else{
s.prop1 = s.prop2 = s.prop3 = "";
}
… the final value of s.prop1, s.prop2,prop3 will be: will do no recalculations if the page dynamically changes its vertical height in pixels
s.prop1="initialpercent=60"
s.prop2="heighestpercent=100"
s.prop3="shop|buyflow|cusotmize"
Example #3
If… Previous pageName is “shop|buyflow|customize” and current pageName is “shop|buyflow|customer info”
…and the following code runs on the current page…
if(s.pageName){
var ppvArray = s.getPercentPageViewed();
}
if(typeof ppvArray != 'undefined' && typeof ppvArray[1] != 'undefined')
{
s.prop4 = 'highestpixel=' + ppvArray[3];
}
else{
s.prop4 "";
}
… the final value of s.prop4 will be: highest number of vertical pixels viewed of the previous page
s.prop4=" highestpixel =5132"
Example #4 (Recommanded)
If… Previous pageName is “shop:buyflow:customize” and current pageName is “shop:buyflow:customer info”
…and the following code runs on the current page…
if(s.pageName){
var ppvArray = s.getPercentPageViewed();
}
if(typeof ppvArray != 'undefined' && typeof ppvArray[1] != 'undefined')
{
s.prop1 = 'initialpercent=' + ppvArray[2]+ '|highestpercent=' + ppvArray[1]+ '|'+ ppvArray[0]+'|heightpixel =' ppvArray[3];
}
else{
s.prop1 ="";
}
… the final value of s.prop1 will be:
s.prop1="initialpercent=60| heighestpercent=100|shop:buyflow:cusotmize|highestpixel=5132 "
S Object Replacement
When instantiating the main AppMeasurement library object with a name other than "s", change the following portion of the plugin code from this…
s.getPercentPageViewed = function(pid, change)
…to this:
[objectname].getPercentPageViewed = function(pid, change)
Reporting/Backend Setup (Requires Admin Access)
Prop setup
Setup the Prop that will hold the Percent Page Viewed data with the following attributes:
• Name: Percent Page Viewed
• Description: Percent Page Viewed concatenated value
• List Support: Disabled
• All other attributes use the default values provided
Code Minified Code /* Plugin: getPercentPageViewed v2.01 */ s.handlePPVevents=function(){if(!s_c_il)return;for(var i=0,scill=s_c_il.length;i<scill;i++)if(typeof s_c_il[i]!="undefined"&&s_c_il[i]._c&&s_c_il[i]._c=="s_c"){var s=s_c_il[i];break}if(!s)return;if(!s.getPPVid)return;var dh=Math.max(Math.max(s.d.body.scrollHeight,s.d.documentElement.scrollHeight),Math.max(s.d.body.offsetHeight,s.d.documentElement.offsetHeight),Math.max(s.d.body.clientHeight,s.d.documentElement.clientHeight)),vph=window.innerHeight||(s.d.documentElement.clientHeight||s.d.body.clientHeight), st=window.pageYOffset||(window.document.documentElement.scrollTop||window.document.body.scrollTop),vh=st+vph,pv=Math.min(Math.round(vh/dh*100),100),c="",p=s.c_r("s_ppv").split(",")[0];if(!s.c_r("tp")||(s.unescape?s.unescape(p):decodeURIComponent(p))!=s.getPPVid||s.ppvChange=="1"&&(s.c_r("tp")&&dh!=s.c_r("tp"))){s.c_w("tp",dh);s.c_w("s_ppv","")}else c=s.c_r("s_ppv");var a=c&&c.indexOf(",")>-1?c.split(",",4):[],id=a.length>0?a[0]:escape(s.getPPVid),cv=a.length>1?parseInt(a[1]):0,p0=a.length>2?parseInt(a[2]): pv,cy=a.length>3?parseInt(a[3]):0,cn=pv>0?id+","+(pv>cv?pv:cv)+","+p0+","+(vh>cy?vh:cy):"";s.c_w("s_ppv",cn)}; s.getPercentPageViewed=function(pid,change){var s=this,ist=!s.getPPVid?true:false;pid=pid?pid:s.pageName?s.pageName:document.location.href;s.ppvChange=change?change:"1";if(typeof s.linkType!="undefined"&&s.linkType!="0"&&s.linkType!=""&&s.linkType!="e")return"";var v=s.c_r("s_ppv"),a=v.indexOf(",")>-1?v.split(",",4):[];if(a&&a.length<4){for(var i=3;i>0;i--)a[i]=i<a.length?a[i-1]:"";a[0]=""}if(a)a[0]=unescape(a[0]);if(!s.getPPVid||s.getPPVid!=pid){s.getPPVid=pid;s.c_w("s_ppv",escape(s.getPPVid));s.handlePPVevents()}if(ist)if(window.addEventListener){window.addEventListener("load", s.handlePPVevents,false);window.addEventListener("click",s.handlePPVevents,false);window.addEventListener("scroll",s.handlePPVevents,false);window.addEventListener("resize",s.handlePPVevents,false)}else if(window.attachEvent){window.attachEvent("onload",s.handlePPVevents);window.attachEvent("onclick",s.handlePPVevents);window.attachEvent("onscroll",s.handlePPVevents);window.attachEvent("onresize",s.handlePPVevents)}return pid!="-"?a:a[1]};
Thanks & Regards
Parit Mittal