- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
01-04-2019 08:50 AM
Hi,
I am trying to track the links as shown in the screenshot (pink) and to give it the eventlabel of the corresponding Header Title (orange). How do I go about that? Thanks for any help!
I have the following extensions ready:
DOM Ready JS Code:
// jQuery listener for all 'a' Tags at the Page jQuery(document).on('click', 'a', function(e) { // Variable Declaration var tgt = jQuery(e.target); var clickURL = tgt.attr('href'); var clickText = tgt.text().replace(/[^a-zA-Z0-9]+/g, "-"); var clickClass = tgt.attr('class'); var clickID = tgt.attr('id'); var clickURLHostname = this.hostname; var clickURLPath = this.pathname; var clickElement = jQuery(e.target)[0]; var clickType; // Check if the clicked Link is internal or External. // Please edit 'PLACEHOLDER' if (clickURLHostname.indexOf("zweipunkt.com") === -1) { clickType = "external"; }else { clickType = "internal"; } // sent Tealium Event with all click Elements utag.link({ 'tealium_event' : 'link_click', 'click_url' : clickURL, 'click_text' : clickText, 'click_class' : clickClass, 'click_id' : clickID, 'click_urlHostname' : clickURLHostname, 'click_urlPath' : clickURLPath, 'click_type' : clickType, 'click_element': clickElement }); });
Thanks for any help!
01-07-2019 10:16 AM - edited 01-07-2019 11:58 AM
Hi @chriszp,
In your link you have href links. Last portion of href link is titile. So, you can use the split function to get the last portion of the URL and pass it to the label.
Here is the sample code you need to add.
var clickTitle = tgt[0].href.split("/")[tgt[0].href.split("/").length-1];
02-12-2019 07:43 PM - edited 02-12-2019 07:43 PM
Hi @chriszp
You could take advantage of other jQuery functions to retrieve that dom element.
For example, you could get its value using the closest method
closest(): For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
If the header was in an h2 element, you could use:
var title = tgt.closest("h2").text();
Hope that helps!
Copyright All Rights Reserved © 2008-2023