Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Deprecate Google Analytics Integration #2600

Closed
Gerrit0 opened this issue Jun 21, 2024 · 9 comments
Closed

Deprecate Google Analytics Integration #2600

Gerrit0 opened this issue Jun 21, 2024 · 9 comments
Milestone

Comments

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jun 21, 2024

Search Terms

gaId, privacy, gdpr, cookies

Problem

TypeDoc supports specifying a gaId option. When set, this causes TypeDoc to include Google Analytics tracking code in the generated pages. This causes a problem for anyone attempting to comply with the EU Cookie Law as TypeDoc does not generate a cookie banner.

Suggested Solution

Push the gaId option to an external plugin. I could generate a cookie banner within TypeDoc, but other plugins (like typedoc-clarity-plugin) also ought to cause this to be generated, so TypeDoc's check would have to be externally controlled.

@Gerrit0 Gerrit0 added the enhancement Improved functionality label Jun 21, 2024
@Gerrit0 Gerrit0 added this to the v0.26.0 milestone Jun 21, 2024
@euberdeveloper
Copy link

Are you aware of any google analytics plugin? I would like to migrate

@Gerrit0
Copy link
Collaborator Author

Gerrit0 commented Jun 23, 2024

One can be easily constructed from the code in 1b55285

$ typedoc --plugin ./analytics.mjs
// @ts-check
// Apache License 2.0 - https://github.com/TypeStrong/typedoc/blob/master/LICENSE
import td from "typedoc";

/** @param {td.Application} app */
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}');
`.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);
    });
}

@euberdeveloper
Copy link

I think in the official docs website, gaId is still specified as a possible option

@Gerrit0
Copy link
Collaborator Author

Gerrit0 commented Jun 23, 2024

Fixed with TypeStrong/typedoc-site@c43e28b, thanks

@euberdeveloper
Copy link

One can be easily constructed from the code in 1b55285

$ typedoc --plugin ./analytics.mjs
// @ts-check
// Apache License 2.0 - https://github.com/TypeStrong/typedoc/blob/master/LICENSE
import td from "typedoc";

/** @param {td.Application} app */
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}');
`.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);
    });
}

Hello, this plugin has been done today, it can be found here: https://www.npmjs.com/package/typedoc-plugin-ga

Feedback would be nice, also, can it be added to typedoc's documentation, in the plugins' list?

@Gerrit0
Copy link
Collaborator Author

Gerrit0 commented Aug 15, 2024

It will automatically be picked up when the site rebuilds tonight

@euberdeveloper
Copy link

It didn't appear

@Gerrit0
Copy link
Collaborator Author

Gerrit0 commented Aug 21, 2024

Ah, that's because you don't have a peerDependency declared. Setting it to 0.26.x will make it show up.

@euberdeveloper
Copy link

Oh ok, I had it as dev, thanks

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants