From 9ae46afb1a0100f912ed179b966f95594bdd79f4 Mon Sep 17 00:00:00 2001 From: Matteo Gabriele Date: Thu, 5 Apr 2018 10:01:29 +0200 Subject: [PATCH] fix(trackers): lifecycle hook error window.ga was initialized after plugin api causing an error for a missing ga property closes #106 --- src/create-trackers.js | 7 ------- src/index.js | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/create-trackers.js b/src/create-trackers.js index 97d812c..e258c6a 100644 --- a/src/create-trackers.js +++ b/src/create-trackers.js @@ -6,13 +6,6 @@ import { getTracker } from './helpers' export default function createTrackers () { const ids = getId() - if (!window.ga) { - window.ga = window.ga || function () { - (ga.q = ga.q || []).push(arguments) - } - ga.l = Number(new Date()) - } - if (config.debug.enabled) { window.ga_debug = { trace: config.debug.trace diff --git a/src/index.js b/src/index.js index ef6fb73..7a37e7b 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,13 @@ import analyticsMiddleware from './vuex-middleware' export default function install (Vue, options = {}) { update(options) + if (!window.ga) { + window.ga = window.ga || function () { + (window.ga.q = window.ga.q || []).push(arguments) + } + window.ga.l = Number(new Date()) + } + Vue.directive('ga', ga) Vue.prototype.$ga = Vue.$ga = lib