Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

New mobile web metric #217

Merged
merged 2 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions custom_metrics/almanac.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,33 @@ return JSON.stringify({

return inputNodes;
})(),
'link_protocols_used': (() => {
const protocols_and_count = {};
const anchors = document.querySelectorAll('a[href]');
for (const anchor of anchors) {
try {
const url = new URL(anchor.href);
rviscomi marked this conversation as resolved.
Show resolved Hide resolved

// Get the protocol and remove the :
const protocol = (url.protocol || '').toLowerCase().slice(0, -1);
if (!protocol) {
continue;
}

// Increase the counter
if (protocols_and_count[protocol]) {
protocols_and_count[protocol]++;
} else {
protocols_and_count[protocol] = 1;
}
} catch (e) {
// Not a valid URL. Skip over it
continue;
}
}

return protocols_and_count;
})(),
// Find first child of <head>
// Whether the first child of <head> is a Google Fonts <link>
'06.47': (() => {
Expand Down
15 changes: 15 additions & 0 deletions custom_metrics/metric-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ Example response:
}
```

## link_protocols_used

Lists all of the different protocols used in `<a href>` elements, along with their frequency

Example response:

```json
{
"https": 2,
"http": 1,
"tel": 1,
"javascript": 1
}
```

## 06.47
Detects if the first child of `<head>` is a Google Fonts `<link>`. `1` if true, `0` if false.

Expand Down