rsbuild-plugin-google-analytics 1.0.2 → 1.0.4

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
@@ -6,7 +6,8 @@ An Rsbuild plugin to setup Google Analytics in your website.
6
6
  <a href="https://npmjs.com/package/rsbuild-plugin-google-analytics">
7
7
  <img src="https://img.shields.io/npm/v/rsbuild-plugin-google-analytics?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
8
8
  </a>
9
- <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
9
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
10
+ <a href="https://npmcharts.com/compare/rsbuild-plugin-google-analytics?minimal=true"><img src="https://img.shields.io/npm/dm/rsbuild-plugin-google-analytics.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
10
11
  </p>
11
12
 
12
13
  ## Usage
@@ -38,9 +39,10 @@ export default {
38
39
 
39
40
  Here are the available options:
40
41
 
41
- | Name | Type | Description | Defaults |
42
- | ---- | -------- | ------------- | ----------- |
43
- | id | `string` | Google tag ID | `undefined` |
42
+ | Name | Type | Description | Defaults |
43
+ | ------ | --------- | ---------------------------------- | ----------- |
44
+ | id | `string` | Google tag ID | `undefined` |
45
+ | enable | `boolean` | Whether to enable Google Analytics | `true` |
44
46
 
45
47
  ## License
46
48
 
package/dist/index.cjs CHANGED
@@ -1,65 +1,66 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- pluginGoogleAnalytics: () => pluginGoogleAnalytics
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ pluginGoogleAnalytics: ()=>pluginGoogleAnalytics
24
28
  });
25
- module.exports = __toCommonJS(src_exports);
26
- var pluginGoogleAnalytics = ({
27
- id
28
- }) => ({
29
- name: "rsbuild-plugin-google-analytics",
30
- setup(api) {
31
- if (!id) {
32
- throw new Error(
33
- "[rsbuild-plugin-google-analytics] Google tag ID is required!"
34
- );
35
- }
36
- api.modifyRsbuildConfig((userConfig, { mergeRsbuildConfig }) => {
37
- const extraConfig = {
38
- html: {
39
- tags: [
40
- {
41
- tag: "script",
42
- attrs: {
43
- async: true,
44
- src: `https://www.googletagmanager.com/gtag/js?id=${id}`
45
- }
46
- },
47
- {
48
- tag: "script",
49
- children: `
29
+ const pluginGoogleAnalytics = ({ id, enable = true })=>({
30
+ name: 'rsbuild-plugin-google-analytics',
31
+ setup (api) {
32
+ if (!enable) return;
33
+ if (!id) throw new Error('[rsbuild-plugin-google-analytics] Google tag ID is required!');
34
+ api.modifyRsbuildConfig((userConfig, { mergeRsbuildConfig })=>{
35
+ const extraConfig = {
36
+ html: {
37
+ tags: [
38
+ {
39
+ tag: "script",
40
+ attrs: {
41
+ async: true,
42
+ src: `https://www.googletagmanager.com/gtag/js?id=${id}`
43
+ }
44
+ },
45
+ {
46
+ tag: "script",
47
+ children: `
50
48
  window.dataLayer = window.dataLayer || [];
51
49
  function gtag(){dataLayer.push(arguments);}
52
50
  gtag('js', new Date());
53
51
  gtag('config', '${id}');`
54
- }
55
- ]
52
+ }
53
+ ]
54
+ }
55
+ };
56
+ return mergeRsbuildConfig(extraConfig, userConfig);
57
+ });
56
58
  }
57
- };
58
- return mergeRsbuildConfig(extraConfig, userConfig);
59
59
  });
