fix: add sdk logs behind debug flag

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-12-15 10:20:19 +01:00
parent 3d8a3e8997
commit 1f5c648afe
2 changed files with 13 additions and 9 deletions

View File

@@ -68,6 +68,7 @@ export type OpenPanelOptions = {
waitForProfile?: boolean; waitForProfile?: boolean;
filter?: (payload: TrackHandlerPayload) => boolean; filter?: (payload: TrackHandlerPayload) => boolean;
disabled?: boolean; disabled?: boolean;
debug?: boolean;
}; };
export class OpenPanel { export class OpenPanel {
@@ -129,6 +130,7 @@ export class OpenPanel {
} }
async track(name: string, properties?: TrackProperties) { async track(name: string, properties?: TrackProperties) {
this.log('track event', name, properties);
return this.send({ return this.send({
type: 'track', type: 'track',
payload: { payload: {
@@ -143,6 +145,7 @@ export class OpenPanel {
} }
async identify(payload: IdentifyPayload) { async identify(payload: IdentifyPayload) {
this.log('identify user', payload);
if (payload.profileId) { if (payload.profileId) {
this.profileId = payload.profileId; this.profileId = payload.profileId;
this.flush(); this.flush();
@@ -162,12 +165,10 @@ export class OpenPanel {
} }
} }
async alias(payload: AliasPayload) { /**
return this.send({ * @deprecated This method is deprecated and will be removed in a future version.
type: 'alias', */
payload, async alias(payload: AliasPayload) {}
});
}
async increment(payload: IncrementPayload) { async increment(payload: IncrementPayload) {
return this.send({ return this.send({
@@ -224,4 +225,10 @@ export class OpenPanel {
}); });
this.queue = []; this.queue = [];
} }
log(...args: any[]) {
if (this.options.debug) {
console.log('[OpenPanel.dev]', ...args);
}
}
} }

View File

@@ -38,8 +38,6 @@ export class OpenPanel extends OpenPanelBase {
}); });
if (!this.isServer()) { if (!this.isServer()) {
console.log('OpenPanel.dev - Initialized', this.options);
try { try {
const pending = sessionStorage.getItem('openpanel-pending-revenues'); const pending = sessionStorage.getItem('openpanel-pending-revenues');
if (pending) { if (pending) {
@@ -202,7 +200,6 @@ 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,