@wxt-dev/analytics 0.2.2 → 0.2.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/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.mjs +24 -8
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/providers/google-analytics-4.d.mts +1 -1
- package/dist/providers/google-analytics-4.d.ts +1 -1
- package/dist/providers/umami.d.mts +1 -1
- package/dist/providers/umami.d.ts +1 -1
- package/dist/shared/{analytics.5d517cf0.d.mts → analytics.079e9952.d.mts} +2 -2
- package/dist/shared/{analytics.5d517cf0.d.ts → analytics.079e9952.d.ts} +2 -2
- package/package.json +1 -1
package/dist/client.d.mts
CHANGED
package/dist/client.d.ts
CHANGED
package/dist/client.mjs
CHANGED
|
@@ -13,12 +13,12 @@ function createAnalytics(config) {
|
|
|
13
13
|
}
|
|
14
14
|
if (location.pathname === "/background.js")
|
|
15
15
|
return createBackgroundAnalytics(config);
|
|
16
|
-
return createFrontendAnalytics();
|
|
16
|
+
return createFrontendAnalytics(config);
|
|
17
17
|
}
|
|
18
18
|
function createBackgroundAnalytics(config) {
|
|
19
|
-
const userIdStorage = config?.userId ?? defineStorageItem("
|
|
19
|
+
const userIdStorage = config?.userId ?? defineStorageItem("wxt-analytics:user-id");
|
|
20
20
|
const userPropertiesStorage = config?.userProperties ?? defineStorageItem(
|
|
21
|
-
"
|
|
21
|
+
"wxt-analytics:user-properties",
|
|
22
22
|
{}
|
|
23
23
|
);
|
|
24
24
|
const enabled = config?.enabled ?? defineStorageItem("local:wxt-analytics:enabled", false);
|
|
@@ -80,7 +80,9 @@ function createBackgroundAnalytics(config) {
|
|
|
80
80
|
providers.map((provider) => provider.identify(event))
|
|
81
81
|
);
|
|
82
82
|
} else if (config?.debug) {
|
|
83
|
-
console.debug(
|
|
83
|
+
console.debug(
|
|
84
|
+
"[analytics] Analytics disabled, identify() not uploaded"
|
|
85
|
+
);
|
|
84
86
|
}
|
|
85
87
|
},
|
|
86
88
|
page: async (url, forwardMeta) => {
|
|
@@ -100,7 +102,7 @@ function createBackgroundAnalytics(config) {
|
|
|
100
102
|
providers.map((provider) => provider.page(event))
|
|
101
103
|
);
|
|
102
104
|
} else if (config?.debug) {
|
|
103
|
-
console.debug("[analytics]
|
|
105
|
+
console.debug("[analytics] Analytics disabled, page() not uploaded");
|
|
104
106
|
}
|
|
105
107
|
},
|
|
106
108
|
track: async (eventName, eventProperties, forwardMeta) => {
|
|
@@ -116,7 +118,7 @@ function createBackgroundAnalytics(config) {
|
|
|
116
118
|
providers.map((provider) => provider.track(event))
|
|
117
119
|
);
|
|
118
120
|
} else if (config?.debug) {
|
|
119
|
-
console.debug("[analytics]
|
|
121
|
+
console.debug("[analytics] Analytics disabled, track() not uploaded");
|
|
120
122
|
}
|
|
121
123
|
},
|
|
122
124
|
setEnabled: async (newEnabled) => {
|
|
@@ -137,7 +139,7 @@ function createBackgroundAnalytics(config) {
|
|
|
137
139
|
});
|
|
138
140
|
return analytics;
|
|
139
141
|
}
|
|
140
|
-
function createFrontendAnalytics() {
|
|
142
|
+
function createFrontendAnalytics(config) {
|
|
141
143
|
const port = chrome.runtime.connect({ name: ANALYTICS_PORT });
|
|
142
144
|
const sessionId = Date.now();
|
|
143
145
|
const getMetadata = () => ({
|
|
@@ -148,15 +150,29 @@ function createFrontendAnalytics() {
|
|
|
148
150
|
screen: globalThis.window ? `${globalThis.window.screen.width}x${globalThis.window.screen.height}` : void 0,
|
|
149
151
|
url: location.href
|
|
150
152
|
});
|
|
151
|
-
const methodForwarder = (fn) => (...args) =>
|
|
153
|
+
const methodForwarder = (fn) => (...args) => {
|
|
154
|
+
if (config?.debug) {
|
|
155
|
+
console.debug(
|
|
156
|
+
`[analytics] Sending ${fn} to background for upload`,
|
|
157
|
+
...args
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
port.postMessage({ fn, args: [...args, getMetadata()] });
|
|
161
|
+
};
|
|
152
162
|
const analytics = {
|
|
153
163
|
identify: methodForwarder("identify"),
|
|
154
164
|
page: methodForwarder("page"),
|
|
155
165
|
track: methodForwarder("track"),
|
|
156
166
|
setEnabled: methodForwarder("setEnabled"),
|
|
157
167
|
autoTrack: (root) => {
|
|
168
|
+
if (config?.debug) {
|
|
169
|
+
console.debug("[analytics] autoTrack() called!");
|
|
170
|
+
}
|
|
158
171
|
const onClick = (event) => {
|
|
159
172
|
const element = event.target;
|
|
173
|
+
if (config?.debug) {
|
|
174
|
+
console.debug("[analytics] autoTrack() element clicked", element);
|
|
175
|
+
}
|
|
160
176
|
if (!element || !INTERACTIVE_TAGS.has(element.tagName) && !INTERACTIVE_ROLES.has(element.getAttribute("role")))
|
|
161
177
|
return;
|
|
162
178
|
void analytics.track("click", {
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ interface Analytics {
|
|
|
2
2
|
/** Report a page change */
|
|
3
3
|
page: (url: string) => void;
|
|
4
4
|
/** Report a custom event */
|
|
5
|
-
track: (eventName: string, eventProperties
|
|
5
|
+
track: (eventName: string, eventProperties?: Record<string, string>) => void;
|
|
6
6
|
/** Save information about the user */
|
|
7
7
|
identify: (userId: string, userProperties?: Record<string, string>) => void;
|
|
8
8
|
/** Automatically setup and track user interactions, returning a function to remove any listeners that were setup. */
|
|
@@ -24,7 +24,7 @@ interface AnalyticsConfig {
|
|
|
24
24
|
*/
|
|
25
25
|
version?: string;
|
|
26
26
|
/**
|
|
27
|
-
* Configure how the enabled flag is persisted
|
|
27
|
+
* Configure how the enabled flag is persisted. Defaults to using `""` in local extension storage.
|
|
28
28
|
*/
|
|
29
29
|
enabled?: AnalyticsStorageItem<boolean>;
|
|
30
30
|
/**
|
|
@@ -2,7 +2,7 @@ interface Analytics {
|
|
|
2
2
|
/** Report a page change */
|
|
3
3
|
page: (url: string) => void;
|
|
4
4
|
/** Report a custom event */
|
|
5
|
-
track: (eventName: string, eventProperties
|
|
5
|
+
track: (eventName: string, eventProperties?: Record<string, string>) => void;
|
|
6
6
|
/** Save information about the user */
|
|
7
7
|
identify: (userId: string, userProperties?: Record<string, string>) => void;
|
|
8
8
|
/** Automatically setup and track user interactions, returning a function to remove any listeners that were setup. */
|
|
@@ -24,7 +24,7 @@ interface AnalyticsConfig {
|
|
|
24
24
|
*/
|
|
25
25
|
version?: string;
|
|
26
26
|
/**
|
|
27
|
-
* Configure how the enabled flag is persisted
|
|
27
|
+
* Configure how the enabled flag is persisted. Defaults to using `""` in local extension storage.
|
|
28
28
|
*/
|
|
29
29
|
enabled?: AnalyticsStorageItem<boolean>;
|
|
30
30
|
/**
|