File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Expand file tree Collapse file tree 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 77 "GitHub" : " https://github.com/jakeboone02/numeric-quantity/" ,
88 "Support" : " https://github.com/sponsors/jakeboone02"
99 },
10+ "plugin" : [" ./typedoc-plugin-ga.mjs" ],
1011 "gaID" : " G-X98SBNC2CJ"
1112}
You can’t perform that action at this time.
0 commit comments