Two separate script tags for Google Analytics?

前端 未结 5 970
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 13:04

Does anyone know why Google Analytics requires two separate script tags?

Specifically, their instructions advise users to embed the following snippet of code into a web

5条回答
  •  猫巷女王i
    2021-02-05 13:12

    document.write occurs as soon as it is executed in code. So if we used your "one script block" example, the actual generated source code would end up looking like this:

    
    
    
    

    Hence the var pageTracker = _gat._getTracker("UA-8720817-1"); pageTracker._trackPageview(); code would fail because _gat wouldn't be defined until the ga.js file is loaded.

    Does that make sense?

提交回复
热议问题