Is it possible to put Google Analytics code in an external JS file?

后端 未结 8 705
生来不讨喜
生来不讨喜 2021-02-05 02:56
var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");
document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-anal         


        
8条回答
  •  遇见更好的自我
    2021-02-05 03:22

    I came across this post while trying to resolve a similiar issue. After searching further I came across another post that worked for me:

    Using Google Analytics asynchronous code from external JS file

    I had to move the var _gaq outside of the function it was in so that it became global.

    Hope this helps!

提交回复
热议问题