@dcl/hooks 0.2.2 → 0.2.3-20251202134711.commit-88fc4d5

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/README.md CHANGED
@@ -179,14 +179,17 @@ function MyComponent() {
179
179
 
180
180
  #### Using the usePageTracking Hook
181
181
 
182
- The `usePageTracking` hook automatically tracks page views based on route changes:
182
+ The `usePageTracking` hook tracks page views when the pathname changes. You need to pass the current pathname as a parameter:
183
183
 
184
184
  ```typescript
185
185
  import { usePageTracking } from '@dcl/hooks'
186
186
 
187
187
  function MyPage() {
188
- // Automatically tracks page view when route changes
189
- usePageTracking()
188
+ // Get pathname from your router or window.location
189
+ const pathname = typeof window !== 'undefined' ? window.location.pathname : '/'
190
+
191
+ // Tracks page view when pathname changes
192
+ usePageTracking(pathname)
190
193
 
191
194
  return (
192
195
  <div>
@@ -197,6 +200,20 @@ function MyPage() {
197
200
  }
198
201
  ```
199
202
 
203
+ If you're using a router library, you can get the pathname from it:
204
+
205
+ ```typescript
206
+ import { usePageTracking } from '@dcl/hooks'
207
+ import { useLocation } from 'react-router-dom' // React Router example
208
+
209
+ function MyPage() {
210
+ const location = useLocation()
211
+ usePageTracking(location.pathname)
212
+
213
+ return <div>My Page</div>
214
+ }
215
+ ```
216
+
200
217
  If you need to track additional page properties, you can use the `useAnalytics` hook directly:
201
218
 
202
219
  ```typescript
@@ -232,8 +249,11 @@ Here's a complete example showing how to use all analytics features together:
232
249
  import { AnalyticsProvider, useAnalytics, usePageTracking } from '@dcl/hooks'
233
250
 
234
251
  function MyPage() {
252
+ // Get pathname from your router or window.location
253
+ const pathname = typeof window !== 'undefined' ? window.location.pathname : '/'
254
+
235
255
  // Track page views
236
- usePageTracking()
256
+ usePageTracking(pathname)
237
257
 
238
258
  return (
239
259
  <div>
@@ -347,14 +367,17 @@ function MyComponent() {
347
367
 
348
368
  #### Using the usePageTracking Hook
349
369
 
350
- The `usePageTracking` hook automatically tracks page views based on route changes:
370
+ The `usePageTracking` hook tracks page views when the pathname changes. You need to pass the current pathname as a parameter:
351
371
 
352
372
  ```typescript
353
373
  import { usePageTracking } from '@dcl/hooks'
354
374
 
355
375
  function MyPage() {
356
- // Automatically tracks page view when route changes
357
- usePageTracking()
376
+ // Get pathname from your router or window.location
377
+ const pathname = typeof window !== 'undefined' ? window.location.pathname : '/'
378
+
379
+ // Tracks page view when pathname changes
380
+ usePageTracking(pathname)
358
381
 
359
382
  return (
360
383
  <div>
@@ -365,6 +388,20 @@ function MyPage() {
365
388
  }
366
389
  ```
367
390
 
391
+ If you're using a router library, you can get the pathname from it:
392
+
393
+ ```typescript
394
+ import { usePageTracking } from '@dcl/hooks'
395
+ import { useLocation } from 'react-router-dom' // React Router example
396
+
397
+ function MyPage() {
398
+ const location = useLocation()
399
+ usePageTracking(location.pathname)
400
+
401
+ return <div>My Page</div>
402
+ }
403
+ ```
404
+
368
405
  If you need to track additional page properties, you can use the `useAnalytics` hook directly:
369
406
 
370
407
  ```typescript
@@ -400,8 +437,11 @@ Here's a complete example showing how to use all analytics features together:
400
437
  import { AnalyticsProvider, useAnalytics, usePageTracking } from '@dcl/hooks'
401
438
 
402
439
  function MyPage() {
440
+ // Get pathname from your router or window.location
441
+ const pathname = typeof window !== 'undefined' ? window.location.pathname : '/'
442
+
403
443
  // Track page views
404
- usePageTracking()
444
+ usePageTracking(pathname)
405
445
 
406
446
  return (
407
447
  <div>
@@ -1,2 +1,2 @@
1
- declare const usePageTracking: () => void;
1
+ declare const usePageTracking: (path: string) => void;
2
2
  export { usePageTracking };
@@ -2,14 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.usePageTracking = void 0;
4
4
  const react_1 = require("react");
5
- const react_router_1 = require("react-router");
6
5
  const useAnalytics_1 = require("./useAnalytics");
7
- const usePageTracking = () => {
8
- const location = (0, react_router_1.useLocation)();
6
+ const usePageTracking = (path) => {
9
7
  const { page } = (0, useAnalytics_1.useAnalytics)();
10
8
  (0, react_1.useEffect)(() => {
11
- page(location.pathname);
12
- }, [location, page]);
9
+ page(path);
10
+ }, [page]);
13
11
  };
14
12
  exports.usePageTracking = usePageTracking;
15
13
  //# sourceMappingURL=usePageTracking.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePageTracking.js","sourceRoot":"","sources":["../../src/hooks/usePageTracking.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,+CAA0C;AAC1C,iDAA6C;AAE7C,MAAM,eAAe,GAAG,GAAG,EAAE;IAC3B,MAAM,QAAQ,GAAG,IAAA,0BAAW,GAAE,CAAA;IAC9B,MAAM,EAAE,IAAI,EAAE,GAAG,IAAA,2BAAY,GAAE,CAAA;IAE/B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACzB,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;AACtB,CAAC,CAAA;AAEQ,0CAAe"}
1
+ {"version":3,"file":"usePageTracking.js","sourceRoot":"","sources":["../../src/hooks/usePageTracking.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,iDAA6C;AAE7C,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,EAAE;IACvC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAA,2BAAY,GAAE,CAAA;IAE/B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,IAAI,CAAC,CAAA;IACZ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;AACZ,CAAC,CAAA;AAEQ,0CAAe"}
@@ -1,2 +1,2 @@
1
- declare const usePageTracking: () => void;
1
+ declare const usePageTracking: (path: string) => void;
2
2
  export { usePageTracking };
@@ -1,12 +1,10 @@
1
1
  import { useEffect } from "react";
2
- import { useLocation } from "react-router";
3
2
  import { useAnalytics } from "./useAnalytics";
4
- const usePageTracking = () => {
5
- const location = useLocation();
3
+ const usePageTracking = (path) => {
6
4
  const { page } = useAnalytics();
7
5
  useEffect(() => {
8
- page(location.pathname);
9
- }, [location, page]);
6
+ page(path);
7
+ }, [page]);
10
8
  };
11
9
  export { usePageTracking };
12
10
  //# sourceMappingURL=usePageTracking.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePageTracking.js","sourceRoot":"","sources":["../../src/hooks/usePageTracking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,MAAM,eAAe,GAAG,GAAG,EAAE;IAC3B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAC9B,MAAM,EAAE,IAAI,EAAE,GAAG,YAAY,EAAE,CAAA;IAE/B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACzB,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;AACtB,CAAC,CAAA;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
1
+ {"version":3,"file":"usePageTracking.js","sourceRoot":"","sources":["../../src/hooks/usePageTracking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,EAAE;IACvC,MAAM,EAAE,IAAI,EAAE,GAAG,YAAY,EAAE,CAAA;IAE/B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,IAAI,CAAC,CAAA;IACZ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;AACZ,CAAC,CAAA;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcl/hooks",
3
- "version": "0.2.2",
3
+ "version": "0.2.3-20251202134711.commit-88fc4d5",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "exports": {
@@ -57,7 +57,6 @@
57
57
  "@segment/analytics-next": "^1.79.0",
58
58
  "@sentry/browser": "^9.0.0",
59
59
  "isbot": "^5.1.25",
60
- "react-router": "^7.4.0",
61
60
  "ua-parser-js": "^2.0.2"
62
61
  },
63
62
  "keywords": [
@@ -84,5 +83,5 @@
84
83
  "<rootDir>/test/setup.ts"
85
84
  ]
86
85
  },
87
- "commit": "7882ecd8723c2aea5f7a684cdb3884f932ad67c9"
86
+ "commit": "88fc4d5bf161aa72f229fda449eb6eeb79c704b3"
88
87
  }