Skip to content

Commit 0a0ea16

Browse files
committed
Adds some analytics to the site
1 parent abdc981 commit 0a0ea16

4 files changed

Lines changed: 64 additions & 45 deletions

File tree

.github/workflows/deploy-prod.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ jobs:
3737
PUBLISH_BRANCH: "SITE-PRODUCTION"
3838
PUBLISH_DIR: ./site
3939

40+
# Update the site stats
41+
- run: node packages/typescriptlang-org/scripts/updateAppInsightsGitHubIssue.js
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_BOT_TOKEN }}
44+
APP_INSIGHTS_API_KEY: ${{ secrets.APP_INSIGHTS_API_KEY }}
45+
APP_INSIGHTS_ID: ${{ secrets.APP_INSIGHTS_ID }}
46+
4047
- name: Send a message to Microsoft Teams
4148
if: ${{ failure() }}
4249
uses: aliencube/[email protected]

.github/workflows/weekly.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/typescriptlang-org/scripts/makeMarkdownForAppInsights.js

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const getJSON = async (query, params) => {
1919
const headers = {
2020
"x-api-key": process.env.APP_INSIGHTS_API_KEY,
2121
}
22+
2223
const queryParams = querystring.stringify(params)
2324
const root = `https://api.applicationinsights.io/v1/apps/${process.env.APP_INSIGHTS_ID}`
2425
const href = `${root}${query}?${queryParams}`
@@ -41,6 +42,9 @@ const makeAToSitePath = path =>
4142
const makeAToPlaygroundSample = path =>
4243
`<a href='https://www.staging-typescript.org/play/#example/${path}'>${path}</a>`
4344

45+
const makeAnchorAsNPMModule = path =>
46+
`<a href='https://www.npmjs.com/package/${path}'>${path}</a>`
47+
4448
const makeMarkdownOfWeeklyAppInsightsInfo = async () => {
4549
const mds = []
4650
// You'll be looking at this stuff and think? Err how do I make these complex queries.
@@ -49,9 +53,10 @@ const makeMarkdownOfWeeklyAppInsightsInfo = async () => {
4953
// "Run last query in logs view" (it's like 9 dots, then a speech bubble above the bar graph)
5054
// Which gives you the exact query for the data you see.
5155

52-
// Start here:
56+
mds.push(
57+
`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).`
58+
)
5359

54-
// https://ms.portal.azure.com/#blade/Microsoft_Azure_Monitoring_Logs/LogsBlade/resourceId/%2Fsubscriptions%2F57bfeeed-c34a-4ffd-a06b-ccff27ac91b8%2FresourceGroups%2Ftypescriptlang-org%2Fproviders%2Fmicrosoft.insights%2Fcomponents%2FTypeScriptLang-Prod-Ai/source/AIExtension.UsageWorkbookViewerBlade/timespan/PT24H/query/let%20mainTable%20%3D%20union%20pageViews%2CcustomEvents%20%20%7C%20where%20timestamp%20%3E%20ago(1d)%20%20%7C%20where%20iif('*'%20in%20(%22Liked%20Page%22)%2C%201%3D%3D1%2C%20name%20in%20(%22Liked%20Page%22))%20%7C%20where%20customDimensions%5B%22slug%22%5D%20startswith%20%22%2F%22%20%3B%20let%20byTable%20%3D%20mainTable%3B%20let%20queryTable%20%3D%20()%20%7BbyTable%20%7C%20extend%20dimension%20%3D%20customDimensions%5B%22slug%22%5D%20%7C%20extend%20dimension%20%3D%20iif(isempty(dimension)%2C%20%22%3Cundefined%3E%22%2C%20dimension)%7D%3B%20let%20byCohortTable%20%3D%20queryTable%20%20%7C%20project%20dimension%2C%20timestamp%3B%20%20let%20topSegments%20%3D%20byCohortTable%20%20%7C%20summarize%20Events%20%3D%20count()%20by%20dimension%20%20%7C%20top%2010%20by%20Events%20%20%20%7C%20summarize%20makelist(dimension)%3B%20%20let%20topEventMetrics%20%3D%20byCohortTable%20%20%7C%20where%20dimension%20in%20(topSegments)%3B%20%20let%20otherEventUsers%20%3D%20byCohortTable%20%20%7C%20where%20dimension%20!in%20(topSegments)%20%20%20%7C%20extend%20dimension%20%3D%20%22Other%22%3B%20%20otherEventUsers%20%20%7C%20union%20topEventMetrics%20%20%7C%20summarize%20Events%20%3D%20count()%20by%20dimension%20%20%20%7C%20order%20by%20dimension%20asc/prettify/1
5560
const likedPages = await makeQuery(
5661
`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), "<undefined>", 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`
5762
)
@@ -61,29 +66,73 @@ const makeMarkdownOfWeeklyAppInsightsInfo = async () => {
6166
mds.push(`###### Liked`)
6267
mds.push(
6368
mostLikedPages
64-
.map(e => "- " + makeAToSitePath(e[0]) + `(${e[1]})`)
69+
.map(e => "- " + makeAToSitePath(e[0]) + ` (${e[1]})`)
6570
.join("\n")
6671
)
6772

6873
const dislikedPagesTable = await makeQuery(
69-
`let mainTable = union pageViews,customEvents | where timestamp > ago(1d) | where iif('*' in ("Disliked 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), "<undefined>", 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`
74+
`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), "<undefined>", 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`
7075
)
7176

7277
const mostdisLikedPages = dislikedPagesTable.tables[0].rows
7378
mds.push(`###### Disliked`)
7479
mds.push(
7580
mostdisLikedPages
76-
.map(e => "- " + makeAToSitePath(e[0]) + `(${e[1]})`)
81+
.map(e => "- " + makeAToSitePath(e[0]) + ` (${e[1]})`)
7782
.join("\n")
7883
)
7984

8085
const usedExamples = await makeQuery(
8186
`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), "<undefined>", 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`
8287
)
83-
const examples = usedExamples.tables[0].rows.sort((a, b) => b[1] - a[1])
88+
const examples = usedExamples.tables[0].rows
89+
.sort((a, b) => b[1] - a[1])
90+
.filter(a => a[0] !== "Other")
91+
8492
mds.push(`#### Playground Examples`)
8593
mds.push(
86-
examples.map(e => makeAToPlaygroundSample(e[0]) + `(${e[1]})`).join(", ")
94+
examples.map(e => makeAToPlaygroundSample(e[0]) + ` (${e[1]})`).join(" - ")
95+
)
96+
97+
const playgroundPluginsTable = await makeQuery(`let mainTable = union customEvents
98+
| where timestamp > ago(7d)
99+
| where iif('*' in ("Added Registry Plugin"), 1==1, name in ("Added Registry Plugin"))
100+
| where true;
101+
let byTable = mainTable;
102+
let queryTable = ()
103+
{
104+
byTable
105+
| extend dimension = customDimensions["id"]
106+
| extend dimension = iif(isempty(dimension), "<undefined>", dimension)
107+
};
108+
let byCohortTable = queryTable
109+
| project dimension, timestamp;
110+
let topSegments = byCohortTable
111+
| summarize Events = count() by dimension
112+
| top 10 by Events
113+
| summarize makelist(dimension);
114+
let topEventMetrics = byCohortTable
115+
| where dimension in (topSegments);
116+
let otherEventUsers = byCohortTable
117+
| where dimension !in (topSegments)
118+
| extend dimension = "Other";
119+
otherEventUsers
120+
| union topEventMetrics
121+
| summarize Events = count() by dimension
122+
| order by dimension asc`)
123+
124+
const plugins = playgroundPluginsTable.tables[0].rows
125+
.sort((a, b) => b[1] - a[1])
126+
.filter(a => a[0] !== "Other")
127+
128+
mds.push(`#### Playground Plugins`)
129+
mds.push(
130+
plugins.map(e => makeAnchorAsNPMModule(e[0]) + ` (${e[1]})`).join("\n - ")
131+
)
132+
133+
const today = new Date()
134+
mds.push(
135+
`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).`
87136
)
88137

89138
return mds.join("\n\n")

packages/typescriptlang-org/scripts/updateAppInsightsGitHubIssue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const go = async () => {
2323

2424
const md = await makeMarkdownOfWeeklyAppInsightsInfo()
2525

26-
await octokit.issues.createComment({
26+
await octokit.issues.update({
2727
owner: "Microsoft",
2828
repo: "TypeScript-Website",
2929
issue_number: 1014,

0 commit comments

Comments
 (0)