Skip to content

Commit

Permalink
Ensure plugin shorthand installs are also logged
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrgicak committed Jan 10, 2025
1 parent 996db94 commit f628f6c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
updateClientInfo,
} from './slice-clients';
import {
logBlueprintStepEvent,
logBlueprintEvents,
logErrorEvent,
logTrackingEvent,
} from '../../tracking';
import { Blueprint, isStepDefinition } from '@wp-playground/blueprints';
import { Blueprint } from '@wp-playground/blueprints';
import { logger } from '@php-wasm/logger';
import { setupPostMessageRelay } from '@php-wasm/web';
import { startPlaygroundWeb } from '@wp-playground/client';
Expand Down Expand Up @@ -97,23 +97,15 @@ export function bootSiteClient(
}
}

logTrackingEvent('load');

let blueprint: Blueprint;
if (isWordPressInstalled) {
blueprint = site.metadata.runtimeConfiguration;
} else {
blueprint = site.metadata.originalBlueprint;
}

if (blueprint.steps) {
for (const step of blueprint.steps) {
if (!isStepDefinition(step)) {
continue;
}
logBlueprintStepEvent(step);
}
}
logTrackingEvent('load');
logBlueprintEvents(blueprint);

let playground: PlaygroundClient;
try {
Expand Down
78 changes: 54 additions & 24 deletions packages/playground/website/src/lib/tracking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StepDefinition } from '@wp-playground/blueprints';
import { Blueprint, isStepDefinition } from '@wp-playground/blueprints';
import { logger } from '@php-wasm/logger';

/**
Expand Down Expand Up @@ -34,29 +34,6 @@ export const logTrackingEvent = (
}
};

/**
* Log Blueprint step events
* @param step The Blueprint step
*/
export const logBlueprintStepEvent = (step: StepDefinition) => {
/**
* Log the names of provided Blueprint's steps.
* Only the names (e.g. "runPhp" or "login") are logged. Step options like
* code, password, URLs are never sent anywhere.
*/
logTrackingEvent('step', { step: step.step });

if (step.step === 'installPlugin' && (step as any).pluginData.slug) {
logTrackingEvent('installPlugin', {
slug: (step as any).pluginData.slug,
});
} else if (step.step === 'installTheme' && (step as any).themeData.slug) {
logTrackingEvent('installTheme', {
slug: (step as any).themeData.slug,
});
}
};

/**
* Log error events
*
Expand All @@ -67,3 +44,56 @@ export const logErrorEvent = (source: string) => {
source,
});
};

/**
* Log Blueprint events
* @param blueprint The Blueprint
*/
export const logBlueprintEvents = (blueprint: Blueprint) => {
/**
* Log the names of provided Blueprint steps.
* Only the names (e.g. "runPhp" or "login") are logged. Step options like
* code, password, URLs are never sent anywhere.
*
* For installPlugin and installTheme, the plugin/theme slug is logged.
*/
if (blueprint.steps) {
for (const step of blueprint.steps) {
if (!isStepDefinition(step)) {
continue;
}
logTrackingEvent('step', { step: step.step });
if (
step.step === 'installPlugin' &&
(step as any).pluginData.slug
) {
logTrackingEvent('installPlugin', {
plugin: (step as any).pluginData.slug,
});
} else if (
step.step === 'installTheme' &&
(step as any).themeData.slug
) {
logTrackingEvent('installTheme', {
theme: (step as any).themeData.slug,
});
}
}
}

/**
* Because the Blueprint isn't compiled, we need to log the plugins
* that are installed using the `plugins` shorthand.
*/
if (blueprint.plugins) {
for (const plugin of blueprint.plugins) {
if (typeof plugin !== 'string') {
continue;
}
logTrackingEvent('step', { step: 'installPlugin' });
logTrackingEvent('installPlugin', {
plugin,
});
}
}
};

0 comments on commit f628f6c

Please sign in to comment.