3

Is there really no way for data elements to return click URL? I know you can return event.element.href and setvar in RULES but I want this done through data elements for many reasons I don't have to elaborate on. Why is something as BASIC as click variables not part of the launch core extension for data elements?

Data element won't return click url. Below is one iteration I used but I've tried all kinds of ways to return click URL in a data element and none of them work. It prints to the console but the actual data element value remains undefined

jQuery(document).ready(function(){
   jQuery('a').click(function(){
     let clickHref = $(this).attr('href');
     console.log('Click URL =>', clickHref);
     return clickHref;
   });
})
xmunchaser
  • 33
  • 4

1 Answers1

1

In short, you can't because DEs don't have the context of the trigger or the event object. Another thing that doesn't have it is s code and doplugins.

Launch is gracious enough to always give you the context of what triggered the rule in other places, however. Every rule has access to this and event. event will contain this, but this is a useful shortcut and it will give you the clicked element right away when the trigger is click. this does depend on the trigger. You would typically use this exactly how you use the {{Click Element}} in GTM.

You can definitely still use this as a Data Element. It's useful when you want to put pieces of the clicked element in your UI rather than code. For this, you will have to set your DEs right here, in the same rule like so:

_satellite.setVar("tempVarAttrZ", this.getAttribute("z"));

After this, every action of this rule will have access to %tempVarAttrZ% from the UI. The getVar will work too:

enter image description here

Always have something marking temporary DEs to avoid using them unintendedly. Also keep in mind that if the DE is created through the Launch UI, so it pops up in the list of DEs, your setVar won't work, just pick an unused name for setting it like this.

Finally, you often need it to be set in the first action and adding an action just to set the temporary variable is a bit too much. That's fine. I occasionally would do it through the JS conditions of the rule. It's comfy since conditions always execute before actions. And they don't allow asyncness.

Sorry for the late reply. It's a good question, I just didn't see it here before.

BNazaruk
  • 6,300
  • 3
  • 19
  • 33
  • I have a lot of different pixels to fire based on the Click URL. My plan was to use a mapping table like https://exchange.adobe.com/apps/ec/103136 and use a Click URL data element as the source data. Based on the URL clicked, it would then output a specific URL. This approach would have been more manageable. – xmunchaser Mar 16 '23 at 21:52
  • I did try `_satellite.setVar('Click URL', event.element.href);` in the action custom code of a rule. Rule order set very low so it is prioritized. The trigger event is a core click `a` selector. Using this %Click URL% in the mapping table is very inconsistent. Worse if you have to output pixels for different channels like Meta, Google, etc based on the same Click URL. A scenario like this calls for having different mapping tables for each channel. – xmunchaser Mar 16 '23 at 22:04
  • By the way by output pixel, I mean I would be using the mapping table data element in another rule to dynamically insert the right pixel. `%this.href%` works great in a lot of scenarios like setting vars data for Adobe Analytics but you can't use it in another way as described above. Doesn't work as the data element source in mapping tables. An out of the box Click URL data element would be really nice. – xmunchaser Mar 16 '23 at 22:17
  • Maybe I'm just confused and need a different approach. I'll play around some more and report back. Thanks – xmunchaser Mar 16 '23 at 22:18