I could use some assistance with passing an ID (or other attribute) value into a Data Element. Specifically, we’ve set up Recommendations using Target, and I’m trying to capture the BrandSKU for the recommendations that are engaging customers on click of the item (or rather the div that contains the item). I’m having some difficulty with setting up the data element capture.
The div that contains the item is coded as follows:
I'd like to set an event-based rule that fires on click of any of the links within the div and then capture the value of the SKU for the item contained in that div.
An example of the product recommendations on which I'm trying to capture clicks can be found on the right hand "Customers Also Viewed" section at the link below (note, the production code differs slightly from the code above):
Thanks for reaching out to Adobe DTM community. As per our understanding , we will need to create a data element on the fly and then use it in the interface for an event based rule Hence to achieve this, we can dynamically capture the value of the event, and can set it when defining the criteria for an event based rule, within the custom code block code.
Step 1: Create an Event based rule with conditions as below snapshot :
Step 2: After setting up the the condition please choose "custom" in rule conditions and then add the below code to that :
var sku_id = $(this).parentNode.attr("id"); // This line will fetch the sku id of the link clicked when an event click rule is fired on clicking of a link on the page. _satellite.setVar('Recommendation_SKU',sku_id); _satellite.getVar('Recommendation_SKU'); return true;
1. We are using jquery to fetch the sku id from DOM. If jquery library is not present on the page then please add the library in a script tag in the head of the page. 2. setVar saves the data element on a page level scope – this is okay since you’ll typically only be manually setting these variables when you are referencing elements with $(this).You can also use %% substitutions for these data elements within the UI
3. When you manually override a data element that exists and has a scope, it retains the scope of the element.
Please let us know in case of any questions or queries.