mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-30 01:17:07 +02:00
refactor(plugin-google-gtag, plugin-google-analytics): migrate packages to TS (#5561)
* migration * Move to devDeps * Use type assertion
This commit is contained in:
parent
2ef70cb806
commit
19b27ef73b
13 changed files with 128 additions and 30 deletions
|
@ -13,7 +13,7 @@ export default (function () {
|
|||
}
|
||||
|
||||
return {
|
||||
onRouteUpdate({location}) {
|
||||
onRouteUpdate({location}: {location: Location}) {
|
||||
// Set page so that subsequent hits on this page are attributed
|
||||
// to this page. This is recommended for Single-page Applications.
|
||||
window.ga('set', 'page', location.pathname);
|
|
@ -5,12 +5,15 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
import path from 'path';
|
||||
import type {LoadContext, Plugin, HtmlTags} from '@docusaurus/types';
|
||||
import type {ThemeConfig} from '@docusaurus/plugin-google-analytics';
|
||||
|
||||
module.exports = function (context) {
|
||||
const {siteConfig} = context;
|
||||
const {themeConfig} = siteConfig;
|
||||
const {googleAnalytics} = themeConfig || {};
|
||||
export default function pluginGoogleAnalytics(context: LoadContext): Plugin {
|
||||
const {
|
||||
siteConfig: {themeConfig},
|
||||
} = context;
|
||||
const {googleAnalytics} = themeConfig as ThemeConfig;
|
||||
|
||||
if (!googleAnalytics) {
|
||||
throw new Error(
|
||||
|
@ -66,8 +69,8 @@ module.exports = function (context) {
|
|||
src: 'https://www.google-analytics.com/analytics.js',
|
||||
},
|
||||
},
|
||||
],
|
||||
] as HtmlTags,
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
13
packages/docusaurus-plugin-google-analytics/src/plugin-google-analytics.d.ts
vendored
Normal file
13
packages/docusaurus-plugin-google-analytics/src/plugin-google-analytics.d.ts
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
export interface ThemeConfig {
|
||||
googleAnalytics?: {
|
||||
trackingID: string;
|
||||
anonymizeIP?: boolean;
|
||||
};
|
||||
}
|
12
packages/docusaurus-plugin-google-analytics/src/types.d.ts
vendored
Normal file
12
packages/docusaurus-plugin-google-analytics/src/types.d.ts
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/// <reference types="@docusaurus/module-type-aliases" />
|
||||
|
||||
interface Window {
|
||||
ga: (command: string, ...fields: string[]) => void;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue