Adobe plug-in: getTimeToComplete


This plug-in is provided by Adobe Consulting as a courtesy to help you get more value out of Adobe Analytics. Adobe Customer Care does not provide support with this plug-in, including installation or troubleshooting. If you require help with this plug-in, contact your organization’s Account Manager. They can arrange a meeting with a consultant for assistance.

The getTimeToComplete plug-in tracks the time a user takes to complete a process on a site. The “clock” begins when the start action is called and ends when the stop action is called. Adobe recommends using this plug-in if there is a workflow on the site that takes some time to complete and you would like to know how much time visitors take to complete it. It is unnecessary to use this plug-in if the workflow on your site takes a short period of time (less than 3 seconds) because the granularity is only down to the full second.

Install the plug-in using the Adobe Experience Platform Launch extension

Adobe offers an extension that allows you to use most commonly-used plug-ins.

  1. Log in to using your AdobeID credentials.
  2. Click the desired property.
  3. Go to the Extensions tab, then click on the Catalog button
  4. Install and publish the Common Analytics Plugins extension
  5. If you haven’t already, create a rule labeled “Initialize Plug-ins” with the following configuration:
    • Condition: None
    • Event: Core – Library Loaded (Page Top)
  6. Add an action to the above rule with the following configuration:
    • Extension: Common Analytics Plugins
    • Action Type: Initialize getTimeToComplete
  7. Save and publish the changes to the rule.

Install the plug-in using Launch custom code editor

If you do not want to use the plug-in extension, you can use the custom code editor.

  1. Log in to using your AdobeID credentials.
  2. Click on the desired property.
  3. Go to the Extensions tab, then click the Configure button under the Adobe Analytics extension.
  4. Expand the Configure tracking using custom code accordion, which reveals the Open Editor button.
  5. Open the custom code editor and paste the plug-in code provided below into the edit window.
  6. Save and publish the changes to the Analytics extension.

Install the plug-in using AppMeasurement

Copy and paste the following code anywhere in the AppMeasurement file after the Analytics tracking object is instantiated (using s_gi). Preserving comments and version numbers of the code in your implementation helps Adobe with troubleshooting any potential issues.

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

Use the plug-in

The getTimeToComplete method uses the following arguments:

  • sos (optional, string): Set to "start" when you want to start the timer. Set to "stop" when you want to stop the timer. Defaults to "start".
  • cn (optional, string): The name of the cookie to store the start time. Defaults to "s_gttc".
  • exp (optional, integer): The number of days that the cookie (and timer) expires. Defaults to 0, which represents the end of the browser session.

Calling this method returns a string that contains the number of days, hours, minutes and/or seconds it took between the "start" and "stop" action.

Example Calls

Example #1

Use these calls to determine the time between when a visitor starts the checkout process and when they make a purchase.

Start the timer when the visitor starts the checkout:

if("scCheckout") > -1) s.getTimeToComplete("start");

Stop the timer when the visitor makes the purchase and set prop1 to the time difference between stop and start:

if("purchase") > -1) s.prop1 = s.getTimeToComplete("stop");

s.prop1 will capture the amount of time needed to complete the purchase process

Example #2

If you want to have several timers running at the same time (to measure different processes), you will need to manually set the cn cookie argument. For example, if you want to measure the amount of time needed for a purchase to complete, you would set the following code…

if(s.inList(, "scCheckout")) s.getTimeToComplete("start", "gttcpurchase");
if(s.inList(, "purchase")) s.prop1 = s.getTimeToComplete("start", "gttcpurchase");

…but if you also wanted to measure (at the same time) the amount of time needed for a registration form to be filled out, you would run the following code as well:

if(s.inList(, "event1")) s.getTimeToComplete("start", "gttcregister", 7);
if(s.inList(, "event2")) s.prop2 = s.getTimeToComplete("stop", "gttcregister", 7);

In the second example, event1 is meant to capture the beginning of a registration process that could take up to 7 days to complete, for whatever reason, and event2 is meant to capture the completion of the registration. s.prop2 will capture the amount of time needed to complete the registration process

Version History

4.0 (March 19, 2021)

  • Added version number as context data.

3.1 (September 30, 2019)

  • Added logic that requires a value of either “start” or “stop” in the first argument. All other values passed in stop the plug-in from running.
  • Updated inList 2.0 plug-in to inList 2.1.

3.0 (August 23, 2018)

  • Updated the formatTime v1.0 plug-in to formatTime v1.1.

3.0 (April 17, 2018)

  • Point release (recompiled, smaller code size).
  • Minor bug fixes.

2.0 June 21, 2016)

  • Eliminated the dependency on the p_fo plug-in.
  • Added compatibility with H-code and AppMeasurement.
  • Added console logging.

On this page

Adobe Summit Banner

A virtual event April 27-28.

Expand your skills and get inspired.

Register for free
Adobe Summit Banner

A virtual event April 27-28.

Expand your skills and get inspired.

Register for free
Adobe Maker Awards Banner

Time to shine!

Apply now for the 2021 Adobe Experience Maker Awards.

Apply now
Adobe Maker Awards Banner

Time to shine!

Apply now for the 2021 Adobe Experience Maker Awards.

Apply now