@docusaurus/plugin-google-tag-manager 0.0.0-5434

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Facebook, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # `@docusaurus/plugin-google-tag-manager`
2
+
3
+ Google Tag Manager plugin for Docusaurus.
4
+
5
+ ## Usage
6
+
7
+ See [plugin-google-tag-manager documentation](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-google-tag-manager).
package/lib/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { LoadContext, Plugin, OptionValidationContext } from '@docusaurus/types';
8
+ import type { PluginOptions, Options } from './options';
9
+ export default function pluginGoogleAnalytics(context: LoadContext, options: PluginOptions): Plugin;
10
+ export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
11
+ export type { PluginOptions, Options };
package/lib/index.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validateOptions = void 0;
10
+ const utils_validation_1 = require("@docusaurus/utils-validation");
11
+ function pluginGoogleAnalytics(context, options) {
12
+ const { containerId } = options;
13
+ const isProd = process.env.NODE_ENV === 'production';
14
+ return {
15
+ name: 'docusaurus-plugin-google-tag-manager',
16
+ contentLoaded({ actions }) {
17
+ actions.setGlobalData(options);
18
+ },
19
+ injectHtmlTags() {
20
+ if (!isProd) {
21
+ return {};
22
+ }
23
+ return {
24
+ preBodyTags: [
25
+ {
26
+ tagName: 'noscript',
27
+ innerHTML: `<iframe src="https://www.googletagmanager.com/ns.html?id=${containerId}" height="0" width="0" style="display:none;visibility:hidden"></iframe>`,
28
+ },
29
+ ],
30
+ headTags: [
31
+ {
32
+ tagName: 'link',
33
+ attributes: {
34
+ rel: 'preconnect',
35
+ href: 'https://www.googletagmanager.com',
36
+ },
37
+ },
38
+ {
39
+ tagName: 'script',
40
+ innerHTML: `window.dataLayer = window.dataLayer || [];`,
41
+ },
42
+ {
43
+ tagName: 'script',
44
+ innerHTML: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
45
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
46
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
47
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
48
+ })(window,document,'script','dataLayer','${containerId}');`,
49
+ },
50
+ ],
51
+ };
52
+ },
53
+ };
54
+ }
55
+ exports.default = pluginGoogleAnalytics;
56
+ const pluginOptionsSchema = utils_validation_1.Joi.object({
57
+ containerId: utils_validation_1.Joi.string().required(),
58
+ });
59
+ function validateOptions({ validate, options, }) {
60
+ return validate(pluginOptionsSchema, options);
61
+ }
62
+ exports.validateOptions = validateOptions;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export declare type PluginOptions = {
8
+ containerId: string;
9
+ };
10
+ export declare type Options = Partial<PluginOptions>;
package/lib/options.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@docusaurus/plugin-google-tag-manager",
3
+ "version": "0.0.0-5434",
4
+ "description": "Google Tag Manager (gtm.js) plugin for Docusaurus.",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc --build",
12
+ "watch": "tsc --build --watch"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/facebook/docusaurus.git",
17
+ "directory": "packages/docusaurus-plugin-google-tag-manager"
18
+ },
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@docusaurus/core": "0.0.0-5434",
22
+ "@docusaurus/types": "0.0.0-5434",
23
+ "@docusaurus/utils-validation": "0.0.0-5434",
24
+ "tslib": "^2.4.0"
25
+ },
26
+ "peerDependencies": {
27
+ "react": "^16.8.4 || ^17.0.0",
28
+ "react-dom": "^16.8.4 || ^17.0.0"
29
+ },
30
+ "engines": {
31
+ "node": ">=16.14"
32
+ },
33
+ "gitHead": "f7a250b65c812db35cb4fab50a6ce9dee0536fd0"
34
+ }
package/src/index.ts ADDED
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {Joi} from '@docusaurus/utils-validation';
9
+ import type {
10
+ LoadContext,
11
+ Plugin,
12
+ OptionValidationContext,
13
+ } from '@docusaurus/types';
14
+ import type {PluginOptions, Options} from './options';
15
+
16
+ export default function pluginGoogleAnalytics(
17
+ context: LoadContext,
18
+ options: PluginOptions,
19
+ ): Plugin {
20
+ const {containerId} = options;
21
+ const isProd = process.env.NODE_ENV === 'production';
22
+
23
+ return {
24
+ name: 'docusaurus-plugin-google-tag-manager',
25
+
26
+ contentLoaded({actions}) {
27
+ actions.setGlobalData(options);
28
+ },
29
+
30
+ injectHtmlTags() {
31
+ if (!isProd) {
32
+ return {};
33
+ }
34
+ return {
35
+ preBodyTags: [
36
+ {
37
+ tagName: 'noscript',
38
+ innerHTML: `<iframe src="https://www.googletagmanager.com/ns.html?id=${containerId}" height="0" width="0" style="display:none;visibility:hidden"></iframe>`,
39
+ },
40
+ ],
41
+ headTags: [
42
+ {
43
+ tagName: 'link',
44
+ attributes: {
45
+ rel: 'preconnect',
46
+ href: 'https://www.googletagmanager.com',
47
+ },
48
+ },
49
+ {
50
+ tagName: 'script',
51
+ innerHTML: `window.dataLayer = window.dataLayer || [];`,
52
+ },
53
+ {
54
+ tagName: 'script',
55
+ innerHTML: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
56
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
57
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
58
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
59
+ })(window,document,'script','dataLayer','${containerId}');`,
60
+ },
61
+ ],
62
+ };
63
+ },
64
+ };
65
+ }
66
+
67
+ const pluginOptionsSchema = Joi.object<PluginOptions>({
68
+ containerId: Joi.string().required(),
69
+ });
70
+
71
+ export function validateOptions({
72
+ validate,
73
+ options,
74
+ }: OptionValidationContext<Options, PluginOptions>): PluginOptions {
75
+ return validate(pluginOptionsSchema, options);
76
+ }
77
+
78
+ export type {PluginOptions, Options};
package/src/options.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ export type PluginOptions = {
9
+ containerId: string;
10
+ };
11
+
12
+ export type Options = Partial<PluginOptions>;
package/src/types.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ /// <reference types="@docusaurus/module-type-aliases" />