Expand my Community achievements bar.

Help shape the future of AI assistance by participating in this quick card sorting activity. Your input will help create a more effective system that better serves your needs and those of your colleagues.
SOLVED

Time to Complete Plugin not being recorded as an eVar

Avatar

Level 1

Hi Community,

 

I'm trying to set-up the Time to Complete plugin to record the duration of a workflow on our site but I'm having some difficulty getting the function to work. I am seeing the cookie value being recorded when the first event triggers the starting point; then the cookie clears when the function should end, but I'm not seeing any value being stored as an eVar within the debugger. I have also included the getTimeSinceLastVisit plugin function as a check and that seems to be working correctly. Any insight is appreciated, thanks in advance.

 

For reference, below is a screenshot of the code added into the Analytics Extension in Launch, as well as a screenshot of the cookie value once the process starts.:

 

MAC_13_0-1665756309269.png

 

/* Plugin Config */
s.usePlugins=true
s.doPlugins=function(s) {

// Add calls here
s.eVar101 = getTimeSinceLastVisit();
if(s.events.indexOf("event11") > -1) getTimeToComplete("start");
if(s.events.indexOf("event12") > -1) s.eVar103 = getTimeToComplete("stop");

}

// Add plugin functions below here

/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* ACP: getTimeSinceLastVisit */
function getTimeSinceLastVisit(){if(arguments&&"-v"===arguments[0])return{plugin:"getTimeSinceLastVisit",version:"2.0"};var h=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 h&&(h.contextData.getTimeSinceLastVisit="2.0");window.formatTime=window.formatTime||function(c,b,d){function f(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 e="";"string"===typeof b&&"d"===b||("string"!==typeof b||!f("h,m,s",b))&&86400<=c?(b=86400,e="days",d=isNaN(d)?1:b/(d*b)):"string"===typeof b&&"h"===b||("string"!==typeof b||!f("m,s",b))&&3600<=c?(b=3600,e="hours",d=isNaN(d)?4:b/(d*b)):"string"===typeof b&&"m"===b||("string"!==typeof b||!f("s",b))&&60<=c?(b=60,e="minutes",d=isNaN(d)?2:b/(d*b)):(b=1,e="seconds",d=isNaN(d)?.2:b/d);e=Math.round(c*d/b)/d+" "+e;0===e.indexOf("1 ")&&(e=e.substring(0,e.length-1));return e}};window.cookieWrite=window.cookieWrite||function(c,b,d){if("string"===typeof c){var f=window.location.hostname,e=window.location.hostname.split(".").length-1;if(f&&!/^[0-9.]+$/.test(f)){e=2<e?e:2;var k=f.lastIndexOf(".");if(0<=k){for(;0<=k&&1<e;)k=f.lastIndexOf(".",k-1),e--;k=0<k?f.substring(k):f}}g=k;b="undefined"!==typeof b?""+b:"";if(d||""===b)if(""===b&&(d=-60),"number"===typeof d){var h=new Date;h.setTime(h.getTime()+6E4*d)}else h=d;return c&&(document.cookie=encodeURIComponent(c)+"="+encodeURIComponent(b)+"; path=/;"+(d?" expires="+h.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+"="),f=0>d?d:b.indexOf(";",d);return(c=0>d?"":decodeURIComponent(b.substring(d+2+c.length,0>f?b.length:f)))?c:""};h=new Date;var m=h.getTime(),n=cookieRead("s_tslv")||0,l=Math.round((m-n)/1E3);h.setTime(m+63072E6);cookieWrite("s_tslv",m,h);return n?1800<l||cookieRead("s_inv")?(cookieRead("s_inv")&&(l=cookieRead("s_inv")),cookieWrite("s_inv",l,30),"0"!==l?formatTime(l):"New Visitor"):"":(cookieWrite("s_inv","0",30),"New Visitor")};
/******************************************** END CODE TO DEPLOY ********************************************/

/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* ACP: getTimeToComplete */
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 ********************************************/

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Indeed, there's nothing in the getTimeToComplete plugin that indicates it works with Page View beacons only.

Having said that, for Custom Link beacons to track variables, you need to list those variables in s.linkTrackVars. So have you set eVar103 in s.linkTrackVars? E.g.

// list the variables that should be tracked with the Custom Link beacon
s.linkTrackVars = 'eVar103';

// set the variables
s.eVar103 = getTimeToComplete('stop');

Reference: https://experienceleague.adobe.com/docs/analytics/implementation/vars/config-vars/linktrackvars.html...

View solution in original post

4 Replies

Avatar

Community Advisor

In your browser, what domain is the "s_gttc" cookie being saved to? I'm wondering if the cookie is being saved to a domain that is not accessible at the web page where the "stop" event occurs.

Avatar

Level 1

Thanks for the reply. It's all self-contained within the same site so the "s_gttc" cookie domain is consistent across the workflow. I actually made some changes to experiment and am seeing the TTC value being recorded when the "stop" command occurs during a page view call but not when it's a link tracking one (which is where I'd ultimately need it to occur). 

 

From what I've read it should work for both types but do you by chance have any idea why it may not be firing during a link tracking call?

 

 

Avatar

Correct answer by
Community Advisor

Indeed, there's nothing in the getTimeToComplete plugin that indicates it works with Page View beacons only.

Having said that, for Custom Link beacons to track variables, you need to list those variables in s.linkTrackVars. So have you set eVar103 in s.linkTrackVars? E.g.

// list the variables that should be tracked with the Custom Link beacon
s.linkTrackVars = 'eVar103';

// set the variables
s.eVar103 = getTimeToComplete('stop');

Reference: https://experienceleague.adobe.com/docs/analytics/implementation/vars/config-vars/linktrackvars.html...

Avatar

Level 1

I completely forgot about setting that.

 

Thank you so much. It now works as expected.