Skip to content

Instantly share code, notes, and snippets.

@kevinsimper
Created June 30, 2023 09:15
Show Gist options
  • Save kevinsimper/c9e9c608ac5ce81b628181a7f201cf9e to your computer and use it in GitHub Desktop.
Save kevinsimper/c9e9c608ac5ce81b628181a7f201cf9e to your computer and use it in GitHub Desktop.
Normalized URL in bigquery for Next.js routes
SELECT
normalizedUrl,
COUNT(1)
FROM (
SELECT
httpRequest.requestUrl,
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(httpRequest.requestUrl, r'/_next/data/[^/]+', ''), r'\d+', '[id]'), r'\.json', '') AS normalizedUrl
FROM
`greenmobility.cloudrun_requests.run_googleapis_com_requests`
WHERE
TIMESTAMP_TRUNC(timestamp, DAY) > TIMESTAMP("2023-01-28") )
WHERE
normalizedUrl LIKE '%.com/admin/%'
# AND normalizedUrl LIKE '%package%'
GROUP BY
normalizedUrl
ORDER BY
2 desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment