@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 CHANGED
@@ -1,4 +1,4 @@
1
- import { A as AnalyticsConfig, a as Analytics } from './shared/analytics.5d517cf0.mjs';
1
+ import { A as AnalyticsConfig, a as Analytics } from './shared/analytics.079e9952.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.5d517cf0.js';
1
+ import { A as AnalyticsConfig, a as Analytics } from './shared/analytics.079e9952.js';
2
2
 
3
3
  declare function createAnalytics(config?: AnalyticsConfig): Analytics;
4
4
 
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("local:wxt-analytics:user-id");
19
+ const userIdStorage = config?.userId ?? defineStorageItem("wxt-analytics:user-id");
20
20
  const userPropertiesStorage = config?.userProperties ?? defineStorageItem(
21
- "local:wxt-analytics:user-properties",
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("[analytics] Disabled, identify() not called");
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] Disabled, page() not called");
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] Disabled, track() not called");
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) => port.postMessage({ fn, args: [...args, getMetadata()] });
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
@@ -1,5 +1,5 @@
1
1
  import * as wxt from 'wxt';
2
- import { A as AnalyticsConfig } from './shared/analytics.5d517cf0.mjs';
2
+ import { A as AnalyticsConfig } from './shared/analytics.079e9952.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.5d517cf0.js';
2
+ import { A as AnalyticsConfig } from './shared/analytics.079e9952.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.5d517cf0.mjs';
1
+ import { b as AnalyticsProvider } from '../shared/analytics.079e9952.mjs';
2
2
 
3
3
  interface GoogleAnalyticsProviderOptions {
4
4
  apiSecret: string;
@@ -1,4 +1,4 @@
1
- import { b as AnalyticsProvider } from '../shared/analytics.5d517cf0.js';
1
+ import { b as AnalyticsProvider } from '../shared/analytics.079e9952.js';
2
2
 
3
3
  interface GoogleAnalyticsProviderOptions {
4
4
  apiSecret: string;
@@ -1,4 +1,4 @@
1
- import { b as AnalyticsProvider } from '../shared/analytics.5d517cf0.mjs';
1
+ import { b as AnalyticsProvider } from '../shared/analytics.079e9952.mjs';
2
2
 
3
3
  interface UmamiProviderOptions {
4
4
  baseUrl: string;
@@ -1,4 +1,4 @@
1
- import { b as AnalyticsProvider } from '../shared/analytics.5d517cf0.js';
1
+ import { b as AnalyticsProvider } from '../shared/analytics.079e9952.js';
2
2
 
3
3
  interface UmamiProviderOptions {
4
4
  baseUrl: string;
@@ -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: Record<string, string>) => void;
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: Record<string, string>) => void;
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxt-dev/analytics",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Add analytics to your web extension",
5
5
  "repository": {
6
6
  "type": "git",