- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
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?
$(this).find('div.PlayerThumbnail-module__link--3s667').find('a').attr('href');
Hi @ak87qa
How about using window.location.origin - that will give your url as well
Hi @ak87qa
If the click is being captured on an anchor tag, then $(this) should refer to that anchor tag, so all you should need is:
$(this).attr("href")
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:
$(this).find('div.PlayerThumbnail-module__link--3s667 a').attr('href');
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
$(this).data("tracking")
to pull back the reporting friendly data from the link.
Is there a Javascript variable I can create based on a click/destination URL, and only populate if a "link" tealium event is fired?
I'm not conversant in JavaScript, and was working out whether it could be the following:
b["$(this).attr("href");"]
or
b["document.location.href"]
I haven't been able to find any documentation...
Copyright All Rights Reserved © 2008-2023