@wxt-dev/analytics 0.2.5 → 0.2.7

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 CHANGED
@@ -1,4 +1,4 @@
1
- import { A as AnalyticsConfig, a as Analytics } from './shared/analytics.079e9952.mjs';
1
+ import { A as AnalyticsConfig, a as Analytics } from './shared/analytics.2893a879.mjs';
2
2
 
3
3
  declare function createAnalytics(config?: AnalyticsConfig): Analytics;
4
4
 
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as AnalyticsConfig, a as Analytics } from './shared/analytics.079e9952.js';
1
+ import { A as AnalyticsConfig, a as Analytics } from './shared/analytics.2893a879.js';
2
2
 
3
3
  declare function createAnalytics(config?: AnalyticsConfig): Analytics;
4
4
 
package/dist/client.mjs CHANGED
@@ -13,7 +13,7 @@ function createAnalytics(config) {
13
13
  }
14
14
  if (location.pathname === "/background.js")
15
15
  return createBackgroundAnalytics(config);
16
- return createFrontendAnalytics(config);
16
+ return createFrontendAnalytics();
17
17
  }
18
18
  function createBackgroundAnalytics(config) {
19
19
  const userIdStorage = config?.userId ?? defineStorageItem("wxt-analytics:user-id");
@@ -29,7 +29,7 @@ function createBackgroundAnalytics(config) {
29
29
  );
30
30
  let userProperties = userPropertiesStorage.getValue();
31
31
  const manifest = chrome.runtime.getManifest();
32
- const getBaseEvent = async (meta = {
32
+ const getBackgroundMeta = () => ({
33
33
  timestamp: Date.now(),
34
34
  // Don't track sessions for the background, it can be running
35
35
  // indefinitely, and will inflate session duration stats.
@@ -37,18 +37,13 @@ function createBackgroundAnalytics(config) {
37
37
  language: navigator.language,
38
38
  referrer: void 0,
39
39
  screen: void 0,
40
- url: location.href
41
- }) => {
40
+ url: location.href,
41
+ title: void 0
42
+ });
43
+ const getBaseEvent = async (meta) => {
42
44
  const platform = await platformInfo;
43
45
  return {
44
- meta: {
45
- sessionId: meta.sessionId,
46
- timestamp: meta.timestamp,
47
- screen: meta.screen,
48
- referrer: meta.referrer,
49
- language: meta.language,
50
- url: meta.url
51
- },
46
+ meta,
52
47
  user: {
53
48
  id: await userId,
54
49
  properties: {
@@ -65,14 +60,14 @@ function createBackgroundAnalytics(config) {
65
60
  };
66
61
  };
67
62
  const analytics = {
68
- identify: async (newUserId, newUserProperties = {}, forwardMeta) => {
63
+ identify: async (newUserId, newUserProperties = {}, meta = getBackgroundMeta()) => {
69
64
  userId = Promise.resolve(newUserId);
70
65
  userProperties = Promise.resolve(newUserProperties);
71
66
  await Promise.all([
72
67
  userIdStorage.setValue?.(newUserId),
73
68
  userPropertiesStorage.setValue?.(newUserProperties)
74
69
  ]);
75
- const event = await getBaseEvent(forwardMeta);
70
+ const event = await getBaseEvent(meta);
76
71
  if (config?.debug)
77
72
  console.debug("[analytics] identify", event);
78
73
  if (await enabled.getValue()) {
@@ -85,14 +80,14 @@ function createBackgroundAnalytics(config) {
85
80
  );
86
81
  }
87
82
  },
88
- page: async (location2, forwardMeta) => {
89
- const baseEvent = await getBaseEvent(forwardMeta);
83
+ page: async (location2, meta = getBackgroundMeta()) => {
84
+ const baseEvent = await getBaseEvent(meta);
90
85
  const event = {
91
86
  ...baseEvent,
92
87
  page: {
93
- url: globalThis.location?.href,
88
+ url: meta?.url ?? globalThis.location?.href,
94
89
  location: location2,
95
- title: globalThis.document?.title
90
+ title: meta?.title ?? globalThis.document?.title
96
91
  }
97
92
  };
98
93
  if (config?.debug)
@@ -105,8 +100,8 @@ function createBackgroundAnalytics(config) {
105
100
  console.debug("[analytics] Analytics disabled, page() not uploaded");
106
101
  }
107
102
  },
108
- track: async (eventName, eventProperties, forwardMeta) => {
109
- const baseEvent = await getBaseEvent(forwardMeta);
103
+ track: async (eventName, eventProperties, meta = getBackgroundMeta()) => {
104
+ const baseEvent = await getBaseEvent(meta);
110
105
  const event = {
111
106
  ...baseEvent,
112
107
  event: { name: eventName, properties: eventProperties }
@@ -139,25 +134,20 @@ function createBackgroundAnalytics(config) {
139
134
  });
140
135
  return analytics;
141
136
  }
142
- function createFrontendAnalytics(config) {
137
+ function createFrontendAnalytics() {
143
138
  const port = chrome.runtime.connect({ name: ANALYTICS_PORT });
144
139
  const sessionId = Date.now();
145
- const getMetadata = () => ({
140
+ const getFrontendMetadata = () => ({
146
141
  sessionId,
147
142
  timestamp: Date.now(),
148
143
  language: navigator.language,
149
144
  referrer: globalThis.document?.referrer || void 0,
150
145
  screen: globalThis.window ? `${globalThis.window.screen.width}x${globalThis.window.screen.height}` : void 0,
151
- url: location.href
146
+ url: location.href,
147
+ title: document.title || void 0
152
148
  });
153
149
  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()] });
150
+ port.postMessage({ fn, args: [...args, getFrontendMetadata()] });
161
151
  };
162
152
  const analytics = {
163
153
  identify: methodForwarder("identify"),
@@ -165,14 +155,8 @@ function createFrontendAnalytics(config) {
165
155
  track: methodForwarder("track"),
166
156
  setEnabled: methodForwarder("setEnabled"),
167
157
  autoTrack: (root) => {
168
- if (config?.debug) {
169
- console.debug("[analytics] autoTrack() called!");
170
- }
171
158
  const onClick = (event) => {
172
159
  const element = event.target;
173
- if (config?.debug) {
174
- console.debug("[analytics] autoTrack() element clicked", element);
175
- }
176
160
  if (!element || !INTERACTIVE_TAGS.has(element.tagName) && !INTERACTIVE_ROLES.has(element.getAttribute("role")))
177
161
  return;
178
162
  void analytics.track("click", {
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as wxt from 'wxt';
2
- import { A as AnalyticsConfig } from './shared/analytics.079e9952.mjs';
2
+ import { A as AnalyticsConfig } from './shared/analytics.2893a879.mjs';
3
3
 
4
4
  declare module 'wxt/sandbox' {
5
5
  interface WxtAppConfig {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as wxt from 'wxt';
2
- import { A as AnalyticsConfig } from './shared/analytics.079e9952.js';
2
+ import { A as AnalyticsConfig } from './shared/analytics.2893a879.js';
3
3
 
4
4
  declare module 'wxt/sandbox' {
5
5
  interface WxtAppConfig {
@@ -1,4 +1,4 @@
1
- import { b as AnalyticsProvider } from '../shared/analytics.079e9952.mjs';
1
+ import { b as AnalyticsProvider } from '../shared/analytics.2893a879.mjs';
2
2
 
3
3
  interface GoogleAnalyticsProviderOptions {
4
4
  apiSecret: string;
@@ -1,4 +1,4 @@
1
- import { b as AnalyticsProvider } from '../shared/analytics.079e9952.js';
1
+ import { b as AnalyticsProvider } from '../shared/analytics.2893a879.js';
2
2
 
3
3
  interface GoogleAnalyticsProviderOptions {
4
4
  apiSecret: string;
@@ -1,4 +1,4 @@
1
- import { b as AnalyticsProvider } from '../shared/analytics.079e9952.mjs';
1
+ import { b as AnalyticsProvider } from '../shared/analytics.2893a879.mjs';
2
2
 
3
3
  interface UmamiProviderOptions {
4
4
  baseUrl: string;
@@ -1,4 +1,4 @@
1
- import { b as AnalyticsProvider } from '../shared/analytics.079e9952.js';
1
+ import { b as AnalyticsProvider } from '../shared/analytics.2893a879.js';
2
2
 
3
3
  interface UmamiProviderOptions {
4
4
  baseUrl: string;
@@ -49,25 +49,28 @@ type AnalyticsProvider = (analytics: Analytics, config: AnalyticsConfig) => {
49
49
  identify: (event: BaseAnalyticsEvent) => Promise<void>;
50
50
  };
51
51
  interface BaseAnalyticsEvent {
52
- meta: {
53
- /** Identifier of the session the event was fired from */
54
- sessionId: number | undefined;
55
- /** `Date.now()` of when the event was reported */
56
- timestamp: number;
57
- /** `"1920x1080"` */
58
- screen: string | undefined;
59
- /** `document.referrer` */
60
- referrer: string | undefined;
61
- /** `navigator.language` */
62
- language: string | undefined;
63
- /** `location.href` */
64
- url: string | undefined;
65
- };
52
+ meta: AnalyticsEventMetadata;
66
53
  user: {
67
54
  id: string;
68
55
  properties: Record<string, string | undefined>;
69
56
  };
70
57
  }
58
+ interface AnalyticsEventMetadata {
59
+ /** Identifier of the session the event was fired from */
60
+ sessionId: number | undefined;
61
+ /** `Date.now()` of when the event was reported */
62
+ timestamp: number;
63
+ /** `"1920x1080"` */
64
+ screen: string | undefined;
65
+ /** `document.referrer` */
66
+ referrer: string | undefined;
67
+ /** `navigator.language` */
68
+ language: string | undefined;
69
+ /** `location.href` */
70
+ url: string | undefined;
71
+ /** `document.title` */
72
+ title: string | undefined;
73
+ }
71
74
  interface AnalyticsPageInfo {
72
75
  url: string;
73
76
  title: string | undefined;
@@ -49,25 +49,28 @@ type AnalyticsProvider = (analytics: Analytics, config: AnalyticsConfig) => {
49
49
  identify: (event: BaseAnalyticsEvent) => Promise<void>;
50
50
  };
51
51
  interface BaseAnalyticsEvent {
52
- meta: {
53
- /** Identifier of the session the event was fired from */
54
- sessionId: number | undefined;
55
- /** `Date.now()` of when the event was reported */
56
- timestamp: number;
57
- /** `"1920x1080"` */
58
- screen: string | undefined;
59
- /** `document.referrer` */
60
- referrer: string | undefined;
61
- /** `navigator.language` */
62
- language: string | undefined;
63
- /** `location.href` */
64
- url: string | undefined;
65
- };
52
+ meta: AnalyticsEventMetadata;
66
53
  user: {
67
54
  id: string;
68
55
  properties: Record<string, string | undefined>;
69
56
  };
70
57
  }
58
+ interface AnalyticsEventMetadata {
59
+ /** Identifier of the session the event was fired from */
60
+ sessionId: number | undefined;
61
+ /** `Date.now()` of when the event was reported */
62
+ timestamp: number;
63
+ /** `"1920x1080"` */
64
+ screen: string | undefined;
65
+ /** `document.referrer` */
66
+ referrer: string | undefined;
67
+ /** `navigator.language` */
68
+ language: string | undefined;
69
+ /** `location.href` */
70
+ url: string | undefined;
71
+ /** `document.title` */
72
+ title: string | undefined;
73
+ }
71
74
  interface AnalyticsPageInfo {
72
75
  url: string;
73
76
  title: string | undefined;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@wxt-dev/analytics",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Add analytics to your web extension",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "https://github.com/wxt-dev/wxt.git",
7
+ "url": "git+https://github.com/wxt-dev/wxt.git",
8
8
  "directory": "packages/analytics"
9
9
  },
10
10
  "license": "MIT",