File tree 3 files changed +68
-1
lines changed
3 files changed +68
-1
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ async function buildAllPlugin() {
80
80
var plugins = [
81
81
{ name : 'search' , input : 'search/index.js' } ,
82
82
{ name : 'ga' , input : 'ga.js' } ,
83
+ { name : 'ga4' , input : 'ga4.js' } ,
83
84
{ name : 'matomo' , input : 'matomo.js' } ,
84
85
{ name : 'emoji' , input : 'emoji.js' } ,
85
86
{ name : 'external-script' , input : 'external-script.js' } ,
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ This plugin ignores diacritical marks when performing a full text search (e.g.,
69
69
<script src =" //polyfill.io/v3/polyfill.min.js?features=String.prototype.normalize" ></script >
70
70
```
71
71
72
- ## Google Analytics
72
+ ## Google Universal Analytics (GA3)
73
73
74
74
Install the plugin and configure the track id.
75
75
@@ -91,6 +91,28 @@ Configure by `data-ga`.
91
91
<script src =" //cdn.jsdelivr.net/npm/docsify/lib/plugins/ga.min.js" ></script >
92
92
```
93
93
94
+ ## Google Analytics 4 (GA4)
95
+
96
+ Install the plugin and configure the gtag id.
97
+
98
+ ``` html
99
+ <script >
100
+ window .$docsify = {
101
+ gtag: ' G-XXXXXXXXX' ,
102
+ };
103
+ </script >
104
+ <script src =" //cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js" ></script >
105
+ <script src =" //cdn.jsdelivr.net/npm/docsify/lib/plugins/ga4.min.js" ></script >
106
+ ```
107
+
108
+ Configure by ` data-gtag ` .
109
+
110
+ <!-- prettier-ignore -->
111
+ ``` html
112
+ <script src =" //cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js" data-gtag =" G-XXXXXXXXX" ></script >
113
+ <script src =" //cdn.jsdelivr.net/npm/docsify/lib/plugins/ga.min.js" ></script >
114
+ ```
115
+
94
116
## Emoji
95
117
96
118
Renders a larger collection of emoji shorthand codes. Without this plugin, Docsify is able to render only a limited number of emoji shorthand codes.
Original file line number Diff line number Diff line change
1
+ /* eslint-disable no-console */
2
+ // Inspired by https://github.com/egoist/vue-ga/blob/master/src/index.js
3
+ function appendScript ( id ) {
4
+ const script = document . createElement ( 'script' ) ;
5
+ script . async = true ;
6
+ script . src = 'https://www.googletagmanager.com/gtag/js?id=' + id ;
7
+ document . body . appendChild ( script ) ;
8
+ }
9
+
10
+ function init ( id ) {
11
+ appendScript ( id ) ;
12
+
13
+ window . dataLayer = window . dataLayer || [ ] ;
14
+
15
+ gtag = function ( ) { dataLayer . push ( arguments ) } ;
16
+ gtag ( 'js' , new Date ( ) ) ;
17
+
18
+ gtag ( 'config' , id , {
19
+ send_page_view : false , // Disable automatic pageview
20
+ debug_mode : ( location . hostname === 'localhost' ) ? true : false
21
+ } ) ;
22
+ }
23
+
24
+ function collect ( ) {
25
+ if ( typeof gtag === 'undefined' ) {
26
+ init ( $docsify . gtag ) ;
27
+ }
28
+
29
+ gtag ( 'event' , 'page_view' , {
30
+ page_title : location . hash ,
31
+ page_location : location . href
32
+ } ) ;
33
+ }
34
+
35
+ const install = function ( hook ) {
36
+ if ( ! $docsify . gtag ) {
37
+ console . error ( '[Docsify] gtag is required.' ) ;
38
+ return ;
39
+ }
40
+
41
+ hook . beforeEach ( collect ) ;
42
+ } ;
43
+
44
+ $docsify . plugins = [ ] . concat ( install , $docsify . plugins ) ;
You can’t perform that action at this time.
0 commit comments