Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add siteHash and userAgent #27170

Merged
merged 4 commits into from Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/gatsby-telemetry/src/index.ts
Expand Up @@ -84,9 +84,11 @@ export function addSiteMeasurement(event: string, obj): void {
}

export function expressMiddleware(source: string) {
return function (_req: Request, _res: Response, next): void {
return function (req: Request, _res: Response, next): void {
try {
instance.trackActivity(`${source}_ACTIVE`)
instance.trackActivity(`${source}_ACTIVE`, {
userAgent: req.headers[`user-agent`],
})
} catch (e) {
// ignore
}
Expand Down
6 changes: 4 additions & 2 deletions packages/gatsby-telemetry/src/telemetry.ts
Expand Up @@ -73,6 +73,8 @@ export interface ITelemetryTagsPayload {
name?: string
starterName?: string
siteName?: string
siteHash?: string
userAgent?: string
pluginName?: string
exitCode?: number
duration?: number
Expand Down Expand Up @@ -369,7 +371,7 @@ export class AnalyticsTracker {
return osInfo
}

trackActivity(source: string): void {
trackActivity(source: string, tags: ITelemetryTagsPayload = {}): void {
if (!this.isTrackingEnabled()) {
return
}
Expand All @@ -379,7 +381,7 @@ export class AnalyticsTracker {
const debounceTime = 5 * 1000 // 5 sec

if (now - last > debounceTime) {
this.captureEvent(source)
this.captureEvent(source, tags)
}
this.debouncer[source] = now
}
Expand Down