blob: c07d87006fd30f3a34b95d12a81d840fd22823ce [file] [log] [blame] [edit]
// 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 ga4_events from './ga4_events';
import * as vscode_events 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(vscode_events.onWillExecuteCommand((event) => {
void /* in bg */ addEvent(
ga4_events.createCommandExecutionEvent(event.command)
);
}));
}