Skip to content

Commit

Permalink
fix(console): segment offline crash (#3604)
Browse files Browse the repository at this point in the history
take 2

resolves: #3598

## Checklist

- [ ] Title matches [Winglang's style
guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end
testing

*By submitting this pull request, I confirm that my contribution is made
under the terms of the [Wing Cloud Contribution
License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
ainvoner authored Jul 26, 2023
1 parent 2b5df31 commit cdf5aa4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions apps/wing-console/console/app/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ export interface Analytics {
}

export const createAnalytics = (options: CreateAnalyticsOptions): Analytics => {
const segment = new Segment(options.segmentWriteKey);
let segment: Segment;
const sessionId = Date.now();
try {
segment = new Segment(options.segmentWriteKey);
} catch {}
return {
track(event: string, properties?: Record<string, any>) {
if (!segment) {
return;
}
try {
segment.track({
anonymousId: options.anonymousId,
Expand All @@ -25,9 +31,7 @@ export const createAnalytics = (options: CreateAnalyticsOptions): Analytics => {
},
},
});
} catch (error) {
console.debug("failed to send analytics", error);
}
} catch {}
},
};
};

0 comments on commit cdf5aa4

Please sign in to comment.