Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Race condition in data elements

philipk92120636
Level 4
Level 4

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.

launch
1 Accepted Solution
yuhuisg
Correct answer by
Community Advisor
Community Advisor

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.

View solution in original post

2 Replies
yuhuisg
Correct answer by
Community Advisor
Community Advisor

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.

View solution in original post

philipk92120636
Level 4
Level 4
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.