blob: 20dbc4aaf981eed95a9193ae46fb32abe2e48fa1 [file]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Functions to setup analytics during extension activatioin
import * as vscode from 'vscode';
import { init } from './init';
import { addEvent } from './lib';
import * as ga4Events from './ga4_events';
import * as vscodeEvents from './vscode_events';
import { migrateMetricDirectory } from './metric_properties';
/**
* Initialize analytics
* This has to be called before any extension initiated calls to any other Fuchsia tools,
* so that the opt-in/out and first-run status can be maintained correctly.
* @param context the vscode.ExtensionContext variable
*/
export async function initAnalytics(context: vscode.ExtensionContext) {
await migrateMetricDirectory();
await init(context);
}
/**
* Hook up event triggers for sending analytics.
*/
export function setUpAnalyticsEvents(context: vscode.ExtensionContext) {
context.subscriptions.push(vscodeEvents.onWillExecuteCommand((event) => {
void /* in bg */ addEvent(
ga4Events.createCommandExecutionEvent(event.command),
);
}));
}