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,21 @@
MIT License
Copyright (c) Facebook, Inc. and its affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,7 @@
# `@docusaurus/plugin-google-analytics`
Google analytics plugin for Docusaurus.
## Usage
See [plugin-google-analytics documentation](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-google-analytics).

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 });

View File

@@ -0,0 +1,34 @@
{
"name": "@docusaurus/plugin-google-analytics",
"version": "3.1.1",
"description": "Global analytics (analytics.js) plugin for Docusaurus.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc --build",
"watch": "tsc --build --watch"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/docusaurus.git",
"directory": "packages/docusaurus-plugin-google-analytics"
},
"license": "MIT",
"dependencies": {
"@docusaurus/core": "3.1.1",
"@docusaurus/types": "3.1.1",
"@docusaurus/utils-validation": "3.1.1",
"tslib": "^2.6.0"
},
"peerDependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=18.0"
},
"gitHead": "8017f6a6776ba1bd7065e630a52fe2c2654e2f1b"
}

View File

@@ -0,0 +1,32 @@
/**
* 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';
const clientModule: 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,91 @@
/**
* 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 {Joi} from '@docusaurus/utils-validation';
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 {
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',
},
},
],
};
},
};
}
const pluginOptionsSchema = Joi.object<PluginOptions>({
trackingID: Joi.string().required(),
anonymizeIP: Joi.boolean().default(false),
});
export function validateOptions({
validate,
options,
}: OptionValidationContext<Options, PluginOptions>): PluginOptions {
return validate(pluginOptionsSchema, options);
}
export function validateThemeConfig({
themeConfig,
}: ThemeConfigValidationContext<ThemeConfig>): 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;
}
export type {PluginOptions, Options};

View 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 type PluginOptions = {
trackingID: string;
anonymizeIP: boolean;
};
export type Options = Partial<PluginOptions>;

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.
*/
/// <reference types="@docusaurus/module-type-aliases" />
interface Window {
ga: (command: string, ...fields: string[]) => void;
}