From 7e381764223aaf5e1d76c101f49fdd2efa26a879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Mon, 10 Nov 2025 19:40:36 +0100 Subject: [PATCH] fix: nextjs 16 support and web logging --- packages/sdks/nextjs/package.json | 2 +- packages/sdks/web/src/index.ts | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/sdks/nextjs/package.json b/packages/sdks/nextjs/package.json index 48e4c3bd..3f399098 100644 --- a/packages/sdks/nextjs/package.json +++ b/packages/sdks/nextjs/package.json @@ -10,7 +10,7 @@ "@openpanel/web": "workspace:1.0.1-local" }, "peerDependencies": { - "next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0", + "next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0", "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" }, diff --git a/packages/sdks/web/src/index.ts b/packages/sdks/web/src/index.ts index 759398af..911b3833 100644 --- a/packages/sdks/web/src/index.ts +++ b/packages/sdks/web/src/index.ts @@ -32,6 +32,8 @@ export class OpenPanel extends OpenPanelBase { }); if (!this.isServer()) { + console.log('OpenPanel.dev - Initialized', this.options); + this.setGlobalProperties({ __referrer: document.referrer, }); @@ -71,14 +73,22 @@ export class OpenPanel extends OpenPanelBase { if (link && target) { const href = link.getAttribute('href'); if (href?.startsWith('http')) { - super.track('link_out', { - href, - text: - link.innerText || - link.getAttribute('title') || - target.getAttribute('alt') || - target.getAttribute('title'), - }); + try { + const linkUrl = new URL(href); + const currentHostname = window.location.hostname; + if (linkUrl.hostname !== currentHostname) { + super.track('link_out', { + href, + text: + link.innerText || + link.getAttribute('title') || + target.getAttribute('alt') || + target.getAttribute('title'), + }); + } + } catch { + // Invalid URL, skip tracking + } } } }); @@ -174,6 +184,7 @@ export class OpenPanel extends OpenPanelBase { } this.lastPath = path; + console.log('OpenPanel.dev - Track page view'); super.track('screen_view', { ...(properties ?? {}), __path: path,