Race condition in data elements | Community
Skip to main content
Level 4
May 25, 2021
Solved

Race condition in data elements

  • May 25, 2021
  • 1 reply
  • 2040 views

Hi everyone!

Sometimes we have a situation where we reference the value of a different data element in a separate data element i.e. we define a variable in custom code using _satellite.getVar().

I was wondering if this introduces a race condition meaning that you end up with a data element that doesn't return a value at the point when it's requested even though there may be one as the functions that set the values of the data elements don't run in a specific order.

Use case is when we create fallbacks to account for any issues with data layer properties.

For example, we pass an order ID to the data layer on sale, but this value is also presented in an element in the DOM. So we have two data elements:

  1. For the text value of the order reference element (DOM attribute)
  2. For the value in the data layer OR DOM with precedence given to returning the value from the data layer (custom code)
var orderReferenceElement = _satellite.getVar("orderReferenceElement") // Data element with value from DOM if(digitalData && digitalData.order && digitalData.order.id){ // Checking if data layer property is available var dataLayerOrderReference = digitalData.order.id; } return (typeof dataLayerOrderReference !== "undefined") ? dataLayerOrderReference : orderReferenceElement

There shouldn't ever be a situation where the value is unspecified in Analytics as the page load rule fires on window loaded, meaning that if the data layer isn't ready, there's definitely the element in the DOM at that point.

Any help would be greatly appreciated.

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 yuhuisg

I do this fairly frequently, and so far, I've never encountered race conditions. So it looks like when Launch finds a reference to a data element in any component (whether in another data element or in an event or condition or action), it evaluates the data element and returns the value to the component that uses it.

1 reply

yuhuisg
Community Advisor
yuhuisgCommunity AdvisorAccepted solution
Community Advisor
May 26, 2021

I do this fairly frequently, and so far, I've never encountered race conditions. So it looks like when Launch finds a reference to a data element in any component (whether in another data element or in an event or condition or action), it evaluates the data element and returns the value to the component that uses it.

Level 4
May 26, 2021
Cool. It's always good to hear that the method I'm using isn't fundamentally incorrect. I've followed up with our developers and it turns out they've introduced a new page variant and changed the ID of the element where we're scraping the value for the data element from, whilst also not passing a value to the data layer.