diff --git a/.github/workflows/weekly-stats.yml b/.github/workflows/weekly-stats.yml deleted file mode 100644 index bd7cb74fb4e8..000000000000 --- a/.github/workflows/weekly-stats.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Publish Weekly Stats - -on: - schedule: - # https://crontab.guru/#0_12_*_*_1 - - cron: "0 12 * * 1" - workflow_dispatch: - -permissions: - contents: read - comments: write - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 - with: - node-version: "18.x" - - - uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 - - - run: pnpm install - - # Update the site stats - - run: node packages/typescriptlang-org/scripts/updateAppInsightsGitHubIssue.js - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - APP_INSIGHTS_API_KEY: ${{ secrets.APP_INSIGHTS_API_KEY }} - APP_INSIGHTS_ID: ${{ secrets.APP_INSIGHTS_ID }} \ No newline at end of file diff --git a/packages/playground/src/getExample.ts b/packages/playground/src/getExample.ts index aa6e4298d7c6..35cbeade0111 100644 --- a/packages/playground/src/getExample.ts +++ b/packages/playground/src/getExample.ts @@ -25,11 +25,6 @@ export const getExampleSourceCode = async (prefix: string, lang: string, example code = code.split("\n").slice(1).join("\n").trim() } - // @ts-ignore - window.appInsights && - // @ts-ignore - window.appInsights.trackEvent({ name: "Read Playground Example", properties: { id: exampleID, lang } }) - return { example, code, diff --git a/packages/playground/src/index.ts b/packages/playground/src/index.ts index f215698bc607..5c3528041698 100644 --- a/packages/playground/src/index.ts +++ b/packages/playground/src/index.ts @@ -241,8 +241,6 @@ export const setupPlayground = ( // When any compiler flags are changed, trigger a potential change to the URL sandbox.setDidUpdateCompilerSettings(async () => { playgroundDebouncedMainFunction() - // @ts-ignore - window.appInsights && window.appInsights.trackEvent({ name: "Compiler Settings changed" }) const model = sandbox.editor.getModel() const plugin = getCurrentPlugin() diff --git a/packages/playground/src/sidebar/plugins.ts b/packages/playground/src/sidebar/plugins.ts index 905e821e0f42..755feaeeec12 100644 --- a/packages/playground/src/sidebar/plugins.ts +++ b/packages/playground/src/sidebar/plugins.ts @@ -23,10 +23,6 @@ export const addCustomPlugin = (mod: string) => { const newPlugins = customPlugins() newPlugins.push(mod) localStorage.setItem("custom-plugins-playground", JSON.stringify(newPlugins)) - // @ts-ignore - window.appInsights && - // @ts-ignore - window.appInsights.trackEvent({ name: "Added Custom Module", properties: { id: mod } }) } const customPlugins = (): string[] => { @@ -147,10 +143,6 @@ export const optionsPlugin: PluginFactory = (i, utils) => { const ds = utils.createDesignSystem(div) ds.declareRestartRequired(i) if (input.checked) { - // @ts-ignore - window.appInsights && - // @ts-ignore - window.appInsights.trackEvent({ name: "Added Registry Plugin", properties: { id: key } }) localStorage.setItem(key, "true") } else { localStorage.removeItem(key) diff --git a/packages/typescriptlang-org/gatsby-browser.js b/packages/typescriptlang-org/gatsby-browser.js deleted file mode 100644 index 07b6fc8c4b20..000000000000 --- a/packages/typescriptlang-org/gatsby-browser.js +++ /dev/null @@ -1,61 +0,0 @@ -// This hooks ups client-side app analytics -// it's based on how the google analytics plugin works for gatsby -// https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-google-analytics/src/gatsby-browser.js - -exports.onRouteUpdate = ({ location, prevLocation }) => { - // Run both clear and app insights for a bit, then drop app insights - - // prettier-ignore - // ;(function(c,l,a,r,i,t,y){ - // c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; - // t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; - // y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); - // })(window, document, "clarity", "script", "3w5kyel345"); - - var sdkInstance = "appInsightsSDK" - window[sdkInstance] = "appInsights" - const config = { - instrumentationKey: "78a8fb52-a225-4c66-ac08-92fad1c1ade1", - // loggingLevelConsole: 1 - } - - let hasLocalStorage = false - try { - hasLocalStorage = typeof localStorage !== `undefined` - } catch (error) {} - - try { - // prettier-ignore - // @ts-ignore - var aiName = window[sdkInstance], aisdk = window[aiName] || function (e) { function n(e) { t[e] = function () { var n = arguments; t.queue.push(function () { t[e].apply(t, n) }) } } var t = { config: e }; t.initialize = !0; var i = document, a = window; setTimeout(function () { var n = i.createElement("script"); n.async = true; n.src = e.url || "https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js", i.getElementsByTagName("script")[0].parentNode.appendChild(n) }); try { t.cookie = i.cookie } catch (e) { } t.queue = [], t.version = 2; for (var r = ["Event", "PageView", "Exception", "Trace", "DependencyData", "Metric", "PageViewPerformance"]; r.length;)n("track" + r.pop()); n("startTrackPage"), n("stopTrackPage"); var s = "Track" + r[0]; if (n("start" + s), n("stop" + s), n("setAuthenticatedUserContext"), n("clearAuthenticatedUserContext"), n("flush"), !(!0 === e.disableExceptionTracking || e.extensionConfig && e.extensionConfig.ApplicationInsightsAnalytics && !0 === e.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)) { n("_" + (r = "onerror")); var o = a[r]; a[r] = function (e, n, i, a, s) { var c = o && o(e, n, i, a, s); return !0 !== c && t["_" + r]({ message: e, url: n, lineNumber: i, columnNumber: a, error: s }), c }, e.autoExceptionInstrumented = !0 } return t }(config); - window[aiName] = aisdk - - const locationWithoutPlaygroundCode = location.pathname - .split("#code")[0] - .split("#src")[0] - - const prevHref = (prevLocation && prevLocation.pathname) || "" - const previousLocationWithoutPlaygroundCode = prevHref - .split("#code")[0] - .split("#src")[0] - - const referrerWithoutPlaygroundCode = - document.referrer && document.referrer.split("#code")[0].split("#src")[0] - - // @ts-ignore - aisdk.trackPageView({ - uri: locationWithoutPlaygroundCode, - refUri: referrerWithoutPlaygroundCode, - properties: { - uri: locationWithoutPlaygroundCode, - prev: previousLocationWithoutPlaygroundCode, - lang: document.documentElement.lang, - visitedPlayground: - hasLocalStorage && localStorage.getItem("sandbox-history") !== null, - }, - }) - } catch (error) { - console.error("Error with Application Insights") - console.error(error) - } - } \ No newline at end of file diff --git a/packages/typescriptlang-org/scripts/makeMarkdownForAppInsights.js b/packages/typescriptlang-org/scripts/makeMarkdownForAppInsights.js deleted file mode 100644 index 53ca704b20f9..000000000000 --- a/packages/typescriptlang-org/scripts/makeMarkdownForAppInsights.js +++ /dev/null @@ -1,150 +0,0 @@ -// @ts-check - -/* Creates a markdown summary of the last week's worth of analytics, - * run with: - APP_INSIGHTS_ID="X" APP_INSIGHTS_API_KEY="Y" node packages/typescriptlang-org/scripts/makeMarkdownForAppInsights.js - */ - - const querystring = require("querystring") - - const APP_INSIGHTS_ID = process.env.APP_INSIGHTS_ID; - const APP_INSIGHTS_API_KEY = process.env.APP_INSIGHTS_API_KEY; - - // Get these from: https://ms.portal.azure.com/#@microsoft.onmicrosoft.com/resource/subscriptions/57bfeeed-c34a-4ffd-a06b-ccff27ac91b8/resourceGroups/typescriptlang-org/providers/microsoft.insights/components/TypeScriptLang-Prod-Ai/apiKeys - if (!APP_INSIGHTS_ID) - throw new Error("No App Insights ID at process.env.APP_INSIGHTS_ID") - - if (!APP_INSIGHTS_API_KEY) - throw new Error("No App Insights ID at process.env.APP_INSIGHTS_API_KEY") - - const getJSON = async (query, params) => { - const headers = { - "x-api-key": APP_INSIGHTS_API_KEY, - } - - const queryParams = querystring.stringify(params) - const root = `https://api.applicationinsights.io/v1/apps/${APP_INSIGHTS_ID}` - const href = `${root}${query}?${queryParams}` - const response = await fetch(href, { headers }) - - if (!response.ok) { - console.error("Error in API call to app insights") - console.error(response) - } - - const json = await response.json() - return json - } - - const makeQuery = query => getJSON("/query", { query }) - - const makeAToSitePath = path => - `${path}` - - const makeAToPlaygroundSample = path => - `${path}` - - const makeAnchorAsNPMModule = path => - `${path}` - - const toMDList = (rows, anchorFunc) => { - return rows - .sort((a, b) => b[1] - a[1]) - .map(e => "- " + anchorFunc(e[0]) + ` (${e[1]})`) - .join("\n") - } - - const makeMarkdownOfWeeklyAppInsightsInfo = async () => { - // You'll be looking at this stuff and think? Err how do I make these complex queries. - // - // It's actually pretty trivial, you do it all in the portal, then there is a button to get it: - // "Run last query in logs view" (it's like 9 dots, then a speech bubble above the bar graph) - // Which gives you the exact query for the data you see. - - const likedPages = await makeQuery( - `let mainTable = union pageViews,customEvents | where timestamp > ago(1d) | where iif('*' in ("Liked Page"), 1==1, name in ("Liked Page")) | where customDimensions["slug"] startswith "/" ; let byTable = mainTable; let queryTable = () {byTable | extend dimension = customDimensions["slug"] | extend dimension = iif(isempty(dimension), "", dimension)}; let byCohortTable = queryTable | project dimension, timestamp; let topSegments = byCohortTable | summarize Events = count() by dimension | top 10 by Events | summarize makelist(dimension); let topEventMetrics = byCohortTable | where dimension in (topSegments); let otherEventUsers = byCohortTable | where dimension !in (topSegments) | extend dimension = "Other"; otherEventUsers | union topEventMetrics | summarize Events = count() by dimension | order by dimension asc` - ) - - const dislikedPagesTable = await makeQuery( - `let mainTable = union pageViews,customEvents | where timestamp > ago(1d) | where iif('*' in ("Disliked Page"), 1==1, name in ("Disliked Page")) | where customDimensions["slug"] startswith "/" ; let byTable = mainTable; let queryTable = () {byTable | extend dimension = customDimensions["slug"] | extend dimension = iif(isempty(dimension), "", dimension)}; let byCohortTable = queryTable | project dimension, timestamp; let topSegments = byCohortTable | summarize Events = count() by dimension | top 10 by Events | summarize makelist(dimension); let topEventMetrics = byCohortTable | where dimension in (topSegments); let otherEventUsers = byCohortTable | where dimension !in (topSegments) | extend dimension = "Other"; otherEventUsers | union topEventMetrics | summarize Events = count() by dimension | order by dimension asc` - ) - - const usedExamples = await makeQuery( - `let mainTable = union pageViews,customEvents | where timestamp > ago(7d) | where iif('*' in ("Read Playground Example"), 1==1, name in ("Read Playground Example")) | where true; let byTable = mainTable; let queryTable = () {byTable | extend dimension = customDimensions["id"] | extend dimension = iif(isempty(dimension), "", dimension)}; let byCohortTable = queryTable | project dimension, timestamp; let topSegments = byCohortTable | summarize Events = count() by dimension | top 10 by Events | summarize makelist(dimension); let topEventMetrics = byCohortTable | where dimension in (topSegments); let otherEventUsers = byCohortTable | where dimension !in (topSegments) | extend dimension = "Other"; otherEventUsers | union topEventMetrics | summarize Events = count() by dimension | order by dimension asc` - ) - - const playgroundPluginsTable = await makeQuery(`let mainTable = union customEvents - | where timestamp > ago(7d) - | where iif('*' in ("Added Registry Plugin"), 1==1, name in ("Added Registry Plugin")) - | where true; - let byTable = mainTable; - let queryTable = () - { - byTable - | extend dimension = customDimensions["id"] - | extend dimension = iif(isempty(dimension), "", dimension) - }; - let byCohortTable = queryTable - | project dimension, timestamp; - let topSegments = byCohortTable - | summarize Events = count() by dimension - | top 10 by Events - | summarize makelist(dimension); - let topEventMetrics = byCohortTable - | where dimension in (topSegments); - let otherEventUsers = byCohortTable - | where dimension !in (topSegments) - | extend dimension = "Other"; - otherEventUsers - | union topEventMetrics - | summarize Events = count() by dimension - | order by dimension asc`) - - const mds = [] - - mds.push( - `Hello! This is an always updating GitHub Issue which pulls out the last week of interesting eco-system analytics from the TypeScript website and makes it available for everyone. If you have ideas for things you'd like to see in here, feel free to comment. Microsoft staff can find the [PM focused version here](https://dev.azure.com/devdiv/DevDiv/_dashboards/dashboard/bf4dee3f-7c4b-42b0-805b-670de64052e5).` - ) - - const mostLikedPages = likedPages.tables[0].rows - mds.push(`#### Most liked/disliked pages`) - mds.push( - "All documentation pages have :+1: and :-1: next to them asking _'Is this page helpful?'_. This is the aggregate of the last week for the results." - ) - mds.push(`###### Most Helpful`) - mds.push(toMDList(mostLikedPages, makeAToSitePath)) - - const mostdisLikedPages = dislikedPagesTable.tables[0].rows - mds.push(`###### Least Helpful`) - mds.push(toMDList(mostdisLikedPages, makeAToSitePath)) - - const examples = usedExamples.tables[0].rows.filter(a => a[0] !== "Other") - - mds.push(`#### Playground Examples`) - mds.push("What code samples in the playground are getting used?") - mds.push(toMDList(examples, makeAToPlaygroundSample)) - - const plugins = playgroundPluginsTable.tables[0].rows - .sort((a, b) => b[1] - a[1]) - .filter(a => a[0] !== "Other") - - mds.push(`#### Playground Plugins`) - mds.push( - "What Playground Plugins are being used? This only counts folks clicking in the registry in the sidebar" - ) - mds.push(toMDList(plugins, makeAnchorAsNPMModule)) - - const today = new Date() - mds.push( - `This was last updated ${today.getDate()}/${today.getMonth()}/${today.getFullYear()}. Created with [this script](https://github.com/microsoft/TypeScript-website/blob/v2/packages/typescriptlang-org/scripts/makeMarkdownForAppInsights.js).` - ) - - return mds.join("\n\n") - } - - // @ts-ignore - if (!module.parent) { - makeMarkdownOfWeeklyAppInsightsInfo().then(console.log) - } - - module.exports = { makeMarkdownOfWeeklyAppInsightsInfo } diff --git a/packages/typescriptlang-org/scripts/updateAppInsightsGitHubIssue.js b/packages/typescriptlang-org/scripts/updateAppInsightsGitHubIssue.js deleted file mode 100644 index f5df05217c6d..000000000000 --- a/packages/typescriptlang-org/scripts/updateAppInsightsGitHubIssue.js +++ /dev/null @@ -1,34 +0,0 @@ -// @ts-check - -// Uses the App Insights API to grab useful analytics - -// See: https://dev.applicationinsights.io/reference/get-events -// https://ms.portal.azure.com/#@microsoft.onmicrosoft.com/resource/subscriptions/57bfeeed-c34a-4ffd-a06b-ccff27ac91b8/resourceGroups/typescriptlang-org/providers/microsoft.insights/components/TypeScriptLang-Prod-Ai/events -// - -const { - makeMarkdownOfWeeklyAppInsightsInfo, - } = require("./makeMarkdownForAppInsights") - const Octokit = require("@octokit/rest") - - // Get this from OneNote - if (!process.env.GITHUB_TOKEN) - throw new Error("No GitHub Token at process.env.GITHUB_TOKEN") - - const go = async () => { - const octokit = new Octokit({ - auth: process.env.GITHUB_TOKEN, - userAgent: "TS AppInsights Issue Updater", - }) - - const md = await makeMarkdownOfWeeklyAppInsightsInfo() - - await octokit.issues.update({ - owner: "Microsoft", - repo: "TypeScript-Website", - issue_number: 1014, - body: md, - }) - } - - go() \ No newline at end of file diff --git a/packages/typescriptlang-org/src/components/index/AboveTheFold.tsx b/packages/typescriptlang-org/src/components/index/AboveTheFold.tsx index a785a75b13ba..548c1dbafbd1 100644 --- a/packages/typescriptlang-org/src/components/index/AboveTheFold.tsx +++ b/packages/typescriptlang-org/src/components/index/AboveTheFold.tsx @@ -9,13 +9,6 @@ const Row = (props: { children: any, className?: string }) =>
{props.children}
const Col2 = (props: { children: any }) =>
{props.children}
-const event = (name: string, options?: any) => { - // @ts-ignore - window.appInsights && - // @ts-ignore - window.appInsights.trackEvent({ name }, options) -} - const FluidButton = (props: { href?: string, onClick?: any, title: string, subtitle?: string, icon: JSX.Element, className?: string }) => (
@@ -36,7 +29,6 @@ export const AboveTheFold = () => { const onclick = (e) => { setShowCTALinks(true) e.preventDefault() - event("Home Page CTA Started") return false } @@ -76,7 +68,6 @@ export const AboveTheFold = () => { title={i("index_2_cta_play")} subtitle={i("index_2_cta_play_subtitle")} href="/play" - onClick={() => event("Home Page CTA Exited", { link: "playground" })} icon={ @@ -100,7 +91,6 @@ export const AboveTheFold = () => { title={i("index_2_cta_download")} subtitle={i("index_2_cta_download_subtitle")} href="/download" - onClick={() => event("Home Page CTA Exited", { link: "download" })} icon={ diff --git a/packages/typescriptlang-org/src/templates/pages/cheatsheets.tsx b/packages/typescriptlang-org/src/templates/pages/cheatsheets.tsx index f4b45dfaab69..f090ee6ea6bd 100644 --- a/packages/typescriptlang-org/src/templates/pages/cheatsheets.tsx +++ b/packages/typescriptlang-org/src/templates/pages/cheatsheets.tsx @@ -56,7 +56,6 @@ const Index: React.FC = (props) => { title={i("cht_dl_title")} subtitle={i("cht_dl_subtitle")} href="/assets/typescript-cheat-sheets.zip" - onClick={() => event("Downloaded Cheat Sheet Zip", { link: "download" })} icon={ @@ -70,13 +69,6 @@ const Index: React.FC = (props) => { export default (props: Props) => -const event = (name: string, options?: any) => { - // @ts-ignore - window.appInsights && - // @ts-ignore - window.appInsights.trackEvent({ name }, options) -} - const FluidButton = (props: { href?: string, onClick?: any, title: string, subtitle?: string, icon: JSX.Element, className?: string }) => (
diff --git a/packages/typescriptlang-org/src/templates/scripts/setupLikeDislikeButtons.ts b/packages/typescriptlang-org/src/templates/scripts/setupLikeDislikeButtons.ts index d0677590d3f0..1c17f4cbf070 100644 --- a/packages/typescriptlang-org/src/templates/scripts/setupLikeDislikeButtons.ts +++ b/packages/typescriptlang-org/src/templates/scripts/setupLikeDislikeButtons.ts @@ -4,14 +4,6 @@ export const setupLikeDislikeButtons = (slug: string, i: any) => { if (!likeButton || !dislikeButton) return const clicked = (eventName: string) => () => { - // @ts-ignore - window.appInsights && - // @ts-ignore - window.appInsights.trackEvent({ - name: eventName, - properties: { slug: slug, ab: "b" }, - }) - const newContent: string = i("handb_thanks") const textSectionNav = document.getElementById("like-dislike-subnav")!