{"id":117,"date":"2016-01-18T02:32:43","date_gmt":"2016-01-18T02:32:43","guid":{"rendered":"http:\/\/www.digitaldatatactics.com\/?p=117"},"modified":"2016-01-18T16:49:03","modified_gmt":"2016-01-18T16:49:03","slug":"referencing-this-in-event-based-rules","status":"publish","type":"post","link":"https:\/\/www.digitaldatatactics.com\/index.php\/2016\/01\/18\/referencing-this-in-event-based-rules\/","title":{"rendered":"Referencing &#8220;this&#8221; in Event-Based Rules"},"content":{"rendered":"<p>Not many people know you can pull information out about the element that an Event-Based Rule fires on, without any custom code. Let&#8217;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:<\/p>\n<pre>&lt;div partner=\"adobe\"&gt;\r\n     &lt;a href=\"http:\/\/www.adobe.com\" class=\"partnerExit\" alt=\"go to our partner Adobe\" target=\"_blank\"&gt;This is an example link.&lt;\/a&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>I would set my rule up to correctly fire on that link (with something like &#8220;a.partnerExit&#8221;), then for eVar3 I would put %this.hostname%, where &#8220;this&#8221; refers to &#8220;this thing that the rule fired on&#8221;.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.digitaldatatactics.com\/examples\/images\/thisHostname.png\" alt=\"\" \/><\/p>\n<p>I don&#8217;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.)<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<h3>Putting this in the interface&#8230;<\/h3>\n<\/td>\n<td>\n<h3>Would let me access&#8230;<\/h3>\n<\/td>\n<td>\n<h3>Which would yield this&#8230;<\/h3>\n<\/td>\n<\/tr>\n<tr>\n<td>%this.hostname%<\/td>\n<td>The domain of the link that was clicked<\/td>\n<td>www.adobe.com<\/td>\n<\/tr>\n<tr>\n<td>%this.href%<\/td>\n<td>The full URL of the link that was clicked<\/td>\n<td>http:\/\/www.adobe.com\/<\/td>\n<\/tr>\n<tr>\n<td>%this.src%<\/td>\n<td>The source of the element that was clicked (works for images, not links)<\/td>\n<td>(Not applicable here.)<\/td>\n<\/tr>\n<tr>\n<td>%this.alt%<\/td>\n<td>The &#8220;alt&#8221; value of the element that was clicked<\/td>\n<td>go to our partner Adobe.<\/td>\n<\/tr>\n<tr>\n<td>%this.@text%<\/td>\n<td>The internal text of the element that was clicked<\/td>\n<td>This is an example link.<\/td>\n<\/tr>\n<tr>\n<td>%this.@cleanText%<\/td>\n<td>The internal text of the element that was clicked, trimmed to remove extra white space<\/td>\n<td>This is an example link.<\/td>\n<\/tr>\n<tr>\n<td>%this.className%<\/td>\n<td>The class of the element that was clicked (less handy in reports, but very handy for DTM troubleshooting)<\/td>\n<td>partnerLink<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>For more advanced &#8220;DOM-scraping&#8221; 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 &lt;div&gt; that HOLDS the anchor tag, I could do this in the custom code:<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.digitaldatatactics.com\/examples\/images\/customCodeLinkTrack.png\" alt=\"\" \/><\/p>\n<p>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&#8217;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).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not many people know you can pull information out about the element that an Event-Based Rule fires on, without any custom code. Let&#8217;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: &lt;div partner=&#8221;adobe&#8221;&gt; &lt;a &#8230; <a title=\"Referencing &#8220;this&#8221; in Event-Based Rules\" class=\"read-more\" href=\"https:\/\/www.digitaldatatactics.com\/index.php\/2016\/01\/18\/referencing-this-in-event-based-rules\/\" aria-label=\"Read more about Referencing &#8220;this&#8221; in Event-Based Rules\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,7,23],"tags":[19,8],"_links":{"self":[{"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/posts\/117"}],"collection":[{"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":2,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/posts\/117\/revisions\/119"}],"wp:attachment":[{"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}