@azerion/bunosaurus-plugin-google-tag-manager 0.0.0-stage → 4.0.0

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/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # `@docusaurus/plugin-google-tag-manager`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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 pluginGoogleTagManager(context: LoadContext, options: PluginOptions): Plugin | null;
10
+ export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
11
+ export type { PluginOptions, Options };
package/lib/index.js ADDED
@@ -0,0 +1,60 @@
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.default = pluginGoogleTagManager;
10
+ exports.validateOptions = validateOptions;
11
+ const utils_validation_1 = require("@docusaurus/utils-validation");
12
+ function pluginGoogleTagManager(context, options) {
13
+ if (process.env.NODE_ENV !== 'production') {
14
+ return null;
15
+ }
16
+ const { containerId } = options;
17
+ return {
18
+ name: 'docusaurus-plugin-google-tag-manager',
19
+ contentLoaded({ actions }) {
20
+ actions.setGlobalData(options);
21
+ },
22
+ injectHtmlTags() {
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
+ const pluginOptionsSchema = utils_validation_1.Joi.object({
56
+ containerId: utils_validation_1.Joi.string().required(),
57
+ });
58
+ function validateOptions({ validate, options, }) {
59
+ return validate(pluginOptionsSchema, options);
60
+ }
@@ -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 type PluginOptions = {
8
+ containerId: string;
9
+ };
10
+ export 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 CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@azerion/bunosaurus-plugin-google-tag-manager",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.0.0",
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/azerion/bunosaurus.git",
17
+ "directory": "packages/docusaurus-plugin-google-tag-manager"
18
+ },
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@docusaurus/core": "npm:@azerion/bunosaurus-core@4.0.0",
22
+ "@docusaurus/types": "npm:@azerion/bunosaurus-types@4.0.0",
23
+ "@docusaurus/utils-validation": "npm:@azerion/bunosaurus-utils-validation@4.0.0",
24
+ "tslib": "^2.8.1"
25
+ },
26
+ "devDependencies": {
27
+ "@docusaurus/module-type-aliases": "npm:@azerion/bunosaurus-module-type-aliases@4.0.0"
28
+ },
29
+ "peerDependencies": {
30
+ "react": "^19.3.0",
31
+ "react-dom": "^19.3.0"
32
+ },
33
+ "engines": {
34
+ "bun": ">=1.4.1"
35
+ }
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1,77 @@
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 pluginGoogleTagManager(
17
+ context: LoadContext,
18
+ options: PluginOptions,
19
+ ): Plugin | null {
20
+ if (process.env.NODE_ENV !== 'production') {
21
+ return null;
22
+ }
23
+
24
+ const {containerId} = options;
25
+ return {
26
+ name: 'docusaurus-plugin-google-tag-manager',
27
+
28
+ contentLoaded({actions}) {
29
+ actions.setGlobalData(options);
30
+ },
31
+
32
+ injectHtmlTags() {
33
+ return {
34
+ preBodyTags: [
35
+ {
36
+ tagName: 'noscript',
37
+ innerHTML: `<iframe src="https://www.googletagmanager.com/ns.html?id=${containerId}" height="0" width="0" style="display:none;visibility:hidden"></iframe>`,
38
+ },
39
+ ],
40
+ headTags: [
41
+ {
42
+ tagName: 'link',
43
+ attributes: {
44
+ rel: 'preconnect',
45
+ href: 'https://www.googletagmanager.com',
46
+ },
47
+ },
48
+ {
49
+ tagName: 'script',
50
+ innerHTML: `window.dataLayer = window.dataLayer || [];`,
51
+ },
52
+ {
53
+ tagName: 'script',
54
+ innerHTML: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
55
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
56
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
57
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
58
+ })(window,document,'script','dataLayer','${containerId}');`,
59
+ },
60
+ ],
61
+ };
62
+ },
63
+ };
64
+ }
65
+
66
+ const pluginOptionsSchema = Joi.object<PluginOptions>({
67
+ containerId: Joi.string().required(),
68
+ });
69
+
70
+ export function validateOptions({
71
+ validate,
72
+ options,
73
+ }: OptionValidationContext<Options, PluginOptions>): PluginOptions {
74
+ return validate(pluginOptionsSchema, options);
75
+ }
76
+
77
+ 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" />