Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 795 Bytes

when-google-analytics-is-loaded.md

File metadata and controls

32 lines (23 loc) · 795 Bytes

Analytics ready!

In the option object of the plugin there's a callback function available that fires when analytics.js or analytics_debug.js is loaded

always remember that the debug version is more heavy than the production one and might take more to load

import VueAnalytics from 'vue-analytics'

Vue.use(VueAnalytics, {
  beforeFirstHit () {
    // this is right after the tracker and before every other hit to Google Analytics
  },
  ready () {
    // here Google Analytics is ready to track!
  }
})

It is also possible to use the onScriptLoaded method, which returns a promise.

import VueAnalytics, { onAnalyticsReady } from 'vue-analytics'

Vue.use(VueAnalytics, { ... })

const App = new Vue({ ... })

onAnalyticsReady().then(() => {
  App.$mount('#app')
})