DEV Community

Discussion on: Can you explain to me what's going on in this code?

Collapse
 
rpalo profile image
Ryan Palo

I tried to un-minimize it. Not all the way there, but at least now it's easier to see what the code is doing. 😁

const docElem = document.documentElement;
docElem.className += ' ' + 'async-hide';

const removeHideClass = function() {
  docElem.className = docElem.className.replace(/ ?async-hide/, '');
}

const hide = {
  'GTM-PNDQRRW': true,
  start: 1*new Date,  // new date (in seconds)
  end: removeHide
};

// window.dataLayer seems to be where Google Tag manager stores data to track

// Load or initialize it to an empty array
window['dataLayer']=window['dataLayer'] || [];
window['dataLayer'].hide = hide;

setTimeout(function() {
  removeHideClass();
  hide.end = null;
}, 4000);

hide.timeout = 4000;