Adobe 插件:getPageLoadTime

重要

此插件由 Adobe Consulting 团队提供,旨在帮助您从 Adobe Analytics 中获取更多的价值。Adobe 客户关怀团队不提供对此插件的支持,包括安装或疑难解答。如果您需要关于此插件的帮助,请与您组织的 Adobe 客户团队联系。他们可为您安排与顾问会面以寻求帮助。

getPageLoadTime 插件使用 JavaScript 性能对象来让您可以测量页面完全加载所需的时间。如果您想要测量页面加载所需的时间,Adobe 建议您使用此插件。

注意/警告:如果您从早期版本升级此插件,您很可能还需要更改调用此函数的代码。在部署到生产环境之前,请检查您的实施并彻底测试

使用Web SDK或Web SDK扩展安装此插件

尚不支持在Web SDK中使用此插件。

使用Adobe Analytics扩展安装插件

Adobe提供了一个扩展,允许您将最常用的插件与Adobe Analytics一起使用。

  1. 使用您的 Adobe ID 凭据登录 Adobe Experience Platform 数据收集
  2. 单击所需的标记属性。
  3. 转到扩展选项卡,然后单击目录按钮
  4. 安装并发布常用 Analytics 插件扩展
  5. 如果还没有任何扩展,请使用以下配置创建一个标签为“初始化插件”的规则:
    • 条件:无
    • 事件:核心 - 已加载的库(页面顶部)
  6. 使用以下配置向上述规则添加操作:
    • 扩展:常用 Analytics 插件
    • 操作类型:初始化 getPageLoadTime
  7. 保存并发布对上述规则所做的更改。

使用自定义代码编辑器安装此插件

如果您不想使用“常用Analytics插件”插件扩展,则可以使用自定义代码编辑器。

  1. 使用您的 Adobe ID 凭据登录 Adobe Experience Platform 数据收集
  2. 单击所需的属性。
  3. 转到扩展选项卡,然后单击 Adobe Analytics 扩展下的​配置​按钮。
  4. 展开使用自定义代码配置跟踪折叠面板,这会显示打开编辑器按钮。
  5. 打开自定义代码编辑器,并将下面提供的插件代码粘贴到编辑窗口中。
  6. 保存并发布对此 Analytics 扩展所做的更改。

使用 AppMeasurement 安装此插件

在实例化(使用 s_gi)Analytics 跟踪对象后,将以下代码复制并粘贴到 AppMeasurement 文件中的任意位置。在您的实施中保留代码的注释和版本号可帮助 Adobe 对任何潜在问题进行疑难解答。

/******************************************* 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 ********************************************/

使用此插件

getPercentPageViewed 函数使用以下参数:

  • pv(可选,字符串):要与页面加载时间关联的维度。此值应等于标识页面本身的值。如果未设置,此参数将默认为 Adobe AppMeasurement pageName 变量(即 s.pageName)或未设置 s.pageName 时的 URL

调用此函数时,不会返回任何内容;但是,会设置以下变量:

  • window._pltPreviousPage:上一页的值(即传入 pv 参数的内容)
  • window._pltLoadTime:加载上一页所用的时间(以秒为单位)

getPageLoadTime 插件会创建一个第一方 Cookie:

  • s_plt:加载上一页所用的时间(以秒为单位)。还包含已传入 pv 参数的内容的值。将在浏览器会话结束时过期。

示例

// 1. Run the getPageLoadTime function if the pageName variable is set
// 2. Set prop10 to the load time of the previous page
// 3. Set eVar10 to the name of the previous page
// 4. Set event100 to the load time (in seconds) of the previous page. A numeric event is required to capture this value.
// You can then use event100 in calculated metrics to obtain the average page load time per page.
if(s.pageName) getPageLoadTime();
if(window._pltPreviousPage)
{
  s.prop10 = window._pltLoadTime;
  s.eVar10 = window._pltPreviousPage
  s.events = "event100=" + window._pltLoadTime;
}

版本历史记录

3.0(2022 年 12 月 6 日)

  • 完全重写插件以使其与解决方案无关。例如,它现在与 AEP Web SDK 兼容
  • 在窗口对象(而不是 AppMeasurement s 对象)中创建 _pltPreviousPage_pltLoadTime 变量
  • 消除了对 s_pltp Cookie 的需求;现在,所有内容都只存储在 s_plt Cookie 中
  • 包括 getVersion 函数以帮助进行故障排除

2.0.1(2021 年 3 月 26 日)

  • 解决了插件未正确对 s 对象设置值的问题。

2.0(2021 年 3 月 19 日)

  • 以上下文数据形式添加了版本号。

1.0(2018 年 5 月 22 日)

  • 第一版。

在此页面上