-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathga.js
More file actions
44 lines (36 loc) · 1 KB
/
ga.js
File metadata and controls
44 lines (36 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// From https://github.com/egoist/vue-ga/blob/master/src/index.js
function appendScript() {
const script = document.createElement('script');
script.async = true;
script.src = 'https://www.google-analytics.com/analytics.js';
document.body.appendChild(script);
}
const window = /** @type {any} */ (globalThis);
function init(id) {
appendScript();
window.ga =
window.ga ||
function () {
(window.ga.q = window.ga.q || []).push(arguments);
};
window.ga.l = Number(new Date());
window.ga('create', id, 'auto');
}
function collect() {
if (!window.ga) {
init(window.$docsify.ga);
}
window.ga('set', 'page', location.hash);
window.ga('send', 'pageview');
}
const install = function (hook) {
if (!window.$docsify.ga) {
// eslint-disable-next-line no-console
console.error('[Docsify] ga is required.');
return;
}
hook.beforeEach(collect);
};
window.$docsify = window.$docsify || {};
window.$docsify.plugins = [install, ...(window.$docsify?.plugins || [])];
export {};