I made a toolbar for my e-commerce site where there is an option for the selected page after selecting a specific page, if I click the save button, I want to dynamically run these codes on the selected page, with which I can use the scriptAnalytics.js file only for pages that I want.
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src","scriptAnalytics.js")
document.getElementsByTagName("head")[0].appendChild(fileref)
source
share