Skip to content

Commit

Permalink
Merge pull request #150 from GoogleChromeLabs/add/query-for-template-…
Browse files Browse the repository at this point in the history
…types-popularity

Implement query to get the usage of different WordPress template types on the home page
  • Loading branch information
felixarntz authored Oct 3, 2024
2 parents b6b6177 + c2ba57d commit c92d0ea
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
73 changes: 73 additions & 0 deletions sql/2024/08/home-page-template-types-popularity.sql
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
1 change: 1 addition & 0 deletions sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ For additional considerations for writing BigQuery queries against HTTP Archive,
### 2024/08

* [Active install counts for Performance Lab plugins (with or without the Performance Lab plugin)](./2024/08/performance-lab-plugins-adoption.sql)
* [Usage of different WordPress template types on the home page](./2024/08/home-page-template-types-popularity.sql)

### 2024/04

Expand Down

0 comments on commit c92d0ea

Please sign in to comment.