Skip to content

Commit d1389c5

Browse files
d13eamodio
authored andcommitted
Adds tracking when opening the upgrade url is cancelled
1 parent 74ad6ec commit d1389c5

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

docs/telemetry-events.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,16 @@ void
17311731
17321732
```typescript
17331733
{
1734-
'action': 'manage' | 'sign-up' | 'sign-in' | 'sign-out' | 'reactivate' | 'resend-verification' | 'pricing' | 'start-preview-trial' | 'upgrade'
1734+
'action': 'manage' | 'sign-up' | 'sign-in' | 'sign-out' | 'reactivate' | 'resend-verification' | 'pricing' | 'start-preview-trial'
1735+
}
1736+
```
1737+
1738+
or
1739+
1740+
```typescript
1741+
{
1742+
'aborted': boolean,
1743+
'action': 'upgrade'
17351744
}
17361745
```
17371746

src/constants.telemetry.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,11 @@ type SubscriptionActionEventData =
784784
| 'reactivate'
785785
| 'resend-verification'
786786
| 'pricing'
787-
| 'start-preview-trial'
788-
| 'upgrade';
787+
| 'start-preview-trial';
788+
}
789+
| {
790+
action: 'upgrade';
791+
aborted: boolean;
789792
}
790793
| {
791794
action: 'visibility';

src/plus/gk/subscriptionService.ts

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import { getLogScope, setLogScopeExit } from '../../system/logger.scope';
6262
import { flatten } from '../../system/object';
6363
import { pauseOnCancelOrTimeout } from '../../system/promise';
6464
import { pluralize } from '../../system/string';
65+
import { createDisposable } from '../../system/unifiedDisposable';
6566
import { satisfies } from '../../system/version';
6667
import { LoginUriPathPrefix } from './authenticationConnection';
6768
import { authenticationProviderScopes } from './authenticationProvider';
@@ -871,9 +872,22 @@ export class SubscriptionService implements Disposable {
871872

872873
if (!(await ensurePlusFeaturesEnabled())) return;
873874

874-
if (this.container.telemetry.enabled) {
875-
this.container.telemetry.sendEvent('subscription/action', { action: 'upgrade' }, source);
876-
}
875+
let aborted = false;
876+
using telemetry = this.container.telemetry.enabled
877+
? createDisposable(
878+
() => {
879+
this.container.telemetry.sendEvent(
880+
'subscription/action',
881+
{
882+
action: 'upgrade',
883+
aborted: aborted,
884+
},
885+
source,
886+
);
887+
},
888+
{ once: true },
889+
)
890+
: undefined;
877891

878892
if (this._subscription.account != null) {
879893
// Do a pre-check-in to see if we've already upgraded to a paid plan.
@@ -910,27 +924,34 @@ export class SubscriptionService implements Disposable {
910924

911925
try {
912926
if (hasAccount) {
913-
const token = await this.container.accountAuthentication.getExchangeToken(
914-
SubscriptionUpdatedUriPathPrefix,
915-
);
916-
query.set('token', token);
917-
} else {
927+
try {
928+
const token = await this.container.accountAuthentication.getExchangeToken(
929+
SubscriptionUpdatedUriPathPrefix,
930+
);
931+
query.set('token', token);
932+
} catch (ex) {
933+
Logger.error(ex, scope);
934+
}
935+
}
936+
937+
if (!query.has('token')) {
918938
const successUri = await env.asExternalUri(
919939
Uri.parse(`${env.uriScheme}://${this.container.context.extension.id}/${LoginUriPathPrefix}`),
920940
);
921941
query.set('success_uri', successUri.toString(true));
922942
}
923-
924-
if (!(await openUrl(this.container.getGkDevUri('purchase/checkout', query.toString()).toString(true)))) {
925-
return;
926-
}
927943
} catch (ex) {
928944
Logger.error(ex, scope);
929-
if (!(await openUrl(this.container.getGkDevUri('purchase/checkout', query.toString()).toString(true)))) {
930-
return;
931-
}
932945
}
933946

947+
aborted = !(await openUrl(this.container.getGkDevUri('purchase/checkout', query.toString()).toString(true)));
948+
949+
if (aborted) {
950+
return;
951+
}
952+
953+
telemetry?.dispose();
954+
934955
const completionPromises = [new Promise<boolean>(resolve => setTimeout(() => resolve(false), 5 * 60 * 1000))];
935956

936957
if (hasAccount) {

0 commit comments

Comments
 (0)