load time for page | Community
Skip to main content
August 28, 2023
Solved

load time for page

  • August 28, 2023
  • 2 replies
  • 5382 views

I have implemeted custom script as in picture below, how can i show page load time for each pagename in report?

all variables prop60, evar60 and event100 coming as undefined in report?

 

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 Jennifer_Dungan

Where is this custom script implemented? 

 

I believe as this is part of a plugin, it should be added to the "doPlugins" section in the custom code of the extension.

 

If this is currently just a custom code block, it may not be reading the s object correctly and may be throwing a behind the scenes issue.

 

 

In your Extension, I believe the code should look like:

 

s.usePlugins = true; function s_doPlugins(s) { if(s.pageName) getPageLoadTime(); if(window._pltPreviousPage) { s.prop60 = window._pltLoadTime; s.eVar60 = window._pltPreviousPage s.events = "event100=" + window._pltLoadTime; } } /******************************************* BEGIN CODE TO DEPLOY *******************************************/ /* Adobe Consulting Plugin: getPageLoadTime v3.0 */ !function(){let e=globalThis.window||this;e.getPageLoadTime=function(t){let i=function(){if(e.s_c_il){for(let t in e.s_c_il)if("s_c"===e.s_c_il[t]._c)return e.s_c_il[t]}}();function n(){var i=performance.timing;i.loadEventEnd>0&&(clearInterval(e.pi),""===e.cookieRead("s_plt")&&e.cookieWrite("s_plt",function e(t,i){if(t>=0&&i>=0)return t-i<6e4&&t-i>=0?parseFloat((t-i)/1e3).toFixed(2):60}(i.loadEventEnd,i.navigationStart)+","+t)),e.ptc=i.loadEventEnd}if(i&&(i.contextData.getPageLoadTime="3.1"),t=t||i&&i.pageName||document.location.href,e.cookieWrite=e.cookieWrite||function(t,i,n){if("string"==typeof t){if(g=function(){var t=e.location.hostname,i=e.location.hostname.split(".").length-1;if(t&&!/^[0-9.]+$/.test(t)){i=2<i?i:2;var n=t.lastIndexOf(".");if(0<=n){for(;0<=n&&1<i;)n=t.lastIndexOf(".",n-1),i--;n=0<n?t.substring(n):t}}return n}(),i=void 0!==i?""+i:"",n||""===i){if(""===i&&(n=-60),"number"==typeof n){var o=new Date;o.setTime(o.getTime()+6e4*n)}else o=n}return!!t&&(document.cookie=encodeURIComponent(t)+"="+encodeURIComponent(i)+"; path=/;"+(n?" expires="+o.toUTCString()+";":"")+(g?" domain="+g+";":""),"undefined"!=typeof cookieRead)&&cookieRead(t)===i}},e.cookieRead=e.cookieRead||function(e){if("string"!=typeof e)return"";e=encodeURIComponent(e);var t=" "+document.cookie,i=t.indexOf(" "+e+"="),n=0>i?i:t.indexOf(";",i);return(e=0>i?"":decodeURIComponent(t.substring(i+2+e.length,0>n?t.length:n)))?e:""},e.p_fo=e.p_fo||function(t){return e.__fo||(e.__fo={}),!e.__fo[t]&&(e.__fo[t]={},!0)},performance&&e.p_fo("performance")){var o=performance;o.clearResourceTimings(),""!==e.cookieRead("s_plt")&&(o.timing.loadEventEnd>0&&clearInterval(e.pi),this._pltLoadTime=e.cookieRead("s_plt").split(",")[0],this._pltPreviousPage=e.cookieRead("s_plt").split(",")[1],e.cookieWrite("s_plt","")),0===o.timing.loadEventEnd?e.pi=setInterval(function(){n()},250):o.timing.loadEventEnd>0&&(e.ptc?e.ptc===o.timing.loadEventEnd&&1===o.getEntries().length&&(e.pwp=setInterval(function(){var i;(i=performance).getEntries().length>0&&(e.ppfe===i.getEntries().length?clearInterval(e.pwp):e.ppfe=i.getEntries().length),""===e.cookieRead("s_plt")&&e.cookieWrite("s_plt",((i.getEntries()[i.getEntries().length-1].responseEnd-i.getEntries()[0].startTime)/1e3).toFixed(2)+","+t)},500)):n())}},e.getPageLoadTime.getVersion=function(){return{plugin:"getPageLoadTime",version:"3.0"}}}(); /******************************************** END CODE TO DEPLOY ********************************************/

2 replies

Jennifer_Dungan
Community Advisor and Adobe Champion
Jennifer_DunganCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
August 28, 2023

Where is this custom script implemented? 

 

I believe as this is part of a plugin, it should be added to the "doPlugins" section in the custom code of the extension.

 

If this is currently just a custom code block, it may not be reading the s object correctly and may be throwing a behind the scenes issue.

 

 

In your Extension, I believe the code should look like:

 

