Highlighted

global navigation

Rookie Contributor
How can I track clicks on global navigation (header , menu/sub-menus and footer) while avoiding coding for each link separately? I understand this can be done by utag.link() for each link whereas the link tracking extension is deprecated and should not be used. Is there a generic way to track all navigation links by default (by reading the label of the link or some other HTML attribute like id)?
6 REPLIES 6
Highlighted
Target the div and bind the link tracking function to each links using jQuery.
Highlighted

global navigation

Employee Emeritus
Mehdi's recommendation is good but requires you know how to write jQuery selectors. You can select all 'a' elements generically simply by using 'a' as your selector, but if your goal is to only select the navigational items you will have to get more detailed (but not as detailed as coding IDs for every item you want to track). Every site is different though and without direct examination of your page we wouldn't be able to recommend the exact selector for your use-case. I'd recommend contacting your account or deployment manager so we can look into this for you.
Highlighted
If you select all the 'a' elements then this can effect the performance of the page load. By using bit of javascript code you can help the performance of the page.
Highlighted
Silver Contributor
Silver Contributor
Agree with Mehdi. I'd suggest to review the navigation elements and get selectors where required, using which, build a jQuery function to track assets clicked. TIP: do not try to fire onClick, rather save it in a session cookie and read it on next pageLoad and fire it along with pageLoad tracking call. Benefits: no delay tracking no extra tracking calls. Cheers Samrat
Highlighted

global navigation

Silver Contributor
Silver Contributor
Samrat , could you please elaborate more ?
Highlighted
Silver Contributor
Silver Contributor
Hi Pallavi First create a function to save whatever values to pass in a cookie, onClick of global navigation. Second, create a function that runs on every pageLoad to check for this cookie and if it exists pass it to GA/Adobe and reset it. Thanks Sam