Skip to content

Commit

Permalink
add basic usage analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlacey committed Nov 18, 2024
1 parent 2300428 commit 188efe2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/AnalyticsConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace CollapseComments
{
public static class AnalyticsConfig
{
public static string TelemetryConnectionString { get; set; } = "";
}
}
42 changes: 40 additions & 2 deletions src/CollapseCommandPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using EnvDTE;
using EnvDTE80;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Task = System.Threading.Tasks.Task;
Expand Down Expand Up @@ -54,9 +57,44 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
runningDocumentTable.Advise(MyRunningDocTableEvents.Instance);

await SponsorRequestHelper.CheckIfNeedToShowAsync();
}

public void Log(string message)
TrackBasicUsageAnalytics();
}

private static void TrackBasicUsageAnalytics()
{
#if !DEBUG
try
{
if (string.IsNullOrWhiteSpace(AnalyticsConfig.TelemetryConnectionString))
{
return;
}

var config = new TelemetryConfiguration
{
ConnectionString = AnalyticsConfig.TelemetryConnectionString,
};

var client = new TelemetryClient(config);

var properties = new Dictionary<string, string>
{
{ "VsixVersion", Vsix.Version },
{ "VsVersion", Microsoft.VisualStudio.Telemetry.TelemetryService.DefaultSession?.GetSharedProperty("VS.Core.ExeVersion") },
};

client.TrackEvent(Vsix.Name, properties);
}
catch (Exception exc)
{
System.Diagnostics.Debug.WriteLine(exc);
OutputPane.Instance.WriteLine("Error tracking usage analytics: " + exc.Message);
}
#endif
}

public void Log(string message)
{
if (this.Options.EnableDetailedLogging)
{
Expand Down
4 changes: 4 additions & 0 deletions src/CollapseComments.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="AnalyticsConfig.cs" />
<Compile Include="BaseOptionModel.cs" />
<Compile Include="Commands\CollapseAllCommand.cs" />
<Compile Include="Commands\DefinitionsPlusCommand.cs" />
Expand Down Expand Up @@ -139,6 +140,9 @@
<PackageReference Include="MessagePack">
<Version>2.5.192</Version>
</PackageReference>
<PackageReference Include="Microsoft.ApplicationInsights">
<Version>2.22.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.IO.Redist">
<Version>6.1.0</Version>
</PackageReference>
Expand Down

0 comments on commit 188efe2

Please sign in to comment.