Click Tracking using Javascript Code is not getting executed

Bronze Contributor
Bronze Contributor

I have created a Javascript code extension for capturing the some clicks on sharepoint portal using CSS selectors. The code get is working properly when executed on console but not working in extension. Below is the small code that is used in extension:

jQuery('#myHR-css p a').click(function(){
    s.linkTrackVars = 'eVar16';
    s.linkTrackEvents='event14';
    var active_sidebar = jQuery('.pages-menu__item.analyticsTrigger.active .pages-menu__link.analyticsTrigger.active span').text();
    var c = utag_data.subSection+":"+utag_data._site+":"+ active_sidebar ;
    var clicktext = ($(this).text());
    s.eVar16 = c+":"+clicktext;
    s.events = 'event14';
    s.tl(this,'o',null,'navigate');
    //console.log(s.eVar16)
});
3 REPLIES 3

Click Tracking using Javascript Code is not getting executed

Gold Contributor
Gold Contributor

Hi @Rohan ,

The code may not be working because, the CSS selector which you are using may not be available in the inital page load. so try to modify the code like

jQuery(document).on('click', 'css selector', function () {

.....
});

Also it  is not recommended to send the call explicitly to adobe by using s.tl().

You should pass these values in some UDO variables by utag.link() call and then use it in the tag by data-mapping.

You could use this link to learn more about data-mappings

https://community.tealiumiq.com/t5/iQ-Tag-Management/Data-Mappings/ta-p/10645

 

Thanks,

Its Not Who I am Underneath, but What I Do That Defines Me

Click Tracking using Javascript Code is not getting executed

Bronze Contributor
Bronze Contributor

@Rohan Hey Rohan

Try to use the code in Preloader Extension with IF condition on URL to restrict this code to a particular page. So it should not execute across the site.

Please place Preloader Extension on top of all the extensions since Tealium follows order of operations where Preloader loads first so it will detect all your site elements.

Click Tracking using Javascript Code is not getting executed

Bronze Contributor
Bronze Contributor

Hi,

don't know if that's the case but if these CTAs cause a change of context and load other pages, maybe with click event you have troubles with some browsers.

I advice to use .on method as others said but with the "mousedown" trigger: as it gets fired before you have more chances tracking get sent before the page change.

Regards

Public