Expand my Community achievements bar.

SOLVED

Custom code in "Set Variable" section executing asynchronously

Avatar

Level 3

Hi All,

We have recently migrated our property from Adobe DTM to Launch. I have a direct call rule, in which evars and props are set using mapping at UI level in Launch, however events and products are set in the custom code of same section "Set Variables" under Action in launch.

Now , the call to DCR has been written like this in code controller :

try {

      window._satellite.track('commonsPageLoad');

    } catch (error) {

      console.error(error);

    } finally {

      window.digitalData = {};

    }

Here, before DCR fully gets executet ,i.e., before image request getting fired , datalayer gets emptied from finally block. It results in loss of data , when image request is fired

Is it due to custom code executing asynchronously ? Can anyone please help on this, what needs to be done.

1 Accepted Solution

Avatar

Correct answer by
Level 4

The direct call is made in a synchronous manner - but you can think of all the subsequent activity of the rule running afterwards. The execution of another Rule Trigger is completely external to the initial direct call line, so there's no control on timing there.

If you need to control the timing, you do have a few options...

Option 1 (do it yourself): create your own callback, promise, or other control alongside your DCR to ensure it does no continue until the timing you desire.

Option 2 (let Launch do it): If you perform this same type of call in a series of conditions of a rule, Launch will control the execution of the other Trigger (the DCR Rule) to be completed before continuing onward within the current Trigger.

View solution in original post

4 Replies

Avatar

Level 5

Hi,

from my understanding of how the direct call rule is replaced with an event capture rule in Launch, I suppose it is indeed running asynchronous.

So I suggest you move the clearing of your digitalData to an action event (custom script), after the action(s), where you process the rule.

Due to the action sequencing, in the order you set in the actions, you'll be sure that the data is cleared "after" processing.

Stefan

Avatar

Level 9

You could also provide the required data as a payload with the tracking call, to be sure to have its data available.

If you empty digitalData anyway at the end, why do you even have it?

Avatar

Correct answer by
Level 4

The direct call is made in a synchronous manner - but you can think of all the subsequent activity of the rule running afterwards. The execution of another Rule Trigger is completely external to the initial direct call line, so there's no control on timing there.

If you need to control the timing, you do have a few options...

Option 1 (do it yourself): create your own callback, promise, or other control alongside your DCR to ensure it does no continue until the timing you desire.

Option 2 (let Launch do it): If you perform this same type of call in a series of conditions of a rule, Launch will control the execution of the other Trigger (the DCR Rule) to be completed before continuing onward within the current Trigger.

Avatar

Level 10
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?