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 all 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
8 changes: 5 additions & 3 deletions packages/gatsby-telemetry/src/index.ts
Expand Up @@ -38,7 +38,7 @@ export function trackCli(
tags?: ITelemetryTagsPayload,
opts?: ITelemetryOptsPayload
): void {
instance.captureEvent(input, tags, opts)
instance.trackCli(input, tags, opts)
}

export function captureEvent(
Expand Down Expand Up @@ -92,9 +92,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
23 changes: 20 additions & 3 deletions packages/gatsby-telemetry/src/telemetry.ts
@@ -1,6 +1,6 @@
import uuidv4 from "uuid/v4"
import os from "os"
import { isCI, getCIName } from "gatsby-core-utils"
import { isCI, getCIName, createContentDigest } from "gatsby-core-utils"
import {
getRepositoryId as _getRepositoryId,
IRepositoryId,
Expand Down 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 @@ -118,6 +120,7 @@ export class AnalyticsTracker {
repositoryId?: IRepositoryId
features = new Set<string>()
machineId: string
siteHash?: string = createContentDigest(process.cwd())
jamo marked this conversation as resolved.
Show resolved Hide resolved

constructor({
componentId,
Expand Down Expand Up @@ -202,6 +205,20 @@ export class AnalyticsTracker {
return `-0.0.0`
}

trackCli(
type: string | Array<string> = ``,
tags: ITelemetryTagsPayload = {},
opts: ITelemetryOptsPayload = { debounce: false }
): void {
if (!this.isTrackingEnabled()) {
return
}
if (typeof tags.siteHash === `undefined`) {
tags.siteHash = this.siteHash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, a place in the wild where ??= is going to be useful when it lands!

}
this.captureEvent(type, tags, opts)
}

captureEvent(
type: string | Array<string> = ``,
tags: ITelemetryTagsPayload = {},
Expand Down Expand Up @@ -369,7 +386,7 @@ export class AnalyticsTracker {
return osInfo
}

trackActivity(source: string): void {
trackActivity(source: string, tags: ITelemetryTagsPayload = {}): void {
if (!this.isTrackingEnabled()) {
return
}
Expand All @@ -379,7 +396,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
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -20725,7 +20725,7 @@ remark-mdx@1.6.16:
remark-parse "8.0.3"
unified "9.1.0"

remark-mdx@^1.6.18, remark-mdx@^1.6.6:
remark-mdx@^1.6.18:
version "1.6.18"
resolved "https://registry.yarnpkg.com/remark-mdx/-/remark-mdx-1.6.18.tgz#d8c76017c95824cc7fb853bb2759add8ba0cf319"
integrity sha512-xNhjv4kJZ8L6RV68yK8fQ6XWlvSIFOE5VPmM7wMKSwkvwBu6tlUJy0gRF2WiZ4fPPOj6jpqlVB9QakipvZuEqg==
Expand Down