|
1 |
| -/* eslint-disable no-console */ |
2 |
| -// From https://github.com/egoist/vue-ga/blob/master/src/index.js |
3 |
| -function appendScript() { |
4 |
| - const script = document.createElement('script'); |
5 |
| - script.async = true; |
6 |
| - script.src = 'https://www.google-analytics.com/analytics.js'; |
7 |
| - document.body.appendChild(script); |
8 |
| -} |
9 |
| - |
10 |
| -function init(id) { |
11 |
| - appendScript(); |
12 |
| - window.ga = |
13 |
| - window.ga || |
14 |
| - function () { |
15 |
| - (window.ga.q = window.ga.q || []).push(arguments); |
16 |
| - }; |
| 1 | +(function () { |
| 2 | + // From https://github.com/egoist/vue-ga/blob/master/src/index.js |
| 3 | + function appendScript() { |
| 4 | + const script = document.createElement('script'); |
| 5 | + script.async = true; |
| 6 | + script.src = 'https://www.google-analytics.com/analytics.js'; |
| 7 | + document.body.appendChild(script); |
| 8 | + } |
17 | 9 |
|
18 |
| - window.ga.l = Number(new Date()); |
19 |
| - window.ga('create', id, 'auto'); |
20 |
| -} |
| 10 | + function init(id) { |
| 11 | + appendScript(); |
| 12 | + window.ga = |
| 13 | + window.ga || |
| 14 | + function () { |
| 15 | + (window.ga.q = window.ga.q || []).push(arguments); |
| 16 | + }; |
21 | 17 |
|
22 |
| -function collect() { |
23 |
| - if (!window.ga) { |
24 |
| - init($docsify.ga); |
| 18 | + window.ga.l = Number(new Date()); |
| 19 | + window.ga('create', id, 'auto'); |
25 | 20 | }
|
26 | 21 |
|
27 |
| - window.ga('set', 'page', location.hash); |
28 |
| - window.ga('send', 'pageview'); |
29 |
| -} |
| 22 | + function collect() { |
| 23 | + if (!window.ga) { |
| 24 | + init($docsify.ga); |
| 25 | + } |
30 | 26 |
|
31 |
| -const install = function (hook) { |
32 |
| - if (!$docsify.ga) { |
33 |
| - console.error('[Docsify] ga is required.'); |
34 |
| - return; |
| 27 | + window.ga('set', 'page', location.hash); |
| 28 | + window.ga('send', 'pageview'); |
35 | 29 | }
|
36 | 30 |
|
37 |
| - hook.beforeEach(collect); |
38 |
| -}; |
| 31 | + const gaPlugin = function (hook, vm) { |
| 32 | + if (!$docsify.ga) { |
| 33 | + /* eslint-disable-next-line no-console */ |
| 34 | + console.error('[Docsify] ga is required.'); |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + hook.beforeEach(collect); |
| 39 | + }; |
39 | 40 |
|
40 |
| -$docsify.plugins = [].concat(install, $docsify.plugins); |
| 41 | + // Add plugin to docsify's plugin array |
| 42 | + $docsify = $docsify || {}; |
| 43 | + $docsify.plugins = [].concat($docsify.plugins || [], gaPlugin); |
| 44 | +})(); |
0 commit comments