@wxt-dev/analytics 0.2.1 → 0.2.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/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);
@@ -137,7 +137,7 @@ function createBackgroundAnalytics(config) {
137
137
  });
138
138
  return analytics;
139
139
  }
140
- function createFrontendAnalytics() {
140
+ function createFrontendAnalytics(config) {
141
141
  const port = chrome.runtime.connect({ name: ANALYTICS_PORT });
142
142
  const sessionId = Date.now();
143
143
  const getMetadata = () => ({
@@ -148,15 +148,29 @@ function createFrontendAnalytics() {
148
148
  screen: globalThis.window ? `${globalThis.window.screen.width}x${globalThis.window.screen.height}` : void 0,
149
149
  url: location.href
150
150
  });
151
- const methodForwarder = (fn) => (...args) => port.postMessage({ fn, args: [...args, getMetadata()] });
151
+ const methodForwarder = (fn) => (...args) => {
152
+ if (config?.debug) {
153
+ console.debug(
154
+ `[analytics] Sending ${fn} to background for upload`,
155
+ ...args
156
+ );
157
+ }
158
+ port.postMessage({ fn, args: [...args, getMetadata()] });
159
+ };
152
160
  const analytics = {
153
161
  identify: methodForwarder("identify"),
154
162
  page: methodForwarder("page"),
155
163
  track: methodForwarder("track"),
156
164
  setEnabled: methodForwarder("setEnabled"),
157
165
  autoTrack: (root) => {
166
+ if (config?.debug) {
167
+ console.debug("[analytics] autoTrack() called!");
168
+ }
158
169
  const onClick = (event) => {
159
170
  const element = event.target;
171
+ if (config?.debug) {
172
+ console.debug("[analytics] autoTrack() element clicked", element);
173
+ }
160
174
  if (!element || !INTERACTIVE_TAGS.has(element.tagName) && !INTERACTIVE_ROLES.has(element.getAttribute("role")))
161
175
  return;
162
176
  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 {
package/dist/index.mjs CHANGED
@@ -18,9 +18,10 @@ const index = defineWxtModule({
18
18
  "analytics/index.ts"
19
19
  );
20
20
  const analyticsModuleCode = `
21
- import { createAnalytics } from '@wxt-dev/analytics/client';
21
+ import { createAnalytics } from '@wxt-dev/analytics/client';
22
+ import { useAppConfig } from 'wxt/client';
22
23
 
23
- export const analytics = createAnalytics(useAppConfig().analytics);
24
+ export const analytics = createAnalytics(useAppConfig().analytics);
24
25
  `;
25
26
  addAlias(wxt, "#analytics", analyticsModulePath);
26
27
  wxt.hook("prepare:types", async (_, entries) => {
@@ -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.1",
3
+ "version": "0.2.3",
4
4
  "description": "Add analytics to your web extension",
5
5
  "repository": {
6
6
  "type": "git",