-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from GoogleChromeLabs/add/query-for-template-…
…types-popularity Implement query to get the usage of different WordPress template types on the home page
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# HTTP Archive query to get the usage of different WordPress template types on the home page. | ||
# | ||
# WPP Research, Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# See https://github.com/GoogleChromeLabs/wpp-research/pull/150 | ||
|
||
DECLARE DATE_TO_QUERY DATE DEFAULT '2024-07-01'; | ||
|
||
CREATE TEMPORARY FUNCTION IS_CMS(technologies ARRAY<STRUCT<technology STRING, categories ARRAY<STRING>, info ARRAY<STRING>>>, cms STRING, version STRING) RETURNS BOOL AS ( | ||
EXISTS( | ||
SELECT * FROM UNNEST(technologies) AS technology, UNNEST(technology.info) AS info | ||
WHERE technology.technology = cms | ||
AND ( | ||
version = "" | ||
OR ENDS_WITH(version, ".x") AND (STARTS_WITH(info, RTRIM(version, "x")) OR info = RTRIM(version, ".x")) | ||
OR info = version | ||
) | ||
) | ||
); | ||
|
||
CREATE TEMPORARY FUNCTION GET_CONTENT_TYPE(custom_metrics STRING) RETURNS STRUCT<template STRING, postType STRING, taxonomy STRING> AS ( | ||
STRUCT( | ||
CAST(JSON_EXTRACT_SCALAR(custom_metrics, "$.cms.wordpress.content_type.template") AS STRING) AS template, | ||
CAST(JSON_EXTRACT_SCALAR(custom_metrics, "$.cms.wordpress.content_type.post_type") AS STRING) AS postType, | ||
CAST(JSON_EXTRACT_SCALAR(custom_metrics, "$.cms.wordpress.content_type.taxonomy") AS STRING) AS taxonomy | ||
) | ||
); | ||
|
||
WITH contentTypes AS ( | ||
SELECT | ||
date, | ||
"WordPress" AS cms, | ||
IF(client = "mobile", "phone", "desktop") AS device, | ||
page AS url, | ||
GET_CONTENT_TYPE(custom_metrics) AS contentType | ||
FROM | ||
`httparchive.all.pages` | ||
WHERE | ||
date = DATE_TO_QUERY | ||
AND IS_CMS(technologies, "WordPress", "") | ||
AND is_root_page = TRUE | ||
) | ||
|
||
SELECT | ||
date, | ||
cms, | ||
device, | ||
contentType.template AS contentTypeSummary, | ||
COUNT(url) AS urls | ||
FROM | ||
contentTypes | ||
GROUP BY | ||
date, | ||
cms, | ||
device, | ||
contentType.template | ||
ORDER BY | ||
date ASC, | ||
cms ASC, | ||
device ASC, | ||
urls DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters