| // 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. |
| |
| import * as vscode from 'vscode'; |
| import { Ffx } from '../ffx'; |
| import { Analytics } from './lib'; |
| import { migrateMetricDirectory } from './metric_properties'; |
| |
| /** |
| * Initialize analytics |
| * @param context the vscode.ExtensionContext variable |
| */ |
| export async function initAnalytics(context: vscode.ExtensionContext) { |
| await migrateMetricDirectory(); |
| const analytics = Analytics.instance; |
| analytics.setExtensionInfo(context); |
| await analytics.init(); |
| } |
| |
| /** |
| * Hook up event triggers for sending analytics |
| * @param ffx the Ffx variable |
| */ |
| export function setUpAnalyticsEvents(ffx: Ffx) { |
| const analytics = Analytics.instance; |
| |
| analytics.registerDisposable(ffx.onFfxInvocation((event) => { |
| void /* in bg */ analytics.addEvent({ category: 'ffx-invocation', action: 'not-reported' }); |
| })); |
| } |
| |
| /** |
| * Dispose resources used by analytics. |
| */ |
| export function disposeAnalytics() { |
| const analytics = Analytics.instance; |
| analytics.disposeAll(); |
| } |