Delay loading of BugHerd script on your site
- Last updated on November 13, 2019 at 1:09 AM
If you install BugHerd on your site, it is normally recommended that you install the script verbatim, ie:
(function (d, t) {
var bh = d.createElement(t), s = d.getElementsByTagName(t)[0];
bh.type = 'text/javascript';
bh.src = 'https://www.bugherd.com/sidebarv2.js?apikey=KEY';
s.parentNode.insertBefore(bh, s);
})(document, 'script');
However, in some circumstances that can depend on how the site is built, it is better to delay loading of the BugHerd scripts until the site itself is loaded. This might be the case with some JavaScript frameworks. It's certainly not always required, but if you wish, you can wrap the code in an unload function:
window.onload = function() {
(function (d, t) {
var bh = d.createElement(t), s = d.getElementsByTagName(t)[0];
bh.type = 'text/javascript';
bh.src = 'https://www.bugherd.com/sidebarv2.js?apikey=KEY';
s.parentNode.insertBefore(bh, s);
})(document, 'script');
}
Finally, if you have a need for even more delay and don't want BugHerd to appear after everything else is loaded and then some, then this script is for you. Please change the value of the timeout to suit:
window.onload = function() {
setTimeout(function() {
(function (d, t) {
var bh = d.createElement(t), s = d.getElementsByTagName(t)[0];
bh.type = 'text/javascript';
bh.src = 'https://www.bugherd.com/sidebarv2.js?apikey=KEY';
s.parentNode.insertBefore(bh, s);
})(document, 'script');
}, 5000);
}