Skip to content

Commit

Permalink
Use teplate literals
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Jaffee committed Feb 14, 2024
1 parent 08be2cd commit ef2b390
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/AnalyticsEventReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ export class AnalyticsEventReporter implements AnalyticsEventService {
public async report(newPayload?: EventPayload): Promise<string> {
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) : '{}'}`
);
}

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ef2b390

Please sign in to comment.