diff --git a/src/AnalyticsEventReporter.ts b/src/AnalyticsEventReporter.ts index c3e0509..7c30579 100644 --- a/src/AnalyticsEventReporter.ts +++ b/src/AnalyticsEventReporter.ts @@ -47,11 +47,15 @@ export class AnalyticsEventReporter implements AnalyticsEventService { public async report(newPayload?: EventPayload): Promise { if (this.config.debug) { console.log( - '[DEBUG] Merging the following payloads:\n' + - '\nOriginal Payload from call to `with`:\n' + - `\n${this.payload ? JSON.stringify(this.payload) : '{}'}\n` + - '\nNew Payload from call to `report:`\n' + - `\n${newPayload ? JSON.stringify(newPayload) : '{}'}\n` + `[DEBUG] Merging the following payloads: + + Original Payload from call to \`with\`: + + ${this.payload ? JSON.stringify(this.payload) : '{}'} + + New Payload from call to \`report:\` + + ${newPayload ? JSON.stringify(newPayload) : '{}'}` ); } @@ -84,17 +88,18 @@ export class AnalyticsEventReporter implements AnalyticsEventService { const requestUrl = setupRequestUrl(this.config.env, this.config.region); if (this.config.debug) { + const reportMethod = shouldUseBeacon ? 'Beacon' : 'fetch()'; + const sessionTrackingStatus = this.config.sessionTrackingEnabled + ? 'enabled' + : 'disabled'; console.log( - '[DEBUG] The following Payload would be sent to the Yext Events API using ' + - (shouldUseBeacon ? 'Beacon. ' : 'fetch(). ') + - 'Session Tracking is ' + - (this.config.sessionTrackingEnabled ? 'enabled.\n' : 'disabled.\n') + - 'Request URL: ' + - requestUrl + - '\n' + - 'To send the event to the Yext Events API, disable the debug flag in your AnalyticsConfig.\n', + `[DEBUG] The following Payload would be sent to the Yext Events API using ${reportMethod}. + The request url would be ${requestUrl}, with Session Tracking ${sessionTrackingStatus}. + To actually send the event, disable the debug flag in your AnalyticsConfig.`, finalPayload ); + // Return early to prevent the request from being sent when debug mode is on. + return ''; } // If useBeacon returns true, return boolean response of postWithBeacon as string.