File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ // @ts -check
2
+ // Adapted from https://github.com/TypeStrong/typedoc/issues/2600#issuecomment-2184995074
3
+
4
+ import td from 'typedoc' ;
5
+
6
+ /** @param {td.Application } app */
7
+ export function load ( app ) {
8
+ app . options . addDeclaration ( {
9
+ name : 'gaID' ,
10
+ help : 'Set the Google Analytics tracking ID and activate tracking code' ,
11
+ type : td . ParameterType . String ,
12
+ } ) ;
13
+
14
+ app . renderer . hooks . on ( 'body.end' , ( ) => {
15
+ const gaID = app . options . getValue ( 'gaID' ) ;
16
+ if ( gaID ) {
17
+ const script = `
18
+ window.dataLayer = window.dataLayer || [];
19
+ function gtag(){dataLayer.push(arguments);}
20
+ gtag('js', new Date());
21
+ gtag('config', '${ gaID } ');
22
+ ` . trim ( ) ;
23
+
24
+ return td . JSX . createElement ( td . JSX . Fragment , null , [
25
+ td . JSX . createElement ( 'script' , {
26
+ async : true ,
27
+ src : 'https://www.googletagmanager.com/gtag/js?id=' + gaID ,
28
+ } ) ,
29
+ td . JSX . createElement (
30
+ 'script' ,
31
+ null ,
32
+ td . JSX . createElement ( td . JSX . Raw , { html : script } )
33
+ ) ,
34
+ ] ) ;
35
+ }
36
+
37
+ return td . JSX . createElement ( td . JSX . Fragment , null ) ;
38
+ } ) ;
39
+ }
Original file line number Diff line number Diff line change 8
8
"GitHub" : " https://github.com/jakeboone02/parse-ingredient/" ,
9
9
"Support" : " https://github.com/sponsors/jakeboone02"
10
10
},
11
+ "plugin" : [" ./typedoc-plugin-ga.mjs" ],
11
12
"gaID" : " G-TMFVDH6J7S"
12
13
}
You can’t perform that action at this time.
0 commit comments