Uncaught ReferenceError: _gaq is not defined (Google Analytics)

后端 未结 5 1308
名媛妹妹
名媛妹妹 2021-02-03 20:22

The following message appears when viewing a site page in the chrome debug log.

Uncaught ReferenceError: _gaq is not defined

The pag

5条回答
  •  醉梦人生
    2021-02-03 21:07

    Regarding the position of the async snippet, the GA help page says -

    Paste this snippet into your website template page so that it appears before the closing tag.

    My first thought was that JS should be loaded at the bottom of the page to improve page speed. However, the GA async tracking snippet should be loaded in the head, as it will not load the ga.js immediately, and it won't block page execution.(It does this by dynamically adding the script tag to the DOM, which puts it at the back of the queue.)

    If, for some reason, you can't move the async snippet to the head, you can define _gaq yourself, like this-

提交回复
热议问题