From 608c1e7ece7731bab3fd6dbffdfda481f68e03c1 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Mon, 14 Feb 2022 20:57:32 -0700 Subject: [PATCH] Remove gaSite option, update Google Analytics script Closes #1846 --- CHANGELOG.md | 1 + internal-docs/custom-themes.md | 4 ++-- src/lib/output/renderer.ts | 4 ---- .../themes/default/partials/analytics.tsx | 20 +++++++++---------- src/lib/utils/options/declaration.ts | 1 - src/lib/utils/options/sources/typedoc.ts | 5 ----- src/test/capture-screenshots.ts | 1 - 7 files changed, 13 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f44c0736e..43b405a7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Breaking Changes - TODO: The behavior of `@inheritDoc` has changed... describe how +- The `gaSite` option has been removed since Google Analytics now infers the site automatically. - `reflection.decorates`, `reflection.decorators`, and their corresponding interfaces have been removed as no code in TypeDoc used them. - The shape of the `Comment` class has changed significantly to support multiple tag kinds. - Listeners to `Converter.EVENT_CREATE_TYPE_PARAMETER` and `Converter.EVENT_CREATE_DECLARATION` will now never be passed a `ts.Node` as their third argument. diff --git a/internal-docs/custom-themes.md b/internal-docs/custom-themes.md index ab5bb545f..6ef538072 100644 --- a/internal-docs/custom-themes.md +++ b/internal-docs/custom-themes.md @@ -26,9 +26,9 @@ class MyThemeContext extends DefaultThemeRenderContext { // to destructure the context object to only grab what they care about. override analytics = () => { // Reusing existing option rather than declaring our own for brevity - if (!this.options.isSet("gaSite")) return; + if (!this.options.isSet("gaId")) return; - const site = this.options.getValue("gaSite"); + const site = this.options.getValue("gaId"); const script = ` (function() { diff --git a/src/lib/output/renderer.ts b/src/lib/output/renderer.ts index a5cb0dc14..8fa3227b4 100644 --- a/src/lib/output/renderer.ts +++ b/src/lib/output/renderer.ts @@ -133,10 +133,6 @@ export class Renderer extends ChildableComponent< @BindOption("gaID") gaID!: string; - /** @internal */ - @BindOption("gaSite") - gaSite!: string; - /** @internal */ @BindOption("githubPages") githubPages!: boolean; diff --git a/src/lib/output/themes/default/partials/analytics.tsx b/src/lib/output/themes/default/partials/analytics.tsx index bdb8b928a..afcf8fbbd 100644 --- a/src/lib/output/themes/default/partials/analytics.tsx +++ b/src/lib/output/themes/default/partials/analytics.tsx @@ -3,21 +3,21 @@ import { JSX } from "../../../../utils"; export function analytics(context: DefaultThemeRenderContext) { const gaID = context.options.getValue("gaID"); - const gaSite = context.options.getValue("gaSite"); if (!gaID) return; const script = ` -(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ - (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), - m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) -})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); -ga('create', '${gaID}', '${gaSite}'); -ga('send', 'pageview'); +window.dataLayer = window.dataLayer || []; +function gtag(){dataLayer.push(arguments);} +gtag('js', new Date()); +gtag('config', '${gaID}'); `.trim(); return ( - + <> + + + ); } diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index f157f3356..0c8144a38 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -97,7 +97,6 @@ export interface TypeDocOptionMap { gitRevision: string; gitRemote: string; gaID: string; - gaSite: string; githubPages: boolean; hideGenerator: boolean; hideLegend: boolean; diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index f470defb6..907181199 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -258,11 +258,6 @@ export function addTypeDocOptions(options: Pick) { name: "gaID", help: "Set the Google Analytics tracking ID and activate tracking code.", }); - options.addDeclaration({ - name: "gaSite", - help: "Set the site name for Google Analytics. Defaults to `auto`.", - defaultValue: "auto", - }); options.addDeclaration({ name: "githubPages", help: "Generate a .nojekyll file to prevent 404 errors in GitHub Pages. Defaults to `true`.", diff --git a/src/test/capture-screenshots.ts b/src/test/capture-screenshots.ts index 14d6e6e3d..ac62b8111 100644 --- a/src/test/capture-screenshots.ts +++ b/src/test/capture-screenshots.ts @@ -60,7 +60,6 @@ export async function captureRegressionScreenshots() { app.bootstrap({ logger: "console", readme: join(src, "..", "README.md"), - gaSite: "foo.com", // verify theme option without modifying output name: "typedoc", disableSources: true, cleanOutputDir: true,