Skip to content

Commit

Permalink
Merge pull request #4525 from NomicFoundation/scoped-hardhat-tasks
Browse files Browse the repository at this point in the history
Report ignition deploy to GA
  • Loading branch information
fvictorio authored Oct 24, 2023
2 parents 845f8c5 + bddfcff commit 114171e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-windows-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Send GA hits for `ignition deploy` tasks
23 changes: 20 additions & 3 deletions packages/hardhat-core/src/internal/cli/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,31 @@ export class Analytics {
*
* @returns The abort function
*/
public async sendTaskHit(): Promise<[AbortAnalytics, Promise<void>]> {
public async sendTaskHit(
scopeName: string | undefined,
taskName: string
): Promise<[AbortAnalytics, Promise<void>]> {
if (!this._enabled) {
return [() => {}, Promise.resolve()];
}

return this._sendHit(await this._buildTaskHitPayload());
let eventParams = {};
if (scopeName === "ignition" && taskName === "deploy") {
eventParams = {
scope: scopeName,
task: taskName,
};
}

return this._sendHit(await this._buildTaskHitPayload(eventParams));
}

private async _buildTaskHitPayload(): Promise<AnalyticsPayload> {
private async _buildTaskHitPayload(
eventParams: {
scope?: string;
task?: string;
} = {}
): Promise<AnalyticsPayload> {
return {
client_id: this._clientId,
user_id: this._clientId,
Expand All @@ -119,6 +135,7 @@ export class Analytics {
// for user activity to display in standard reports like Realtime
engagement_time_msec: "10000",
session_id: this._sessionId,
...eventParams,
},
},
],
Expand Down
5 changes: 4 additions & 1 deletion packages/hardhat-core/src/internal/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ async function main() {
Reporter.setEnabled(true);
}

const [abortAnalytics, hitPromise] = await analytics.sendTaskHit();
const [abortAnalytics, hitPromise] = await analytics.sendTaskHit(
scopeName,
taskName
);

let taskArguments: TaskArguments;

Expand Down

0 comments on commit 114171e

Please sign in to comment.