Skip to content

Commit

Permalink
chore(docs): added GA to js api ref (#1939)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj authored Feb 11, 2025
1 parent 7d65e0a commit 29c4b14
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
61 changes: 61 additions & 0 deletions js/typedoc-ga.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as td from 'typedoc';

export function load(app) {
app.options.addDeclaration({
name: 'gaID',
help: 'Set the Google Analytics tracking ID and activate tracking code',
type: td.ParameterType.String,
});

app.renderer.hooks.on('body.end', () => {
const gaID = app.options.getValue('gaID');
if (gaID) {
const script = `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gaID}');
const gaAck = localStorage.getItem("gaAck");
if (gaAck !== 'true') {
var bannerRoot = document.createElement( 'div' );
bannerRoot.setAttribute('id', 'gaBanner');
bannerRoot.setAttribute('style', 'border: 1px solid #CCC; padding: 15px 10px; background: white; color: black; text-align: center; position: fixed; bottom: 0px; width: 100%;');
bannerRoot.innerHTML = 'genkit.dev uses <a href="https://policies.google.com/technologies/cookies">cookies</a> from Google to deliver and enhance the quality of its services and to analyze traffic &nbsp;&nbsp;<button onclick="document.genkitAckGaBanner()">I Understand</button>';
document.body.appendChild(bannerRoot);
document.genkitAckGaBanner = function() {
localStorage.setItem("gaAck", 'true');
document.getElementById('gaBanner').remove();
}
}
`.trim();
return td.JSX.createElement(td.JSX.Fragment, null, [
td.JSX.createElement('script', {
async: true,
src: 'https://www.googletagmanager.com/gtag/js?id=' + gaID,
}),
td.JSX.createElement(
'script',
null,
td.JSX.createElement(td.JSX.Raw, { html: script })
),
]);
}
return td.JSX.createElement(td.JSX.Fragment, null);
});
}
5 changes: 3 additions & 2 deletions js/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
"sort": ["kind", "instance-first", "alphabetical"],
"sortEntryPoints": true,
"readme": "index.typedoc.md",
"plugin": ["typedoc-plugin-zod", "typedoc-github-theme"],
"plugin": ["typedoc-plugin-zod", "typedoc-github-theme", "./typedoc-ga.mjs"],
"navigation": {
"includeCategories": false,
"includeGroups": false,
"includeFolders": false,
"compactFolders": false,
"excludeReferences": true
},
"categorizeByGroup": false
"categorizeByGroup": false,
"gaID": "G-Y4X57D8XYG"
}

0 comments on commit 29c4b14

Please sign in to comment.