getTimeBetweenEvents for web sdk implemenentation in adobe analytics | Community
Skip to main content
Level 2
October 4, 2024
Question

getTimeBetweenEvents for web sdk implemenentation in adobe analytics

  • October 4, 2024
  • 1 reply
  • 1472 views

getTimeBetweenEvents plug-in is not available for web SDK implementation, is there an alternative to it for web SDK implementation?

 

I need to find the time spent by the users between two events:

A particular use case would be the time it takes for a user to go from adding the first item to the cart to clicking "confirm order."

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

bjoern__koth
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
October 4, 2024

Hi @firefighteradi 

yeah that's indeed not possible. I guess a couple of lines of code in the might be able to solve that in the "on before event send callback code" though.

How do you pass in analytics events? meaning, do you use data.__adobe.analytics or the "Adobe Analytics ExperienceEvent Full Extension schema field group" (i.e., xdm._experience.analytics...)?

 

 

Top of my head, something like this might work, you would obviously have to take it from there and set the resulting time to which ever prop/eVar you need.

// Modify content.xdm or content.data as necessary. There is no need to wrap the // code in a function or return a value. For example: // content.xdm.web.webPageDetails.name = "Checkout"; const findEventInPayload = (eventName) => { _satellite.logger.debug(">>> findEventInPayload", eventName); if (content?.data?.__adobe?.analytics?.events?.includes?.(eventName)) { // contextdata is present // _satellite.logger.debug(">>> timer start event found in data.__adobe.analytics.events"); return true; } else if (content?.xdm?._experience?.analytics?.event1to100?.[eventName]?.value) { // _satellite.logger.debug(">>> timer start event found in xdm._experience.analytics"); return true; } return false; }; // dummy data // const content = { // xdm: { // _experience: { // analytics: { // event1to100: { // event90: { // value: "timerStart" // } // } // } // } // }, // data: { // __adobe: { // analytics: { // events: "event90", // test start // // events: "event91", // test end // } // } // } // }; // 1. set and persist timer when the event occurs // check if startEvent is present either in xdm._experience.analytics data or in data.__adobe.analytics.events const startEvent = "event90"; const endEvent = "event91"; if (findEventInPayload(startEvent)) { // persist in sessionStorage sessionStorage.setItem("timerStart", new Date().getTime().toString()); } // 2. calculate the time difference when the end event occurs if (findEventInPayload(endEvent)) { const startTimer = sessionStorage.getItem("timerStart"); if (startTimer) { const endTimer = new Date().getTime(); const timeDifference = Math.round((endTimer - parseInt(startTimer)) / 1000); // persist in sessionStorage _satellite.logger.debug(">>> timeDifference", timeDifference.toString()); // do whatever you need want to do with the data i.e., set it on the data.__adobe.analytics.eVarXYZ or so // remove startTimer sessionStorage.removeItem("timerStart"); } }

 

Cheers from Switzerland!
Level 2
October 11, 2024

Thank you this solution works. 

 

I am also curious to know the best method to setup the same for mobile app.

bjoern__koth
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
October 11, 2024

Glad that it works.

For mobile, I am unfortunately not so deep into the matter to give a qualified answer 😐

Cheers from Switzerland!