s.usePlugins = true; function s_doPlugins(s) { if(s.pageName) getPageLoadTime(); if(window._pltPreviousPage) { s.prop60 = window._pltLoadTime; s.eVar60 = window._pltPreviousPage s.events = "event100=" + window._pltLoadTime; } } /******************************************* BEGIN CODE TO DEPLOY *******************************************/ /* Adobe Consulting Plugin: getPageLoadTime v3.0 */ !function(){let e=globalThis.window||this;e.getPageLoadTime=function(t){let i=function(){if(e.s_c_il){for(let t in e.s_c_il)if("s_c"===e.s_c_il[t]._c)return e.s_c_il[t]}}();function n(){var i=performance.timing;i.loadEventEnd>0&&(clearInterval(e.pi),""===e.cookieRead("s_plt")&&e.cookieWrite("s_plt",function e(t,i){if(t>=0&&i>=0)return t-i<6e4&&t-i>=0?parseFloat((t-i)/1e3).toFixed(2):60}(i.loadEventEnd,i.navigationStart)+","+t)),e.ptc=i.loadEventEnd}if(i&&(i.contextData.getPageLoadTime="3.1"),t=t||i&&i.pageName||document.location.href,e.cookieWrite=e.cookieWrite||function(t,i,n){if("string"==typeof t){if(g=function(){var t=e.location.hostname,i=e.location.hostname.split(".").length-1;if(t&&!/^[0-9.]+$/.test(t)){i=2<i?i:2;var n=t.lastIndexOf(".");if(0<=n){for(;0<=n&&1<i;)n=t.lastIndexOf(".",n-1),i--;n=0<n?t.substring(n):t}}return n}(),i=void 0!==i?""+i:"",n||""===i){if(""===i&&(n=-60),"number"==typeof n){var o=new Date;o.setTime(o.getTime()+6e4*n)}else o=n}return!!t&&(document.cookie=encodeURIComponent(t)+"="+encodeURIComponent(i)+"; path=/;"+(n?" expires="+o.toUTCString()+";":"")+(g?" domain="+g+";":""),"undefined"!=typeof cookieRead)&&cookieRead(t)===i}},e.cookieRead=e.cookieRead||function(e){if("string"!=typeof e)return"";e=encodeURIComponent(e);var t=" "+document.cookie,i=t.indexOf(" "+e+"="),n=0>i?i:t.indexOf(";",i);return(e=0>i?"":decodeURIComponent(t.substring(i+2+e.length,0>n?t.length:n)))?e:""},e.p_fo=e.p_fo||function(t){return e.__fo||(e.__fo={}),!e.__fo[t]&&(e.__fo[t]={},!0)},performance&&e.p_fo("performance")){var o=performance;o.clearResourceTimings(),""!==e.cookieRead("s_plt")&&(o.timing.loadEventEnd>0&&clearInterval(e.pi),this._pltLoadTime=e.cookieRead("s_plt").split(",")[0],this._pltPreviousPage=e.cookieRead("s_plt").split(",")[1],e.cookieWrite("s_plt","")),0===o.timing.loadEventEnd?e.pi=setInterval(function(){n()},250):o.timing.loadEventEnd>0&&(e.ptc?e.ptc===o.timing.loadEventEnd&&1===o.getEntries().length&&(e.pwp=setInterval(function(){var i;(i=performance).getEntries().length>0&&(e.ppfe===i.getEntries().length?clearInterval(e.pwp):e.ppfe=i.getEntries().length),""===e.cookieRead("s_plt")&&e.cookieWrite("s_plt",((i.getEntries()[i.getEntries().length-1].responseEnd-i.getEntries()[0].startTime)/1e3).toFixed(2)+","+t)},500)):n())}},e.getPageLoadTime.getVersion=function(){return{plugin:"getPageLoadTime",version:"3.0"}}}(); /******************************************** END CODE TO DEPLOY ********************************************/
August 31, 2023

@jennifer_dungan i added this code, what next should i do to see data in report

September 3, 2023

If the code is inside of function s_doPlugins(s) then it should run automatically every time an s.t() is called (well it will run with s.tl() as well, but the if(s.pageName) will prevent these from tracking on your actions)

 

Thus is the purpose of doPlugins... basically, you set up your rules and then trigger you beacon... if s.usePlugins is true, then as the beacon is being compiled, all the plugin code is run and attached to the beacon automatically. So that if you have 100 rules in your implementation (for different pages or features, etc), the plugin code will be applied to them all automatically, without you needing to replicate the effort.


Dear @jennifer_dungan , this plugin doesn't work but our developer calculated at page like in below screenshot, how can i create variables here in report suite and tag manager so i can show page load time for each page.

 

 

August 29, 2023

Hi @peeyushbansal 

 

Here's an example of how you can use JavaScript to measure page load time and send it as a custom event to Adobe Analytics:

 

// Measure Page Load Time
var startTime = new Date().getTime();

window.addEventListener('load', function() {
    var endTime = new Date().getTime();
    var pageLoadTime = endTime - startTime;

    // Send Page Load Time as a Custom Event to Adobe Analytics
    s.linkTrackVars = 'events,eVar60'; // Updated eVar60 to match your setup
    s.linkTrackEvents = 'event100';     // Updated event100 to match your setup
    s.events = 'event100';
    s.eVar60 = pageLoadTime;

    s.tl(true, 'o', 'Page Load Time');
});


The s.tl() function sends the custom event to Adobe Analytics.

Jennifer_Dungan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
August 29, 2023

This is horrible advice... this will inflate page view traffic by sending a second page view call.

 

The code should just be added to the correct location (i.e. in the do_plugins function, which is part of the processing after the beacons are called by the existing tagging rules.

Jennifer_Dungan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
August 29, 2023

Sorry, I see that you have s.lt() not s.t()... but page Load Time is only supposed to send on the Page View, of the existing page view call... inflating your server calls with superfluous additional calls will drive up contract costs, which is still a bad idea.