@docusaurus/plugin-google-gtag 3.10.1 → 4.0.0-canary-6808

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/lib/index.d.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import type { LoadContext, Plugin } from '@docusaurus/types';
8
8
  import type { PluginOptions, Options } from './options';
9
+ export {} from './vendor-gtag';
9
10
  export default function pluginGoogleGtag(context: LoadContext, options: PluginOptions): Plugin | null;
10
11
  export { validateThemeConfig, validateOptions } from './options';
11
12
  export type { PluginOptions, Options };
@@ -0,0 +1,133 @@
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
+ declare var gtag: Gtag.Gtag;
8
+ declare namespace Gtag {
9
+ interface GtagCommands {
10
+ config: [
11
+ targetId: string,
12
+ config?: ControlParams | EventParams | ConfigParams | CustomParams
13
+ ];
14
+ set: [targetId: string, config: CustomParams | boolean | string] | [config: CustomParams];
15
+ js: [config: Date];
16
+ event: [
17
+ eventName: EventNames | (string & {}),
18
+ eventParams?: ControlParams | EventParams | CustomParams
19
+ ];
20
+ get: [
21
+ targetId: string,
22
+ fieldName: FieldNames | string,
23
+ callback?: (field: string | CustomParams | undefined) => any
24
+ ];
25
+ consent: [
26
+ consentArg: ConsentArg | (string & {}),
27
+ consentParams: ConsentParams
28
+ ];
29
+ }
30
+ interface Gtag {
31
+ <Command extends keyof GtagCommands>(command: Command, ...args: GtagCommands[Command]): void;
32
+ }
33
+ interface ConfigParams {
34
+ page_title?: string | undefined;
35
+ page_location?: string | undefined;
36
+ page_path?: string | undefined;
37
+ send_page_view?: boolean | undefined;
38
+ }
39
+ interface CustomParams {
40
+ [key: string]: any;
41
+ }
42
+ interface ControlParams {
43
+ groups?: string | string[] | undefined;
44
+ send_to?: string | string[] | undefined;
45
+ event_callback?: (() => void) | undefined;
46
+ event_timeout?: number | undefined;
47
+ }
48
+ type EventNames = 'add_payment_info' | 'add_shipping_info' | 'add_to_cart' | 'add_to_wishlist' | 'begin_checkout' | 'checkout_progress' | 'earn_virtual_currency' | 'exception' | 'generate_lead' | 'join_group' | 'level_end' | 'level_start' | 'level_up' | 'login' | 'page_view' | 'post_score' | 'purchase' | 'refund' | 'remove_from_cart' | 'screen_view' | 'search' | 'select_content' | 'select_item' | 'select_promotion' | 'set_checkout_option' | 'share' | 'sign_up' | 'spend_virtual_currency' | 'tutorial_begin' | 'tutorial_complete' | 'unlock_achievement' | 'timing_complete' | 'view_cart' | 'view_item' | 'view_item_list' | 'view_promotion' | 'view_search_results';
49
+ interface EventParams {
50
+ checkout_option?: string | undefined;
51
+ checkout_step?: number | undefined;
52
+ content_id?: string | undefined;
53
+ content_type?: string | undefined;
54
+ coupon?: string | undefined;
55
+ currency?: string | undefined;
56
+ description?: string | undefined;
57
+ fatal?: boolean | undefined;
58
+ items?: Item[] | undefined;
59
+ method?: string | undefined;
60
+ number?: string | undefined;
61
+ promotions?: Promotion[] | undefined;
62
+ screen_name?: string | undefined;
63
+ search_term?: string | undefined;
64
+ shipping?: Currency | undefined;
65
+ tax?: Currency | undefined;
66
+ transaction_id?: string | undefined;
67
+ value?: number | undefined;
68
+ event_label?: string | undefined;
69
+ event_category?: string | undefined;
70
+ /** @see {@link https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data#specify_different_transport_mechanisms specify_different_transport_mechanisms} */
71
+ transport_type?: 'image' | 'xhr' | 'beacon' | undefined;
72
+ }
73
+ type Currency = string | number;
74
+ /**
75
+ * Interface of an item object used in lists for this event.
76
+ *
77
+ * Reference:
78
+ * @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_item_item view_item_item}
79
+ * @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_item_list_item view_item_list_item}
80
+ * @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#select_item_item select_item_item}
81
+ * @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#add_to_cart_item add_to_cart_item}
82
+ * @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_cart_item view_cart_item}
83
+ */
84
+ interface Item {
85
+ item_id?: string | undefined;
86
+ item_name?: string | undefined;
87
+ affiliation?: string | undefined;
88
+ coupon?: string | undefined;
89
+ currency?: string | undefined;
90
+ creative_name?: string | undefined;
91
+ creative_slot?: string | undefined;
92
+ discount?: Currency | undefined;
93
+ index?: number | undefined;
94
+ item_brand?: string | undefined;
95
+ item_category?: string | undefined;
96
+ item_category2?: string | undefined;
97
+ item_category3?: string | undefined;
98
+ item_category4?: string | undefined;
99
+ item_category5?: string | undefined;
100
+ item_list_id?: string | undefined;
101
+ item_list_name?: string | undefined;
102
+ item_variant?: string | undefined;
103
+ location_id?: string | undefined;
104
+ price?: Currency | undefined;
105
+ promotion_id?: string | undefined;
106
+ promotion_name?: string | undefined;
107
+ quantity?: number | undefined;
108
+ }
109
+ interface Promotion {
110
+ creative_name?: string | undefined;
111
+ creative_slot?: string | undefined;
112
+ promotion_id?: string | undefined;
113
+ promotion_name?: string | undefined;
114
+ }
115
+ type FieldNames = 'client_id' | 'session_id' | 'gclid';
116
+ type ConsentArg = 'default' | 'update';
117
+ /**
118
+ * Reference:
119
+ * @see {@link https://support.google.com/tagmanager/answer/10718549#consent-types consent-types}
120
+ * @see {@link https://developers.google.com/tag-platform/devguides/consent consent}
121
+ */
122
+ interface ConsentParams {
123
+ ad_personalization?: 'granted' | 'denied' | undefined;
124
+ ad_user_data?: 'granted' | 'denied' | undefined;
125
+ ad_storage?: 'granted' | 'denied' | undefined;
126
+ analytics_storage?: 'granted' | 'denied' | undefined;
127
+ functionality_storage?: 'granted' | 'denied' | undefined;
128
+ personalization_storage?: 'granted' | 'denied' | undefined;
129
+ security_storage?: 'granted' | 'denied' | undefined;
130
+ wait_for_update?: number | undefined;
131
+ region?: string[] | undefined;
132
+ }
133
+ }
@@ -0,0 +1,7 @@
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
+ */
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-google-gtag",
3
- "version": "3.10.1",
3
+ "version": "4.0.0-canary-6808",
4
4
  "description": "Global Site Tag (gtag.js) plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "scripts": {
