Rule not firing onchange event | Community
Skip to main content
jezwn
Level 5
October 4, 2020
Solved

Rule not firing onchange event

  • October 4, 2020
  • 2 replies
  • 3074 views

I've added the event Core - Data Element Change and in custom code consoling it out. The data element name is 'form Abandonment' and js object is digitalData.form.formAbandonment
if(digitalData.form.formAbandonment != ""){
console.log("Refresh case:"+_satellite.getVar("form Abandonment"));
return true;
} else {
console.log("Not updated");

return false;
}

I tried consoling out the same value in datalayer and I'm getting the right values for both js and satellite object. The formAbandonment is set on unload event.
$(window).on( "unload", function() {
formArray['formAbandonment'] = fieldName;
});
)};

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

What is most likely happening is that there's a "race condition" between when your digitalData.form.formAbandonment gets set vs when the browser has already unloaded and is navigating to the next page. You can verify if this is the case with the Adobe Experience Platform Debugger's Events panel.

With window's unload function, one "trick" I've used that works pretty consistently is to perform the Rule's action within a condition. Basically, run the action's custom code in a condition, and make sure the last line is "return true;".

2 replies

yuhuisg
Community Advisor
yuhuisgCommunity AdvisorAccepted solution
Community Advisor
October 4, 2020

What is most likely happening is that there's a "race condition" between when your digitalData.form.formAbandonment gets set vs when the browser has already unloaded and is navigating to the next page. You can verify if this is the case with the Adobe Experience Platform Debugger's Events panel.

With window's unload function, one "trick" I've used that works pretty consistently is to perform the Rule's action within a condition. Basically, run the action's custom code in a condition, and make sure the last line is "return true;".

yuhuisg
Community Advisor
Community Advisor
October 5, 2020

@jezwna Data Element Change event might not be the best for you.

Try using a Custom Code event. In there, you can use:

window.addEventListener('beforeunload', function (event) { trigger(); // REQUIRED });

Then, you can read from your data element in a condition or action.

jantzen_b
Adobe Employee
Adobe Employee
December 3, 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?