This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,9 @@
/**
* 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.
*/
import type { ClientModule } from '@docusaurus/types';
declare const clientModule: ClientModule;
export default clientModule;

View File

@@ -0,0 +1,22 @@
/**
* 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.
*/
const clientModule = {
onRouteDidUpdate({ location, previousLocation }) {
if (previousLocation &&
(location.pathname !== previousLocation.pathname ||
location.search !== previousLocation.search ||
location.hash !== previousLocation.hash)) {
// 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 + location.search + location.hash);
// Always refer to the variable on window in-case it gets
// overridden elsewhere.
window.ga('send', 'pageview');
}
},
};
export default clientModule;

View 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.
*/
import type { LoadContext, Plugin, OptionValidationContext, ThemeConfig, ThemeConfigValidationContext } from '@docusaurus/types';
import type { PluginOptions, Options } from './options';
export default function pluginGoogleAnalytics(context: LoadContext, options: PluginOptions): Plugin;
export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
export declare function validateThemeConfig({ themeConfig, }: ThemeConfigValidationContext<ThemeConfig>): ThemeConfig;
export type { PluginOptions, Options };

View File

@@ -0,0 +1,69 @@
"use strict";
/**
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateThemeConfig = exports.validateOptions = void 0;
const utils_validation_1 = require("@docusaurus/utils-validation");
function pluginGoogleAnalytics(context, options) {
const { trackingID, anonymizeIP } = options;
const isProd = process.env.NODE_ENV === 'production';
return {
name: 'docusaurus-plugin-google-analytics',
getClientModules() {
return isProd ? ['./analytics'] : [];
},
injectHtmlTags() {
if (!isProd) {
return {};
}
return {
headTags: [
{
tagName: 'link',
attributes: {
rel: 'preconnect',
href: 'https://www.google-analytics.com',
},
},
// https://developers.google.com/analytics/devguides/collection/analyticsjs/#alternative_async_tag
{
tagName: 'script',
innerHTML: `
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', '${trackingID}', 'auto');
${anonymizeIP ? "ga('set', 'anonymizeIp', true);\n" : ''}
ga('send', 'pageview');
`,
},
{
tagName: 'script',
attributes: {
async: true,
src: 'https://www.google-analytics.com/analytics.js',
},
},
],
};
},
};
}
exports.default = pluginGoogleAnalytics;
const pluginOptionsSchema = utils_validation_1.Joi.object({
trackingID: utils_validation_1.Joi.string().required(),
anonymizeIP: utils_validation_1.Joi.boolean().default(false),
});
function validateOptions({ validate, options, }) {
return validate(pluginOptionsSchema, options);
}
exports.validateOptions = validateOptions;
function validateThemeConfig({ themeConfig, }) {
if ('googleAnalytics' in themeConfig) {
throw new Error('The "googleAnalytics" field in themeConfig should now be specified as option for plugin-google-analytics. More information at https://github.com/facebook/docusaurus/pull/5832.');
}
return themeConfig;
}
exports.validateThemeConfig = validateThemeConfig;

View File

@@ -0,0 +1,11 @@
/**
* 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 type PluginOptions = {
trackingID: string;
anonymizeIP: boolean;
};
export type Options = Partial<PluginOptions>;

View File

@@ -0,0 +1,8 @@
"use strict";
/**
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });