Not many people know you can pull information out about the element that an Event-Based Rule fires on, without any custom code. Let’s say I want to fire a rule on a link that looks like this, and I want to capture the domain of the link that was clicked in eVar3:
<div partner="adobe"> <a href="http://www.adobe.com" class="partnerExit" alt="go to our partner Adobe" target="_blank">This is an example link.</a> </div>
I would set my rule up to correctly fire on that link (with something like “a.partnerExit”), then for eVar3 I would put %this.hostname%, where “this” refers to “this thing that the rule fired on”.
I don’t have to have to do any custom code, or have a data element set up (in fact, data elements are NOT particularly useful at pulling out information specific to the element that fired an event-based rule.)
Putting this in the interface…
Would let me access…
Which would yield this…
|%this.hostname%||The domain of the link that was clicked||www.adobe.com|
|%this.href%||The full URL of the link that was clicked||http://www.adobe.com/|
|%this.src%||The source of the element that was clicked (works for images, not links)||(Not applicable here.)|
|%this.alt%||The “alt” value of the element that was clicked||go to our partner Adobe.|
|%this.@text%||The internal text of the element that was clicked||This is an example link.|
|%this.@cleanText%||The internal text of the element that was clicked, trimmed to remove extra white space||This is an example link.|
|%this.className%||The class of the element that was clicked (less handy in reports, but very handy for DTM troubleshooting)||partnerLink|
For more advanced “DOM-scraping” you may need to take to the custom code. I find jQuery often simplifies things greatly for this. For instance, in the above example, if I wanted to get the ID not of the anchor tag, but of the <div> that HOLDS the anchor tag, I could do this in the custom code:
Note that I remembered to also add it into s.linkTrackVars, since this is an s.tl beacon (DTM automatically creates s.linkTrackVars for any variables you configure directly in the interface, but can’t know which variables you are adding to the custom code section, so you must be sure to add them to linkTrackVars or linkTrackEvents yourself, or the s.tl() beacon will ignore those variables).