How to use a JS variable in another Custom JS script? | Community
Skip to main content
adilk
Level 4
April 7, 2019
Solved

How to use a JS variable in another Custom JS script?

  • April 7, 2019
  • 12 replies
  • 10646 views

In GTM, it's usually by replacing the var name with {{var name}}. How do I do in this Adobe launch?

I have a custom JS that's simply not reading directly from the console log. However, if I separately declare a Data Element that's a JS variable that reads from performance.timing.requestStart, I can see the value in Cloud Debugger.

How can I apply such variables here for startTime and endTime var in below code?

thanks.

function getPageLoadTime() {

if (typeof(performance) !== 'undefined' && typeof(performance.timing) == 'object') {

var timing = performance.timing;

// fall back to less accurate milestones

var startTime = performance.timing.requestStart;

var endTime = performance.timing.loadEventEnd;

if (startTime && endTime && (startTime < endTime)) {

return (endTime - startTime);

}

}

return 'data not available';

}

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

You do not run your code at the time. It needs to be run at the right time of the page lifecycle.

Ideally you would want to run performance code at unload time that way you know that your page is fully loaded (unless people nevigate before the page is fully loaded...).

We do it in this way:

  • Create an event listener on unload
  • On unload a function is called to get all performance data and store them in cookies. We also store the page name that will be the previous page name.
  • On next page send previous page name and performance data to Adobe Analytics
  • In Adobe Analytics run previous page report and add performance metrics

12 replies

adilk
adilkAuthor
Level 4
May 26, 2019

Hi Alexis,

If I had to configure the below in Adobe Launch, how would I go about with this?

  • Create an event listener on unload

In Rules section, I can't find an event for unload.

  • On unload a function is called to get all performance data and store them in cookies. We also store the page name that will be the previous page name.

How can this be done via Adobe Launch?

  • On next page send previous page name and performance data to Adobe Analytics

Should all of the above steps happen in the same Rule? Wait for unload, save to cookies and then set variables > Send beacon ?

Thanks

jantzen_b
Adobe Employee
Adobe Employee
March 24, 2020
Do any of the answers below answer your initial question? If so, can you select one of them as the correct answer? If none of the answers already provided answer your question, can you provide additional information to better help the community solve your question?