8
- "build": "tsc --build",
9
- "watch": "tsc --build --watch"
8
+ "build": "tsc --build && node ../../admin/scripts/copyUntypedFiles.js",
9
+ "watch": "run-p -c copy:watch build:watch",
10
+ "build:watch": "tsc --build --watch",
11
+ "copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
10
12
  },
11
13
  "publishConfig": {
12
14
  "access": "public"
@@ -18,18 +20,17 @@
18
20
  },
19
21
  "license": "MIT",
20
22
  "dependencies": {
21
- "@docusaurus/core": "3.10.1",
22
- "@docusaurus/types": "3.10.1",
23
- "@docusaurus/utils-validation": "3.10.1",
24
- "@types/gtag.js": "^0.0.20",
25
- "tslib": "^2.6.0"
23
+ "@docusaurus/core": "4.0.0-canary-6808",
24
+ "@docusaurus/types": "4.0.0-canary-6808",
25
+ "@docusaurus/utils-validation": "4.0.0-canary-6808",
26
+ "tslib": "^2.8.1"
26
27
  },
27
28
  "peerDependencies": {
28
- "react": "^18.0.0 || ^19.0.0",
29
- "react-dom": "^18.0.0 || ^19.0.0"
29
+ "react": "^19.3.0",
30
+ "react-dom": "^19.3.0"
30
31
  },
