Adobe 插件:getTimeToComplete

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

getTimeToComplete 插件可跟踪用户在网站上完成某个流程所需的时间。“时钟”在调用 start 操作时开始,并在调用 stop 操作时结束。如果网站上的某个工作流程需要花一些时间才能完成,并且您希望了解访客完成该工作流程所用的时间,Adobe 建议使用此插件。如果网站上的工作流程需要很短时间(少于 3 秒)即可完成,则无需使用此插件,因为可测量的最小时间粒度为 1 秒。

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

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

使用Adobe Analytics扩展安装此插件

Adobe提供了一个扩展,通过该扩展,您可以将最常用的插件与Adobe Analytics结合使用。

  1. 使用您的 Adobe ID 凭据登录 Adobe Experience Platform 数据收集

  2. 单击所需的标记属性。

  3. 转到扩展选项卡,然后单击目录按钮

  4. 安装并发布常用 Analytics 插件扩展

  5. 如果还没有任何扩展,请使用以下配置创建一个标签为“初始化插件”的规则:

    • 条件:无
    • 事件:核心 - 已加载的库(页面顶部)
  6. 使用以下配置向上述规则添加操作:

    • 扩展:常用 Analytics 插件
    • 操作类型:初始化 getTimeToComplete
  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: getTimeToComplete v4.0 */
function getTimeToComplete(sos,cn,exp,tp){var f=sos,m=cn,l=exp,e=tp;if("-v"===f)return{plugin:"getTimeToComplete",version:"4.0"};var k=function(){if("undefined"!==typeof window.s_c_il)for(var c=0,b;c<window.s_c_il.length;c++)if(b=window.s_c_il[c],b._c&&"s_c"===b._c)return b}();"undefined"!==typeof k&&(k.contextData.getTimeToComplete="4.0");window.formatTime=window.formatTime||function(c,b,d){function e(b,d,c,e){if("string"!==typeof d)return!1;if("string"===typeof b)b=b.split(c||",");else if("object"!==typeof b)return!1;c=0;for(a=b.length;c<a;c++)if(1==e&&d===b[c]||d.toLowerCase()===b[c].toLowerCase())return!0;return!1}if(!("undefined"===typeof c||isNaN(c)||0>Number(c))){var h="";"string"===typeof b&&"d"===b||("string"!==typeof b\||!e("h,m,s",b))&&86400<=c?(b=86400,h="days",d=isNaN(d)?1:b/(d*b)):"string"===typeof b&&"h"===b||("string"!==typeof b||!e("m,s",b))&&3600<=c?(b=3600,h="hours",d=isNaN(d)?4:b/(d*b)):"string"===typeof b&&"m"===b||("string"!==typeof b||!e("s",b))&&60<=c?(b=60,h="minutes",d=isNaN(d)?2:b/(d*b)):(b=1,h="seconds",d=isNaN(d)?.2:b/d);h=Math.round(c*d/b)/d+" "+h;0===h.indexOf("1 ")&&(h=h.substring(0,h.length-1));return h}};window.cookieWrite=window.cookieWrite||function(c,b,d){if("string"===typeof c){var e=window.location.hostname,h=window.location.hostname.split(".").length-1;if(e&&!/^[0-9.]+$/.test(e)){h=2<h?h:2;var f=e.lastIndexOf(".");if(0<=f){for(;0<=f&&1<h;)f=e.lastIndexOf(".",f-1),h--;f=0<f?e.substring(f):e}}g=f;b="undefined"!==typeof b?""+b:"";if(d||""===b)if(""===b&&(d=-60),"number"===typeof d){var k=new Date;k.setTime(k.getTime()+6E4*d)}else k=d;return c&&(document.cookie=encodeURIComponent(c)+"="+encodeURIComponent(b)+"; path=/;"+(d?" expires="+k.toUTCString()+";":"")+(g?" domain="+g+";":""),"undefined"!==typeof cookieRead)?cookieRead(c)===b:!1}};window.cookieRead=window.cookieRead||function(c){if("string"===typeof c)c=encodeURIComponent(c);else return"";var b=" "+document.cookie,d=b.indexOf(" "+c+"="),e=0>d?d:b.indexOf(";",d);return(c=0>d?"":decodeURIComponent(b.substring(d+2+c.length,0>e?b.length:e)))?c:""};f=f?f.toLowerCase():"start";if("stop"===f||"start"===f){m=m?m:"s_gttc";e?e="d"===e?864E5:"h"===e?36E5:"s"===e?1E3:6E4:(l=30,e=6E4);l=isNaN(l)?30:l;l*=e;k=cookieRead(m);e=new Date;if("stop"===f&&k)return l=Math.round((e.getTime()-k)/1E3),cookieWrite(m,"",0),formatTime(l);"start"!==f||k?k&&Number(k)<e.getTime()+18E5&&cookieWrite(m,k,30):(f=String(e.getTime()),e.setTime(e.getTime()+l),cookieWrite(m,f,e))}};
/******************************************** END CODE TO DEPLOY ********************************************/

使用此插件

getTimeToComplete 函数使用以下参数:

  • sos(可选,字符串):要启动计时器时设置为 "start"。要停止计时器时设置为 "stop"。默认为 "start"
  • cn(可选,字符串):用于存储开始时间的 Cookie 的名称。默认为 "s_gttc"
  • exp(可选,整数):Cookie(和计时器)过期的秒数、小时数或天数(具体取决于 tp 分时参数)。默认为 30 分钟。
  • tp(可选,字符串):Cookie(和计时器)过期的分时字符串,与 exp 参数一起使用。设置为“d”表示天数,设置为“h”表示小时数,设置为“s”表示秒数。如果未设置,Cookie(和计时器)过期时间默认为 30 分钟,无论将 exp 参数设置为何值。

调用此函数将返回一个字符串,其中包含从 "start""stop" 操作所用的时间(天数、小时数、分钟数和/或秒数)。

示例

// Start the timer when the visitor starts the checkout
if(s.events.indexOf("scCheckout") > -1) getTimeToComplete("start");

// Stop the timer when the visitor makes the purchase and set prop1 to the time difference between stop and start
// Sets prop1 to the amount of time it took to complete the purchase process
if(s.events.indexOf("purchase") > -1) s.prop1 = getTimeToComplete("stop");

// Simultaneously track the time it takes to complete a purchase and to fill out a registration form
// Stores each timer in their own respective cookies so they run independently
if(inList(s.events, "scCheckout")) getTimeToComplete("start", "gttcpurchase");
if(inList(s.events, "purchase")) s.prop1 = getTimeToComplete("start", "gttcpurchase");
if(inList(s.events, "event1")) getTimeToComplete("start", "gttcregister", 7, "d");
if(inList(s.events, "event2")) s.prop2 = getTimeToComplete("stop", "gttcregister", 7, "d");

版本历史记录

4.0(2021 年 3 月 19 日)

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

3.1(2019 年 9 月 30 日)

  • 添加了要求第一个参数中的值只能为“start”或“stop”的逻辑。传入的所有其他值都会阻止插件运行。
  • 已将 inList 2.0 插件更新为 inList 2.1

3.0(2018 年 8 月 23 日)

  • 已将 formatTime v1.0 插件更新为 formatTime v1.1

3.0(2018 年 4 月 17 日)

  • 修正版本(重新编译,代码更小)。
  • 若干小错误修复。

2.0(2016 年 6 月 21 日)

  • 消除了对 p_fo 插件的依赖性。
  • 增加了与 H 代码和 AppMeasurement 的兼容性。
  • 添加了控制台日志记录。
recommendation-more-help
b4f6d761-4a8b-4322-b801-c85b9e3be690