From 97db30a0b98a0156f684aafef8556a98698bd02a Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sun, 11 Jun 2017 18:57:21 +0800 Subject: [PATCH] fix ga --- src/plugins/ga.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/plugins/ga.js b/src/plugins/ga.js index 4a80a392..b016f28b 100644 --- a/src/plugins/ga.js +++ b/src/plugins/ga.js @@ -7,24 +7,21 @@ function appendScript () { } function init (id) { - let ga = window.ga - - if (!ga) { - appendScript() - ga = ga || function () { - (ga.q = ga.q || []).push(arguments) - } - ga.l = Number(new Date()) - ga('create', id, 'auto') + appendScript() + window.ga = window.ga || function () { + (window.ga.q = window.ga.q || []).push(arguments) } - return ga + window.ga.l = Number(new Date()) + window.ga('create', id, 'auto') } function collect () { - const ga = init($docsify.ga) + if (!window.ga) { + init($docsify.ga) + } - ga('set', 'page', location.hash) - ga('send', 'pageview') + window.ga('set', 'page', location.hash) + window.ga('send', 'pageview') } const install = function (hook) {