Skip to content

Commit e994845

Browse files
committed
gtag
1 parent cf8a975 commit e994845

File tree

4 files changed

+75
-38
lines changed

4 files changed

+75
-38
lines changed

docs/dist/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/gtag.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function init(id) {
2+
const script = document.createElement('script');
3+
script.async = true;
4+
script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id;
5+
document.body.appendChild(script);
6+
7+
window.dataLayer = window.dataLayer || [];
8+
window.gtag = window.gtag || function gtag(){dataLayer.push(arguments);}
9+
10+
window.gtag('js', new Date());
11+
window.gtag('config', id);
12+
}
13+
14+
function collect() {
15+
if (window.dataLayer === undefined) {
16+
init($docsify.ga)
17+
}
18+
19+
// usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages
20+
window.gtag('event', 'page_view', {
21+
page_title: document.title,
22+
page_location: location.href,
23+
page_path: location.pathname,
24+
});
25+
}
26+
27+
const install = function(hook) {
28+
if (!$docsify.ga) {
29+
console.error('[Docsify] ga is required.');
30+
return;
31+
}
32+
33+
hook.beforeEach(collect);
34+
};
35+
36+
$docsify.plugins = [].concat(install, $docsify.plugins);

docs/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'docsify'
2-
import 'docsify/lib/plugins/ga'
2+
// import 'docsify/lib/plugins/ga'
33
import './cozy'
4+
import './gtag'
45
import 'docsify/lib/plugins/emoji'
56
import 'docsify/lib/plugins/search'
67
import 'prismjs/components/prism-php'

package-lock.json

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)