Using Google Analytics asynchronous code from external JS file

后端 未结 3 1665
孤独总比滥情好
孤独总比滥情好 2020-12-03 00:52

I\'m trying to add the asynchronous version of the Google Analytics tracking code to a website.

I\'d like to keep the JavaScript in a separate file, and call it from

3条回答
  •  感动是毒
    2020-12-03 01:47

    You completely miss the point of the asynchronous tracking code. Don't put it in an external file because that's exactly like including the old synchronous GA.

    And most importantly don't defer the tracking code to window.onload as it may fire too late.

    If you use the asynchronous GA just put it in the top of you document in an inline script tag. This is the recommendation on Google Analytics website as well.

    Insert the asynchronous snippet at the bottom of the section of your pages, after any other scripts your page or template might use.

提交回复
热议问题