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" "@openpanel/web": "workspace:1.0.1-local"
}, },
"peerDependencies": { "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": "^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" "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()) { if (!this.isServer()) {
console.log('OpenPanel.dev - Initialized', this.options);
this.setGlobalProperties({ this.setGlobalProperties({
__referrer: document.referrer, __referrer: document.referrer,
}); });
@@ -71,14 +73,22 @@ export class OpenPanel extends OpenPanelBase {
if (link && target) { if (link && target) {
const href = link.getAttribute('href'); const href = link.getAttribute('href');
if (href?.startsWith('http')) { if (href?.startsWith('http')) {
super.track('link_out', { try {
href, const linkUrl = new URL(href);
text: const currentHostname = window.location.hostname;
link.innerText || if (linkUrl.hostname !== currentHostname) {
link.getAttribute('title') || super.track('link_out', {
target.getAttribute('alt') || href,
target.getAttribute('title'), 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; this.lastPath = path;
console.log('OpenPanel.dev - Track page view');
super.track('screen_view', { super.track('screen_view', {
...(properties ?? {}), ...(properties ?? {}),
__path: path, __path: path,