old_contents: export default ({ app: { router } }) => {
    function create() {
      try {
        window['yaCounter<%= options.id %>'] = new Ya.Metrika(<%= JSON.stringify(options) %>)
        app.router.afterEach(to => {
          // We tell Yandex Metrika to add a page view
          window['yaCounter<%= options.id %>'].hit(to.fullPath)
        })
      } catch (e) {
        //
      }
    }
  
    if (window.Ya && window.Ya.Metrika) {
      create()
    } else {
      (function (w, c) {
        (w[c] = w[c] || []).push(create)
      })(window, 'yandex_metrika_callbacks')
    }
  }
  
new_contents: export default ({ app: { router } }) => {
    let ready = false
  
    router.onReady(() => {
      // Mark when the router has completed the initial navigation.
      ready = true
    })
  
    function create() {
      window['yaCounter<%= options.id %>'] = new Ya.Metrika(<%= JSON.stringify(options) %>)
      router.afterEach((to, from) => {
        if (!ready) {
          // Don't record a duplicate hit for the initial navigation.
          return
        }
        window['yaCounter<%= options.id %>'].hit(to.fullPath, {
          referer: from.fullPath
          // TODO: pass title: <new page title>
          // This will need special handling because router.afterEach is called *before* DOM is updated.
        })
      })
    }
  
    if (window.Ya && window.Ya.Metrika) {
      // Yandex.Metrika API is already available.
      create()
    } else {
      // Yandex.Metrika has not loaded yet, register a callback.
      (function (w, c) {
        (w[c] = w[c] || []).push(create)
      })(window, 'yandex_metrika_callbacks')
    }
  }
  
subject: fix ReferenceError, fix duplicate initial hit (#147)