Check if analytics.js is loaded

后端 未结 3 355
梦如初夏
梦如初夏 2020-12-07 02:08

I have to use a local analytics.js that I serve from my server. I just want to use the local version if necessary - so is there a solution for checking if the call for analy

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 03:09

    instead of waiting for a callback, you can easily get it with

    if(window.ga && ga.loaded) {
        // yeps... it is loaded!
    }
    

    you can easily see this in the Firefox documentation

    same trick can be applied if you want to see if the tracker is blocked (by any plugin for example)

    if(window.ga && ga.q) {
        // yeps... blocked! >:o
    }
    

提交回复
热议问题