Is there a way to capture URL from a click?
I'm trying to populate the URL into event_label using extensions. I have jQuery Selector and want to have js code as below for populating event label. Can this work?
If the click is being captured on an anchor tag, then $(this) should refer to that anchor tag, so all you should need is:
Your code is looking for the div within the clicked element, and then looking inside that for the anchor.
If this is right (ie the click is being captured on a div, or a list element, or something similar) then you shouldn't need to use .find twice. You can just nest the selectors:
It also looks like that div class includes an ID. Is that coming from your CMS, and is it likely to change? If so, it could break the link tracking.
Another option that we have used many times is to add data attributes to links, and then using them for tracking. So you'd have something like:
<a href="someurl.html" class="someclass" data-tracking="useful-tracking-string">link text</a>
then you can use
to pull back the reporting friendly data from the link.