|
| 1 | +CREATE TEMP FUNCTION getLoadingAttr(attributes STRING) RETURNS STRING LANGUAGE js AS ''' |
| 2 | + try { |
| 3 | + const data = JSON.parse(attributes); |
| 4 | + const loadingAttr = data.find(attr => attr["name"] === "loading") |
| 5 | + return loadingAttr.value |
| 6 | + } catch (e) { |
| 7 | + return ""; |
| 8 | + } |
| 9 | +'''; |
| 10 | + |
| 11 | +CREATE TEMP FUNCTION getDecodingAttr(attributes STRING) RETURNS STRING LANGUAGE js AS ''' |
| 12 | + try { |
| 13 | + const data = JSON.parse(attributes); |
| 14 | + const decodingAttr = data.find(attr => attr["name"] === "decoding") |
| 15 | + return decodingAttr.value |
| 16 | + } catch (e) { |
| 17 | + return ""; |
| 18 | + } |
| 19 | +'''; |
| 20 | + |
| 21 | +CREATE TEMP FUNCTION getFetchPriorityAttr(attributes STRING) RETURNS STRING LANGUAGE js AS ''' |
| 22 | + try { |
| 23 | + const data = JSON.parse(attributes); |
| 24 | + const fetchPriorityAttr = data.find(attr => attr["name"] === "fetchpriority") |
| 25 | + return fetchPriorityAttr.value |
| 26 | + } catch (e) { |
| 27 | + return ""; |
| 28 | + } |
| 29 | +'''; |
| 30 | + |
| 31 | +CREATE TEMP FUNCTION getLoadingClasses(attributes STRING) RETURNS STRING LANGUAGE js AS ''' |
| 32 | + try { |
| 33 | + const data = JSON.parse(attributes); |
| 34 | + const classes = data.find(attr => attr["name"] === "class").value |
| 35 | + if (classes.indexOf('lazyload') !== -1) { |
| 36 | + return classes |
| 37 | + } else { |
| 38 | + return "" |
| 39 | + } |
| 40 | + } catch (e) { |
| 41 | + return ""; |
| 42 | + } |
| 43 | +'''; |
| 44 | + |
| 45 | +WITH |
| 46 | +lcp_stats AS ( |
| 47 | + SELECT |
| 48 | + client, |
| 49 | + page AS url, |
| 50 | + JSON_EXTRACT_SCALAR(custom_metrics.performance, '$.lcp_elem_stats.nodeName') AS nodeName, |
| 51 | + JSON_EXTRACT_SCALAR(custom_metrics.performance, '$.lcp_elem_stats.url') AS elementUrl, |
| 52 | + CAST(JSON_EXTRACT_SCALAR(custom_metrics.performance, '$.lcp_elem_stats.size') AS INT64) AS size, |
| 53 | + CAST(JSON_EXTRACT_SCALAR(custom_metrics.performance, '$.lcp_elem_stats.loadTime') AS FLOAT64) AS loadTime, |
| 54 | + CAST(JSON_EXTRACT_SCALAR(custom_metrics.performance, '$.lcp_elem_stats.startTime') AS FLOAT64) AS startTime, |
| 55 | + CAST(JSON_EXTRACT_SCALAR(custom_metrics.performance, '$.lcp_elem_stats.renderTime') AS FLOAT64) AS renderTime, |
| 56 | + JSON_EXTRACT(custom_metrics.performance, '$.lcp_elem_stats.attributes') AS attributes, |
| 57 | + getLoadingAttr(TO_JSON_STRING(custom_metrics.performance.lcp_elem_stats.attributes)) AS loading, |
| 58 | + getDecodingAttr(TO_JSON_STRING(custom_metrics.performance.lcp_elem_stats.attributes)) AS decoding, |
| 59 | + getLoadingClasses(TO_JSON_STRING(custom_metrics.performance.lcp_elem_stats.attributes)) AS classWithLazyload, |
| 60 | + getFetchPriorityAttr(TO_JSON_STRING(custom_metrics.performance.lcp_elem_stats.attributes)) AS fetchPriority |
| 61 | + FROM |
| 62 | + `httparchive.crawl.pages` |
| 63 | + WHERE |
| 64 | + date = '2024-11-01' AND |
| 65 | + is_root_page |
| 66 | +) |
| 67 | + |
| 68 | +SELECT |
| 69 | + client, |
| 70 | + nodeName, |
| 71 | + COUNT(DISTINCT url) AS pages, |
| 72 | + ANY_VALUE(total) AS total, |
| 73 | + COUNT(DISTINCT url) / ANY_VALUE(total) AS pct, |
| 74 | + COUNTIF(elementUrl != '') AS haveImages, |
| 75 | + COUNTIF(elementUrl != '') / COUNT(DISTINCT url) AS pct_haveImages, |
| 76 | + COUNTIF(loading = 'eager') AS native_eagerload, |
| 77 | + COUNTIF(loading = 'lazy') AS native_lazyload, |
| 78 | + COUNTIF(classWithLazyload != '') AS lazyload_class, |
| 79 | + COUNTIF(classWithLazyload != '' OR loading = 'lazy') AS probably_lazyLoaded, |
| 80 | + COUNTIF(classWithLazyload != '' OR loading = 'lazy') / COUNT(DISTINCT url) AS pct_prob_lazyloaded, |
| 81 | + COUNTIF(decoding = 'async') AS async_decoding, |
| 82 | + COUNTIF(decoding = 'sync') AS sync_decoding, |
| 83 | + COUNTIF(decoding = 'auto') AS auto_decoding, |
| 84 | + COUNTIF(fetchPriority = 'low') AS priority_low, |
| 85 | + COUNTIF(fetchPriority = 'high') AS priority_high |
| 86 | +FROM |
| 87 | + lcp_stats |
| 88 | +JOIN ( |
| 89 | + SELECT |
| 90 | + client, |
| 91 | + COUNT(0) AS total |
| 92 | + FROM |
| 93 | + `httparchive.crawl.pages` |
| 94 | + WHERE |
| 95 | + date = '2024-11-01' AND |
| 96 | + is_root_page |
| 97 | + GROUP BY |
| 98 | + client) |
| 99 | +USING |
| 100 | + (client) |
| 101 | +GROUP BY |
| 102 | + client, |
| 103 | + nodeName |
| 104 | +HAVING |
| 105 | + pages > 1000 |
| 106 | +ORDER BY |
| 107 | + pct DESC |
0 commit comments