@posthog/next 0.4.49 → 0.4.51

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.
@@ -1 +1 @@
1
- {"version":3,"file":"PostHogPageView.d.ts","sourceRoot":"","sources":["../../src/client/PostHogPageView.tsx"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,eAAe,4CAM9B"}
1
+ {"version":3,"file":"PostHogPageView.d.ts","sourceRoot":"","sources":["../../src/client/PostHogPageView.tsx"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,eAAe,4CAM9B"}
@@ -3,6 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { Suspense, useEffect } from 'react';
4
4
  import { usePathname, useSearchParams } from 'next/navigation.js';
5
5
  import { usePostHog } from '@posthog/react';
6
+ import { getCurrentUrl } from '../shared/browser.js';
6
7
  /**
7
8
  * Tracks pageviews on route change in Next.js App Router.
8
9
  *
@@ -39,15 +40,12 @@ function PageViewTracker() {
39
40
  const searchParams = useSearchParams();
40
41
  const posthog = usePostHog();
41
42
  useEffect(() => {
42
- if (!posthog) {
43
- return;
44
- }
45
- let url = pathname;
46
43
  const search = searchParams.toString();
47
- if (search) {
48
- url = `${pathname}?${search}`;
44
+ const currentUrl = getCurrentUrl(search ? `${pathname}?${search}` : pathname);
45
+ if (!posthog || !currentUrl) {
46
+ return;
49
47
  }
50
- posthog.capture('$pageview', { $current_url: url });
48
+ posthog.capture('$pageview', { $current_url: currentUrl });
51
49
  }, [pathname, searchParams, posthog]);
52
50
  return null;
53
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PostHogPageView.js","sourceRoot":"","sources":["../../src/client/PostHogPageView.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAC3C,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,sBAAsB,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,eAAe,GAAG;IAC9B,OAAO,CACH,KAAC,QAAQ,IAAC,QAAQ,EAAE,IAAI,YACpB,KAAC,eAAe,KAAG,GACZ,CACd,CAAA;AAAA,CACJ;AAED,SAAS,eAAe,GAAG;IACvB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAC9B,MAAM,YAAY,GAAG,eAAe,EAAE,CAAA;IACtC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;IAE5B,SAAS,CAAC,GAAG,EAAE,CAAC;QACZ,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAA;QACtC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;QAC7E,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;YAC1B,OAAM;QACV,CAAC;QAED,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,CAAA;IAAA,CAC7D,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;IAErC,OAAO,IAAI,CAAA;AAAA,CACd"}
@@ -1 +1 @@
1
- {"version":3,"file":"PostHogPageView.d.ts","sourceRoot":"","sources":["../../src/pages/PostHogPageView.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,SAa9B"}
1
+ {"version":3,"file":"PostHogPageView.d.ts","sourceRoot":"","sources":["../../src/pages/PostHogPageView.tsx"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,SAc9B"}
@@ -1,6 +1,7 @@
1
1
  import { useEffect } from 'react';
2
2
  import { useRouter } from 'next/router.js';
3
3
  import { usePostHog } from '@posthog/react';
4
+ import { getCurrentUrl } from '../shared/browser.js';
4
5
  /**
5
6
  * Tracks pageviews on route change in Next.js Pages Router.
6
7
  *
@@ -28,10 +29,11 @@ export function PostHogPageView() {
28
29
  const router = useRouter();
29
30
  const posthog = usePostHog();
30
31
  useEffect(() => {
31
- if (!posthog || !router.isReady) {
32
+ const currentUrl = getCurrentUrl(router.asPath);
33
+ if (!posthog || !router.isReady || !currentUrl) {
32
34
  return;
33
35
  }
34
- posthog.capture('$pageview', { $current_url: router.asPath });
36
+ posthog.capture('$pageview', { $current_url: currentUrl });
35
37
  }, [router.asPath, router.isReady, posthog]);
36
38
  return null;
37
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PostHogPageView.js","sourceRoot":"","sources":["../../src/pages/PostHogPageView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,eAAe,GAAG;IAC9B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;IAE5B,SAAS,CAAC,GAAG,EAAE,CAAC;QACZ,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC9B,OAAM;QACV,CAAC;QAED,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;IAAA,CAChE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAE5C,OAAO,IAAI,CAAA;AAAA,CACd"}
1
+ {"version":3,"file":"PostHogPageView.js","sourceRoot":"","sources":["../../src/pages/PostHogPageView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,eAAe,GAAG;IAC9B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;IAE5B,SAAS,CAAC,GAAG,EAAE,CAAC;QACZ,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC/C,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;YAC7C,OAAM;QACV,CAAC;QAED,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,CAAA;IAAA,CAC7D,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAE5C,OAAO,IAAI,CAAA;AAAA,CACd"}
@@ -0,0 +1,2 @@
1
+ export declare function getCurrentUrl(path: string): string | undefined;
2
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/shared/browser.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAM9D"}
@@ -0,0 +1,7 @@
1
+ export function getCurrentUrl(path) {
2
+ if (typeof window === 'undefined') {
3
+ return undefined;
4
+ }
5
+ return `${window.location.origin}${path}`;
6
+ }
7
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/shared/browser.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAAC,IAAY,EAAsB;IAC5D,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,SAAS,CAAA;IACpB,CAAC;IAED,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,EAAE,CAAA;AAAA,CAC5C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/next",
3
- "version": "0.4.49",
3
+ "version": "0.4.51",
4
4
  "description": "PostHog integration for Next.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,7 +38,7 @@
38
38
  "worker": "./dist/pages.edge.js",
39
39
  "browser": "./dist/pages.client.js",
40
40
  "react-server": "./dist/pages.js",
41
- "default": "./dist/pages.js"
41
+ "default": "./dist/pages.client.js"
42
42
  }
43
43
  },
44
44
  "main": "./dist/index.client.js",
@@ -51,9 +51,9 @@
51
51
  "dependencies": {
52
52
  "server-only": "^0.0.1",
53
53
  "@posthog/core": "1.29.1",
54
- "@posthog/react": "1.9.0",
54
+ "posthog-js": "1.373.4",
55
55
  "posthog-node": "5.34.1",
56
- "posthog-js": "1.373.4"
56
+ "@posthog/react": "1.9.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@testing-library/jest-dom": "^6.6.3",
@@ -3,6 +3,7 @@
3
3
  import { Suspense, useEffect } from 'react'
4
4
  import { usePathname, useSearchParams } from 'next/navigation.js'
5
5
  import { usePostHog } from '@posthog/react'
6
+ import { getCurrentUrl } from '../shared/browser.js'
6
7
 
7
8
  /**
8
9
  * Tracks pageviews on route change in Next.js App Router.
@@ -46,17 +47,13 @@ function PageViewTracker() {
46
47
  const posthog = usePostHog()
47
48
 
48
49
  useEffect(() => {
49
- if (!posthog) {
50
- return
51
- }
52
-
53
- let url = pathname
54
50
  const search = searchParams.toString()
55
- if (search) {
56
- url = `${pathname}?${search}`
51
+ const currentUrl = getCurrentUrl(search ? `${pathname}?${search}` : pathname)
52
+ if (!posthog || !currentUrl) {
53
+ return
57
54
  }
58
55
 
59
- posthog.capture('$pageview', { $current_url: url })
56
+ posthog.capture('$pageview', { $current_url: currentUrl })
60
57
  }, [pathname, searchParams, posthog])
61
58
 
62
59
  return null
@@ -1,6 +1,7 @@
1
1
  import { useEffect } from 'react'
2
2
  import { useRouter } from 'next/router.js'
3
3
  import { usePostHog } from '@posthog/react'
4
+ import { getCurrentUrl } from '../shared/browser.js'
4
5
 
5
6
  /**
6
7
  * Tracks pageviews on route change in Next.js Pages Router.
@@ -30,11 +31,12 @@ export function PostHogPageView() {
30
31
  const posthog = usePostHog()
31
32
 
32
33
  useEffect(() => {
33
- if (!posthog || !router.isReady) {
34
+ const currentUrl = getCurrentUrl(router.asPath)
35
+ if (!posthog || !router.isReady || !currentUrl) {
34
36
  return
35
37
  }
36
38
 
37
- posthog.capture('$pageview', { $current_url: router.asPath })
39
+ posthog.capture('$pageview', { $current_url: currentUrl })
38
40
  }, [router.asPath, router.isReady, posthog])
39
41
 
40
42
  return null
@@ -0,0 +1,7 @@
1
+ export function getCurrentUrl(path: string): string | undefined {
2
+ if (typeof window === 'undefined') {
3
+ return undefined
4
+ }
5
+
6
+ return `${window.location.origin}${path}`
7
+ }