Using Google Analytics asynchronous code from external JS file

后端 未结 3 1652
孤独总比滥情好
孤独总比滥情好 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:50

    Your variable definition var _gaq is inside a function. That means it's locally scoped inside that function and won't exist globally. Google Analytics depends on the global variable _gaq. If you want to keep it inside a function like that, reference it as window._gaq.

提交回复
热议问题