External Js

hi, I wanted to know if it is possible to insert the tracking script in a js file, and then add it as a link on every page.

for example

if I insert the javascript code in this file, but it seems to not work properly. What is wrong?