Adobe plug-in: getVisitDuration


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 getVisitDuration plug-in tracks the amount of time in minutes that the visitor has been on the site up to that point. Adobe recommends using this plug-in if you want to track cumulative time on the site up to that point, or to track the time it takes to perform an activity. This plug-in does not track the amount of time between events; if this functionality is desired, use the getTimeBetweenEvents plug-in.

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 getVisitDuration
  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: getVisitDuration v2.1 */
function getVisitDuration(){if(arguments&&"-v"===arguments[0])return{plugin:"getVisitDuration",version:"2.1"};var d=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 d&&(d.contextData.getVisitDuration="2.1");window.cookieWrite=window.cookieWrite||function(c,b,f){if("string"===typeof c){var h=window.location.hostname,a=window.location.hostname.split(".").length-1;if(h&&!/^[0-9.]+$/.test(h)){a=2<a?a:2;var e=h.lastIndexOf(".");if(0<=e){for(;0<=e&&1<a;)e=h.lastIndexOf(".",e-1),a--;e=0<e?h.substring(e):h}}g=e;b="undefined"!==typeof b?""+b:"";if(f||""===b)if(""===b&&(f=-60),"number"===typeof f){var d=new Date;d.setTime(d.getTime()+6E4*f)}else d=f;return c&&(document.cookie=encodeURIComponent(c)+"="+encodeURIComponent(b)+"; path=/;"+(f?" expires="+d.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,a=b.indexOf(" "+c+"="),d=0>a?a:b.indexOf(";",a);return(c=0>a?"":decodeURIComponent(b.substring(a+2+c.length,0>d?b.length:d)))?c:""};d=(new Date).getTime();var k=cookieRead("s_dur"),a=0;if(isNaN(k)||18E5<d-k)k=d;a=d-k;cookieWrite("s_dur",k+"",30);if(0===a)return"first hit of visit";a=Math.floor(a/6E4);return 0===a?"less than a minute":1===a?"1 minute":a+" minutes"};
/******************************************** END CODE TO DEPLOY ********************************************/

Use the plug-in

The getVisitDuration method does not use any arguments. It returns one of the following values:

  • "first hit of visit"
  • "less than a minute"
  • "1 minute"
  • "[x] minutes" (where [x] is the number of minutes passed since the visitor landed on the site)

This plug-in creates a first-party cookie called "s_dur", which is the number of milliseconds elapsed since the visitor landed on the site. The cookie expires after 30 minutes of inactivity.

Example Calls

Example #1

The following code…

s.eVar10 = s.getVisitDuration();

…will always set eVar10 equal to the number of minutes passed since the visitor landed on the site

Example #2

The following code…

if(s.inList(, "purchase")) s.eVar10 = s.getVisitDuration();

…uses the inList plug-in to check whether the events variable contains the purchase event. If so, then eVar10 will be set equal to the number of minutes between the visitor’s start of the visit and the time of purchase.

Example #3

The following code…

s.prop10 = s.getVisitDuration();

…will always set prop10 equal to the number of minutes passed since the visitor landed on the site. This will be useful if prop10 has pathing enabled. Adding the “exits” metric to the prop10 report will show a granular, “scatterplot” report of how long a visit took in minutes before a visitor left the site.

Version History

2.1 (March 19, 2021)

  • Added version number as context data.

2.0 (May 2, 2018)

  • Point release (complete reanalysis/rewrite of plug-in).

On this page