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

Race condition in data elements

Avatar

Avatar
Validate 10
Level 3
philipk92120636
Level 3

Likes

14 likes

Total Posts

88 posts

Correct Reply

8 solutions
Top badges earned
Validate 10
Validate 1
Contributor
Give Back 3
Give Back
View profile

Avatar
Validate 10
Level 3
philipk92120636
Level 3

Likes

14 likes

Total Posts

88 posts

Correct Reply

8 solutions
Top badges earned
Validate 10
Validate 1
Contributor
Give Back 3
Give Back
View profile
philipk92120636
Level 3

25-05-2021

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.

custom code data element launch

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Publish 1
MVP
yuhuisg
MVP

Likes

180 likes

Total Posts

541 posts

Correct Reply

106 solutions
Top badges earned
Publish 1
Affirm 100
Springboard
Bedrock
Validate 1
View profile

Avatar
Publish 1
MVP
yuhuisg
MVP

Likes

180 likes

Total Posts

541 posts

Correct Reply

106 solutions
Top badges earned
Publish 1
Affirm 100
Springboard
Bedrock
Validate 1
View profile
yuhuisg
MVP

26-05-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.

Answers (0)