Skip to content

Commit

Permalink
Merge pull request #97 from pwa-builder/4496-update-analytics-for-app…
Browse files Browse the repository at this point in the history
…-capabilities

#4496: Add analytics for new app cap additions and fix typo
  • Loading branch information
zateutsch authored Dec 12, 2023
2 parents e7e8a52 + 195552b commit b8aad89
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { checkParams } from '../utils/checkParams.js';
import { getManifestByLink } from '../utils/getManifestByLink.js';
import {
analyzeServiceWorker,
AnalyzeServiceWorkerResponce,
AnalyzeServiceWorkerResponse,
} from '../utils/analyzeServiceWorker.js';
import { AnalyticsInfo, uploadToAppInsights } from '../utils/analytics.js';
import { Report } from './type.js';

import { dirname, join } from 'path';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import childProcess, { ChildProcess, exec, spawn } from 'child_process';
import { ChildProcess, exec, spawn } from 'child_process';

const __dirname = dirname(fileURLToPath(import.meta.url));
// const _root = `${__dirname}/../..`;
Expand Down Expand Up @@ -175,7 +175,7 @@ const audit = async (
url?: string;
};
} = {};
let swFeatures: AnalyzeServiceWorkerResponce | null = null;
let swFeatures: AnalyzeServiceWorkerResponse | null = null;

const processServiceWorker = async () => {
if (audits['service-worker-audit']?.details?.scriptUrl ) {
Expand Down
14 changes: 14 additions & 0 deletions utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ export async function uploadToAppInsights(
(_manifest['icons'] != undefined &&
(await validateSingleField('icons', _manifest['icons'])).valid) ||
false;
analyticsInfo.properties.hasEdgeSidePanel =
(_manifest['edge_side_panel'] != undefined &&
(await validateSingleField('edge_side_panel', _manifest['edge_side_panel'])).valid) ||
false;
analyticsInfo.properties.hasDisplayOverride =
(_manifest['display_override'] != undefined &&
(await validateSingleField('display_override', _manifest['display_override'])).valid) ||
false;
analyticsInfo.properties.hasHandleLinks =
(_manifest['handle_links'] != undefined &&
(await validateSingleField('handle_links', _manifest['handle_links'])).valid) ||
false;
}
else {
analyticsInfo.properties.hasManifest = false;
Expand All @@ -206,6 +218,8 @@ export async function uploadToAppInsights(
_features.detectedSignsOfLogic;
analyticsInfo.properties.hasEmptyLogic =
_features.detectedEmpty;
analyticsInfo.properties.hasPushRegistration =
_features.detectedPushRegistration;
}
}

Expand Down
4 changes: 2 additions & 2 deletions utils/analyzeServiceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function findAndFetchImportScripts(code: string, origin?: string): Promise
return contents;
}

export type AnalyzeServiceWorkerResponce = {
export type AnalyzeServiceWorkerResponse = {
detectedBackgroundSync?: boolean,
detectedPeriodicBackgroundSync?: boolean,
detectedPushRegistration?: boolean,
Expand All @@ -96,7 +96,7 @@ export type AnalyzeServiceWorkerResponce = {
error?: string
}

export async function analyzeServiceWorker(serviceWorkerUrl?: string, serviceWorkerContent?: string): Promise<AnalyzeServiceWorkerResponce> {
export async function analyzeServiceWorker(serviceWorkerUrl?: string, serviceWorkerContent?: string): Promise<AnalyzeServiceWorkerResponse> {
let content = serviceWorkerContent;
const separateContent: string[] = [];
if (serviceWorkerUrl) {
Expand Down

0 comments on commit b8aad89

Please sign in to comment.