fix: nextjs 16 support and web logging

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-11-10 19:40:36 +01:00
parent 720b56aba6
commit 7e38176422
2 changed files with 20 additions and 9 deletions

View File

@@ -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"
},

View File

@@ -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,