Delay link activation should not interfere with anchor and javascript links

makbeta

28-06-2018

In DTM the delay link activation breaks the JS-based links and in some instances anchor links functionality.

The request is to either:

1. Have an option to disable the delay link activation on links that are pure anchors, contain the URL of the existing page + an anchor, or contain javascript commands.

2. Revise the functionality of delay activation so that the delay just delays the activation of the link, not stops it and then takes user to that URL.

Including a sample code that successfully can achive both of these requests:

/**  * The functions executes for x milliseconds.  * @param  {Integer} ms  Number of milliseconds the function should run.  * @return  */ export default function waitMilliseconds(ms) {   var start = new Date().getTime();   var end = start;   while(end < start + ms) {     end = new Date().getTime();   } } /**  * Delays the links from moving forward on click by 1 second  * to allow the data to go into analytics successfully without the delays.  */ export default function handleInternalLinkClicks() {   let $body = $('body');    $body.on('click', 'a', function (event) {     var $link = $(event.currentTarget);     var currentUrl = window.location.href.split('#')[0];     var linkDestination = $link.attr('href');      // Delay the click on the pages that redirect us so the analytics has time to capture the data,     // ignore current page anchors.     if (linkDestination.indexOf('#') !== 0 &&          linkDestination.replace(currentUrl, '').indexOf('#') !== 0 &&         linkDestination.indexOf('javascript:') !== '0') {       waitMilliseconds(1000);     }   }); }
1 Comment (1 New)
1 Comment

michael-au

17-06-2019

I always run into the issues with the delay link function, especially where JavaScript is used to deliver one URL on mobile devices and a pop-up on desktop. Usually with delay link active it will send the user to the mobile URL instead of the light-box popup on the desktop experience.