Magento – Add inline JavaScript to the head of Magento 2.1

inline()javascriptmagento-2.1

I'm trying to add BugHerd (an issue tracking tool) to my Magento 2.1 project, which requires I add the following script into the <head> tag:

<script type='text/javascript'>
  (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={my api key}';
      s.parentNode.insertBefore(bh, s);
  })(document, 'script');
</script>

There are many questions on this topic referencing old Magento versions, but I can't seem to find an updated answer. Any ideas?

Thanks!

Best Answer

Hi you can also use the backend of magento 2 website.

Just add the bugherd JS code in Content>Design>Configuration>"Your Current Store" and just like the picture insert your JS code there and save.

I hope this helps.

enter image description here