Skip to content

Commit

Permalink
[CLI] Small analytics update to CLI (#4733)
Browse files Browse the repository at this point in the history
Changes:
- Track `MessageShow` event with `label` attribute for campaign tracking
(like for whisper)
- appended the `version` property to all analytics events to keep track
of CLI versioning
  • Loading branch information
zateutsch authored Jun 4, 2024
1 parent 51c2507 commit 2b86f9e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pwabuilder/cli",
"version": "0.0.17",
"version": "0.0.18",
"description": "",
"main": "dist/index.js",
"files": [
Expand Down
26 changes: 22 additions & 4 deletions apps/cli/src/analytics/usage-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export interface CreateEventData {
template: string
}

export interface MessageShowEventData {
label: string
}

export interface PWABuilderData {
user: {
id: string
Expand Down Expand Up @@ -121,23 +125,37 @@ function spawnAnalyticsProcess(event: string, properties?: any) {
child.unref();
}

function getThisPackageVersion(): string {
return require("../../package.json").version;
}

function appendPackageVersionToEventData(eventData: object): object {
var versionAppendedEventData: object = eventData;
versionAppendedEventData['version'] = getThisPackageVersion();
return versionAppendedEventData;
}

function resolveNodeSpawnArgs(event: string, properties?: any): string [] {
const scriptPath: string = path.resolve(__dirname, 'track-events.js')
return properties ? [scriptPath, event, JSON.stringify(properties)] : [scriptPath, event];
}

export function trackErrorWrapper(_error: Error): void {
spawnAnalyticsProcess('error', {error: _error});
spawnAnalyticsProcess('error', {error: _error, version: getThisPackageVersion()});
}

export function trackCreateEventWrapper(createEventData: CreateEventData): void {
spawnAnalyticsProcess('create', createEventData);
spawnAnalyticsProcess('create', appendPackageVersionToEventData(createEventData));
}

export function trackBuildEventWrapper(): void {
spawnAnalyticsProcess('build');
spawnAnalyticsProcess('build', {version: getThisPackageVersion()});
}

export function trackStartEventWrapper(): void {
spawnAnalyticsProcess('start');
spawnAnalyticsProcess('start', {version: getThisPackageVersion()});
}

export function trackMessageShowEventWrapper(messageShowEventData: MessageShowEventData): void {
spawnAnalyticsProcess('messageShow', appendPackageVersionToEventData(messageShowEventData));
}
5 changes: 3 additions & 2 deletions apps/cli/src/util/campaignUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os from 'os';
import * as fs from 'fs';
import { doesFileExist } from '../util/fileUtil';
import { PWABuilderData, createUserDataAndWrite } from '../analytics/usage-analytics';
import { PWABuilderData, createUserDataAndWrite, trackMessageShowEventWrapper } from '../analytics/usage-analytics';
import { outputMessage } from './util';
import { formatCodeSnippet, formatEmphasis, formatEmphasisStrong } from './textUtil';
import * as prompts from "@clack/prompts";
Expand Down Expand Up @@ -63,7 +63,8 @@ function handleShowCampaign(userData: PWABuilderData, campaign: Campaign) {
outputMessage(campaign.displayText);
campaign.displayed = true;
userDataWithCampaign.campaignMap[campaign.name] = campaign;
rewritePWABuilderDataFile(userDataWithCampaign)
trackMessageShowEventWrapper({label: campaign.name});
rewritePWABuilderDataFile(userDataWithCampaign);
}
}

Expand Down

0 comments on commit 2b86f9e

Please sign in to comment.