60
- }
61
- });
62
- // Annotate the CommonJS export names for ESM import in node:
63
- 0 && (module.exports = {
64
- pluginGoogleAnalytics
60
+ exports.pluginGoogleAnalytics = __webpack_exports__.pluginGoogleAnalytics;
61
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
62
+ "pluginGoogleAnalytics"
63
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
64
+ Object.defineProperty(exports, '__esModule', {
65
+ value: true
65
66
  });
package/dist/index.d.ts CHANGED
@@ -1,8 +1,13 @@
1
- import { RsbuildPlugin } from '@rsbuild/core';
2
-
3
- type PluginGoogleAnalyticsOptions = {
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ export type PluginGoogleAnalyticsOptions = {
3
+ /**
4
+ * Google tag ID.
5
+ */
4
6
  id: string;
7
+ /**
8
+ * Whether to enable Google Analytics.
9
+ * @default true
10
+ */
11
+ enable?: boolean;
5
12
  };
6
- declare const pluginGoogleAnalytics: ({ id, }: PluginGoogleAnalyticsOptions) => RsbuildPlugin;
7
-
8
- export { type PluginGoogleAnalyticsOptions, pluginGoogleAnalytics };
13
+ export declare const pluginGoogleAnalytics: ({ id, enable, }: PluginGoogleAnalyticsOptions) => RsbuildPlugin;
package/dist/index.js CHANGED
@@ -1,40 +1,32 @@
1
- // src/index.ts
2
- var pluginGoogleAnalytics = ({
3
- id
4
- }) => ({
5
- name: "rsbuild-plugin-google-analytics",
6
- setup(api) {
7
- if (!id) {
8
- throw new Error(
9
- "[rsbuild-plugin-google-analytics] Google tag ID is required!"
10
- );
11
- }
12
- api.modifyRsbuildConfig((userConfig, { mergeRsbuildConfig }) => {
13
- const extraConfig = {
14
- html: {
15
- tags: [
16
- {
17
- tag: "script",
18
- attrs: {
19
- async: true,
20
- src: `https://www.googletagmanager.com/gtag/js?id=${id}`
21
- }
22
- },
23
- {
24
- tag: "script",
25
- children: `
1
+ const pluginGoogleAnalytics = ({ id, enable = true })=>({
2
+ name: 'rsbuild-plugin-google-analytics',
3
+ setup (api) {
4
+ if (!enable) return;
5
+ if (!id) throw new Error('[rsbuild-plugin-google-analytics] Google tag ID is required!');
6
+ api.modifyRsbuildConfig((userConfig, { mergeRsbuildConfig })=>{
7
+ const extraConfig = {
8
+ html: {
9
+ tags: [
10
+ {
11
+ tag: "script",
12
+ attrs: {
13
+ async: true,
14
+ src: `https://www.googletagmanager.com/gtag/js?id=${id}`
15
+ }
16
+ },
17
+ {
18
+ tag: "script",
19
+ children: `
26
20
  window.dataLayer = window.dataLayer || [];
27
21
  function gtag(){dataLayer.push(arguments);}
28
22
  gtag('js', new Date());
29
23
  gtag('config', '${id}');`
30
- }
31
- ]
24
+ }
25
+ ]
26
+ }
27
+ };
28
+ return mergeRsbuildConfig(extraConfig, userConfig);
29
+ });
32
30
  }
33
- };
34
- return mergeRsbuildConfig(extraConfig, userConfig);
35
31
  });
36
- }
37
- });
38
- export {
39
- pluginGoogleAnalytics
40
- };
32
+ export { pluginGoogleAnalytics };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsbuild-plugin-google-analytics",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "repository": "https://github.com/rspack-contrib/rsbuild-plugin-google-analytics",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,27 +17,30 @@
17
17
  "files": [
18
18
  "dist"
19
19
  ],
20
+ "scripts": {
21
+ "build": "rslib build",
22
+ "dev": "rslib build --watch",
23
+ "prepare": "npm run build",
24
+ "bump": "npx bumpp"
25
+ },
20
26
  "devDependencies": {
21
- "@rsbuild/core": "^1.0.1-beta.10",
22
- "@types/node": "^20.14.13",
23
- "prettier": "^3.3.3",
24
- "tsup": "^8.2.3",
25
- "typescript": "^5.5.4"
27
+ "@rsbuild/core": "^1.4.12",
28
+ "@rslib/core": "^0.11.0",
29
+ "@types/node": "^22.17.0",
30
+ "prettier": "^3.6.2",
31
+ "typescript": "^5.9.2"
26
32
  },
27
33
  "peerDependencies": {
28
- "@rsbuild/core": "0.x || 1.x || ^1.0.1-beta.0"
34
+ "@rsbuild/core": "1.x"
29
35
  },
30
36
  "peerDependenciesMeta": {
31
37
  "@rsbuild/core": {
32
38
  "optional": true
33
39
  }
34
40
  },
41
+ "packageManager": "pnpm@10.14.0",
35
42
  "publishConfig": {
36
43
  "access": "public",
37
44
  "registry": "https://registry.npmjs.org/"
38
- },
39
- "scripts": {
40
- "build": "tsup",
41
- "dev": "tsup --watch"
42
45
  }
43
- }
46
+ }
package/dist/index.d.cts DELETED
@@ -1,8 +0,0 @@
1
- import { RsbuildPlugin } from '@rsbuild/core';
2
-
3
- type PluginGoogleAnalyticsOptions = {
4
- id: string;
5
- };
6
- declare const pluginGoogleAnalytics: ({ id, }: PluginGoogleAnalyticsOptions) => RsbuildPlugin;
7
-
8
- export { type PluginGoogleAnalyticsOptions, pluginGoogleAnalytics };