@wxt-dev/analytics 0.5.2 → 0.5.3
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/index.mjs +5 -4
- package/dist/module.mjs +2 -2
- package/dist/types.d.mts +3 -3
- package/package.json +16 -15
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { UAParser } from "ua-parser-js";
|
|
2
2
|
import { browser } from "@wxt-dev/browser";
|
|
3
|
+
import { isBackground } from "@wxt-dev/is-background";
|
|
3
4
|
|
|
4
5
|
//#region modules/analytics/client.ts
|
|
5
6
|
const ANALYTICS_PORT = "@wxt-dev/analytics";
|
|
@@ -21,7 +22,7 @@ const INTERACTIVE_ROLES = new Set([
|
|
|
21
22
|
function createAnalytics(config) {
|
|
22
23
|
if (!browser?.runtime?.id) throw Error("Cannot use WXT analytics in contexts without access to the browser.runtime APIs");
|
|
23
24
|
if (config == null) console.warn("[@wxt-dev/analytics] Config not provided to createAnalytics. If you're using WXT, add the 'analytics' property to '<srcDir>/app.config.ts'.");
|
|
24
|
-
if (
|
|
25
|
+
if (isBackground()) return createBackgroundAnalytics(config);
|
|
25
26
|
return createFrontendAnalytics();
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
@@ -124,8 +125,8 @@ function createFrontendAnalytics() {
|
|
|
124
125
|
sessionId,
|
|
125
126
|
timestamp: Date.now(),
|
|
126
127
|
language: navigator.language,
|
|
127
|
-
referrer:
|
|
128
|
-
screen:
|
|
128
|
+
referrer: document.referrer || void 0,
|
|
129
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
129
130
|
url: location.href,
|
|
130
131
|
title: document.title || void 0
|
|
131
132
|
});
|
|
@@ -143,7 +144,7 @@ function createFrontendAnalytics() {
|
|
|
143
144
|
autoTrack: (root) => {
|
|
144
145
|
const onClick = (event) => {
|
|
145
146
|
const element = event.target;
|
|
146
|
-
if (!element || !INTERACTIVE_TAGS.has(element.tagName) && !INTERACTIVE_ROLES.has(element.getAttribute("role"))) return;
|
|
147
|
+
if (!element || !INTERACTIVE_TAGS.has(element.tagName) && !INTERACTIVE_ROLES.has(element.getAttribute("role") ?? "")) return;
|
|
147
148
|
analytics.track("click", {
|
|
148
149
|
tagName: element.tagName?.toLowerCase(),
|
|
149
150
|
id: element.id || void 0,
|
package/dist/module.mjs
CHANGED
|
@@ -19,9 +19,9 @@ var analytics_default = defineWxtModule({
|
|
|
19
19
|
if (!manifest.permissions.includes("storage")) manifest.permissions.push("storage");
|
|
20
20
|
});
|
|
21
21
|
const wxtAnalyticsCode = `import { createAnalytics } from '${clientModuleId}';
|
|
22
|
-
import {
|
|
22
|
+
import { getAppConfig } from '#imports';
|
|
23
23
|
|
|
24
|
-
export const analytics = createAnalytics(
|
|
24
|
+
export const analytics = createAnalytics(getAppConfig().analytics);
|
|
25
25
|
`;
|
|
26
26
|
addAlias(wxt, "#analytics", wxtAnalyticsIndex);
|
|
27
27
|
wxt.hook("prepare:types", async (_, entries) => {
|
package/dist/types.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ interface Analytics {
|
|
|
3
3
|
/** Report a page change. */
|
|
4
4
|
page: (url: string) => void;
|
|
5
5
|
/** Report a custom event. */
|
|
6
|
-
track: (eventName: string, eventProperties?: Record<string, string>) => void;
|
|
6
|
+
track: (eventName: string, eventProperties?: Record<string, string | undefined>) => void;
|
|
7
7
|
/** Save information about the user. */
|
|
8
8
|
identify: (userId: string, userProperties?: Record<string, string>) => void;
|
|
9
9
|
/** Automatically setup and track user interactions, returning a function to remove any listeners that were setup. */
|
|
@@ -32,7 +32,7 @@ interface AnalyticsConfig {
|
|
|
32
32
|
/**
|
|
33
33
|
* Configure how the user Id is persisted. Defaults to using `browser.storage.local`.
|
|
34
34
|
*/
|
|
35
|
-
userId?: AnalyticsStorageItem<string>;
|
|
35
|
+
userId?: AnalyticsStorageItem<string | undefined>;
|
|
36
36
|
/**
|
|
37
37
|
* Configure how user properties are persisted. Defaults to using `browser.storage.local`.
|
|
38
38
|
*/
|
|
@@ -81,7 +81,7 @@ interface AnalyticsPageViewEvent extends BaseAnalyticsEvent {
|
|
|
81
81
|
interface AnalyticsTrackEvent extends BaseAnalyticsEvent {
|
|
82
82
|
event: {
|
|
83
83
|
name: string;
|
|
84
|
-
properties?: Record<string, string>;
|
|
84
|
+
properties?: Record<string, string | undefined>;
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxt-dev/analytics",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Add analytics to your web extension",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"ua-parser-js": "^1.0.40",
|
|
8
|
+
"@wxt-dev/browser": "^0.1.37",
|
|
9
|
+
"@wxt-dev/is-background": "^1.0.0"
|
|
10
|
+
},
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"wxt": ">=0.20.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/ua-parser-js": "^0.7.39",
|
|
16
|
+
"publint": "^0.3.17",
|
|
17
|
+
"typescript": "^5.9.3",
|
|
18
|
+
"wxt": "0.20.17"
|
|
19
|
+
},
|
|
5
20
|
"repository": {
|
|
6
21
|
"type": "git",
|
|
7
22
|
"url": "git+https://github.com/wxt-dev/wxt.git",
|
|
8
23
|
"directory": "packages/analytics"
|
|
9
24
|
},
|
|
10
25
|
"license": "MIT",
|
|
11
|
-
"type": "module",
|
|
12
26
|
"exports": {
|
|
13
27
|
".": {
|
|
14
28
|
"types": "./dist/index.d.mts",
|
|
@@ -39,19 +53,6 @@
|
|
|
39
53
|
"files": [
|
|
40
54
|
"dist"
|
|
41
55
|
],
|
|
42
|
-
"peerDependencies": {
|
|
43
|
-
"wxt": ">=0.20.0"
|
|
44
|
-
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"@types/ua-parser-js": "^0.7.39",
|
|
47
|
-
"publint": "^0.3.17",
|
|
48
|
-
"typescript": "^5.9.3",
|
|
49
|
-
"wxt": "0.20.16"
|
|
50
|
-
},
|
|
51
|
-
"dependencies": {
|
|
52
|
-
"ua-parser-js": "^1.0.40",
|
|
53
|
-
"@wxt-dev/browser": "^0.1.36"
|
|
54
|
-
},
|
|
55
56
|
"scripts": {
|
|
56
57
|
"dev": "buildc --deps-only -- wxt",
|
|
57
58
|
"dev:build": "buildc --deps-only -- wxt build",
|