Skip to content

Commit

Permalink
Remove gaSite option, update Google Analytics script
Browse files Browse the repository at this point in the history
Closes #1846
  • Loading branch information
Gerrit0 committed Feb 15, 2022
1 parent 848d2aa commit 608c1e7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions internal-docs/custom-themes.md
Expand Up @@ -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() {
Expand Down
4 changes: 0 additions & 4 deletions src/lib/output/renderer.ts
Expand Up @@ -133,10 +133,6 @@ export class Renderer extends ChildableComponent<
@BindOption("gaID")
gaID!: string;

/** @internal */
@BindOption("gaSite")
gaSite!: string;

/** @internal */
@BindOption("githubPages")
githubPages!: boolean;
Expand Down
20 changes: 10 additions & 10 deletions src/lib/output/themes/default/partials/analytics.tsx
Expand Up @@ -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 (
<script>
<JSX.Raw html={script} />
</script>
<>
<script async src={"https://www.googletagmanager.com/gtag/js?id=" + gaID}></script>
<script>
<JSX.Raw html={script} />
</script>
</>
);
}
1 change: 0 additions & 1 deletion src/lib/utils/options/declaration.ts
Expand Up @@ -97,7 +97,6 @@ export interface TypeDocOptionMap {
gitRevision: string;
gitRemote: string;
gaID: string;
gaSite: string;
githubPages: boolean;
hideGenerator: boolean;
hideLegend: boolean;
Expand Down
5 changes: 0 additions & 5 deletions src/lib/utils/options/sources/typedoc.ts
Expand Up @@ -258,11 +258,6 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
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`.",
Expand Down
1 change: 0 additions & 1 deletion src/test/capture-screenshots.ts
Expand Up @@ -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,
Expand Down

0 comments on commit 608c1e7

Please sign in to comment.