I would like to use the custom code of Data Elements in Adobe Launch to get a text value for the parent element of the clicked element.

I used $(this).parents('h3').text() method, but when I checked with debug tool, the text value is not collected properly. Custom Code of Data Elements in Adobe Launch

However, when I check with the console within the page, I can see that the text value exists through that method.

Does Adobe Launch not support that method? So how do I get a property value for the parent or child element of a clicked element?

2

There are 2 best solutions below

0
On

You can use javascript for this in Launch's custom code where your Rule is an EBR(Event-Based Rule) as below

this.parentNode.innerText

Or

event.element.parentNode.innerText
0
On

Neither the event nor the element object is internally passed to Data Elements (DE). If you want to be able to reference this stuff in a DE, then you can have the DE return a function, so you can call it like a function and pass it as an argument.

Example:

Data Element Name: getClickedElementText

Custom Code:

return function(ev) {
   var ev = ev || {};
   var elem = ev.target || {}:
   return $(elem).parents('h3').text();
}

Then in your Rule, in a custom code box (e.g. in a condition, or in an action custom code box, not flagged for global scope), you can do this:

var text = _satellite.getVar('getClickedElementText')(event);

Note that since this DE is returning a function, you cannot reference it in a built-in text field in your rule.

If you want to be able to use %dataelement% in UI text fields, then you have to instead put the code in a code box within the rule box (again, not globally scoped) to set an adhoc DE. For example, in a rule condition custom code box:

var elem = event.target;
var text = $(elem).parents('h3').text();
_satellite.setVar('clickedElementText',text);

And then you can use the %clickedElementText% syntax in the UI text fields. Note though that since you are creating an adhoc DE on-the-fly like this, it won't show up in the dropdown search hint.