31
32
  "engines": {
32
- "node": ">=20.0"
33
+ "node": ">=24.14"
33
34
  },
34
- "gitHead": "41c1a458ecb07d61b6df2761ea4bc1b13db49d12"
35
+ "gitHead": "91e445730a91fbe20dd5fefae560303a0c655aa7"
35
36
  }
package/src/index.ts CHANGED
@@ -8,6 +8,9 @@
8
8
  import type {LoadContext, Plugin} from '@docusaurus/types';
9
9
  import type {PluginOptions, Options} from './options';
10
10
 
11
+ // Not sure why it's needed to expose vendored types 🤷‍️
12
+ export {} from './vendor-gtag';
13
+
11
14
  function createConfigSnippet({
12
15
  trackingID,
13
16
  anonymizeIP,
@@ -0,0 +1,196 @@
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
+ // Types directly copied from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/gtag.js
9
+ // I'd prefer not do that, but this should fix our StackBlitz playground
10
+ // See https://github.com/facebook/docusaurus/pull/12080
11
+ // See https://github.com/facebook/docusaurus/issues/11615
12
+
13
+ /* eslint-disable */
14
+ declare var gtag: Gtag.Gtag;
15
+ declare namespace Gtag {
16
+ interface GtagCommands {
17
+ config: [
18
+ targetId: string,
19
+ config?: ControlParams | EventParams | ConfigParams | CustomParams,
20
+ ];
21
+ // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
22
+ set:
23
+ | [targetId: string, config: CustomParams | boolean | string]
24
+ | [config: CustomParams];
25
+ // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
26
+ js: [config: Date];
27
+ event: [
28
+ eventName: EventNames | (string & {}),
29
+ eventParams?: ControlParams | EventParams | CustomParams,
30
+ ];
31
+ get: [
32
+ targetId: string,
33
+ fieldName: FieldNames | string,
34
+ callback?: (field: string | CustomParams | undefined) => any,
35
+ ];
36
+ consent: [
37
+ consentArg: ConsentArg | (string & {}),
38
+ consentParams: ConsentParams,
39
+ ];
40
+ }
41
+
42
+ interface Gtag {
43
+ <Command extends keyof GtagCommands>(
44
+ command: Command,
45
+ ...args: GtagCommands[Command]
46
+ ): void;
47
+ }
48
+
49
+ interface ConfigParams {
50
+ page_title?: string | undefined;
51
+ page_location?: string | undefined;
52
+ page_path?: string | undefined;
53
+ send_page_view?: boolean | undefined;
54
+ }
55
+
56
+ interface CustomParams {
57
+ [key: string]: any;
58
+ }
59
+
60
+ interface ControlParams {
61
+ groups?: string | string[] | undefined;
62
+ send_to?: string | string[] | undefined;
63
+ event_callback?: (() => void) | undefined;
64
+ event_timeout?: number | undefined;
65
+ }
66
+
67
+ type EventNames =
68
+ | 'add_payment_info'
69
+ | 'add_shipping_info'
70
+ | 'add_to_cart'
71
+ | 'add_to_wishlist'
72
+ | 'begin_checkout'
73
+ | 'checkout_progress'
74
+ | 'earn_virtual_currency'
75
+ | 'exception'
76
+ | 'generate_lead'
77
+ | 'join_group'
78
+ | 'level_end'
79
+ | 'level_start'
80
+ | 'level_up'
81
+ | 'login'
82
+ | 'page_view'
83
+ | 'post_score'
84
+ | 'purchase'
85
+ | 'refund'
86
+ | 'remove_from_cart'
87
+ | 'screen_view'
88
+ | 'search'
89
+ | 'select_content'
90
+ | 'select_item'
91
+ | 'select_promotion'
92
+ | 'set_checkout_option'
93
+ | 'share'
94
+ | 'sign_up'
95
+ | 'spend_virtual_currency'
96
+ | 'tutorial_begin'
97
+ | 'tutorial_complete'
98
+ | 'unlock_achievement'
99
+ | 'timing_complete'
100
+ | 'view_cart'
101
+ | 'view_item'
102
+ | 'view_item_list'
103
+ | 'view_promotion'
104
+ | 'view_search_results';
105
+
106
+ interface EventParams {
107
+ checkout_option?: string | undefined;
108
+ checkout_step?: number | undefined;
109
+ content_id?: string | undefined;
110
+ content_type?: string | undefined;
111
+ coupon?: string | undefined;
112
+ currency?: string | undefined;
113
+ description?: string | undefined;
114
+ fatal?: boolean | undefined;
115
+ items?: Item[] | undefined;
116
+ method?: string | undefined;
117
+ number?: string | undefined;
118
+ promotions?: Promotion[] | undefined;
119
+ screen_name?: string | undefined;
120
+ search_term?: string | undefined;
121
+ shipping?: Currency | undefined;
122
+ tax?: Currency | undefined;
123
+ transaction_id?: string | undefined;
124
+ value?: number | undefined;
125
+ event_label?: string | undefined;
126
+ event_category?: string | undefined;
127
+ /** @see {@link https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data#specify_different_transport_mechanisms specify_different_transport_mechanisms} */
128
+ transport_type?: 'image' | 'xhr' | 'beacon' | undefined;
129
+ }
130
+
131
+ type Currency = string | number;
132
+
133
+ /**
134
+ * Interface of an item object used in lists for this event.
135
+ *
136
+ * Reference:
137
+ * @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_item_item view_item_item}
138
+ * @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_item_list_item view_item_list_item}
139
+ * @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#select_item_item select_item_item}
140
+ * @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#add_to_cart_item add_to_cart_item}
141
+ * @see {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_cart_item view_cart_item}
142
+ */
143
+ interface Item {
144
+ item_id?: string | undefined;
145
+ item_name?: string | undefined;
146
+ affiliation?: string | undefined;
147
+ coupon?: string | undefined;
148
+ currency?: string | undefined;
149
+ creative_name?: string | undefined;
150
+ creative_slot?: string | undefined;
151
+ discount?: Currency | undefined;
152
+ index?: number | undefined;
153
+ item_brand?: string | undefined;
154
+ item_category?: string | undefined;
155
+ item_category2?: string | undefined;
156
+ item_category3?: string | undefined;
157
+ item_category4?: string | undefined;
158
+ item_category5?: string | undefined;
159
+ item_list_id?: string | undefined;
160
+ item_list_name?: string | undefined;
161
+ item_variant?: string | undefined;
162
+ location_id?: string | undefined;
163
+ price?: Currency | undefined;
164
+ promotion_id?: string | undefined;
165
+ promotion_name?: string | undefined;
166
+ quantity?: number | undefined;
167
+ }
168
+
169
+ interface Promotion {
170
+ creative_name?: string | undefined;
171
+ creative_slot?: string | undefined;
172
+ promotion_id?: string | undefined;
173
+ promotion_name?: string | undefined;
174
+ }
175
+
176
+ type FieldNames = 'client_id' | 'session_id' | 'gclid';
177
+
178
+ type ConsentArg = 'default' | 'update';
179
+
180
+ /**
181
+ * Reference:
182
+ * @see {@link https://support.google.com/tagmanager/answer/10718549#consent-types consent-types}
183
+ * @see {@link https://developers.google.com/tag-platform/devguides/consent consent}
184
+ */
185
+ interface ConsentParams {
186
+ ad_personalization?: 'granted' | 'denied' | undefined;
187
+ ad_user_data?: 'granted' | 'denied' | undefined;
188
+ ad_storage?: 'granted' | 'denied' | undefined;
189
+ analytics_storage?: 'granted' | 'denied' | undefined;
190
+ functionality_storage?: 'granted' | 'denied' | undefined;
191
+ personalization_storage?: 'granted' | 'denied' | undefined;
192
+ security_storage?: 'granted' | 'denied' | undefined;
193
+ wait_for_update?: number | undefined;
194
+ region?: string[] | undefined;
195
+ }
196
+ }