{"id":8802,"date":"2026-08-05T13:59:19","date_gmt":"2026-08-05T11:59:19","guid":{"rendered":"https:\/\/www.lukaswojcik.com\/blog\/?page_id=8802"},"modified":"2026-08-05T14:01:35","modified_gmt":"2026-08-05T12:01:35","slug":"bigquery-ga4-query-unnest-builder","status":"publish","type":"page","link":"https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/bigquery-ga4-query-unnest-builder\/","title":{"rendered":"BigQuery GA4 Query &#038; UNNEST Builder"},"content":{"rendered":"<div class=\"gtm-analyser-container\" style=\"background: var(--bg-panel, #1e1e24); padding: 25px; border-radius: 8px; border: 1px solid var(--border, #2a2a35);\">\n<p style=\"color: var(--text-secondary); margin-bottom: 20px;\">\n        Select dimensions and event parameters to automatically generate optimized Standard SQL with clean <code>UNNEST(event_params)<\/code> logic.\n    <\/p>\n<div style=\"margin-bottom: 20px;\">\n        <label style=\"color: var(--text-primary); font-weight: bold; display: block; margin-bottom: 6px;\">BigQuery Table ID:<\/label><br \/>\n        <input type=\"text\" id=\"bq-table-id\" value=\"your-project.analytics_123456789.events_*\" style=\"width: 100%; padding: 10px; background: var(--bg-body, #101416); border: 1px solid var(--border); color: var(--accent); border-radius: 6px; font-family: monospace;\">\n    <\/div>\n<div style=\"display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px;\">\n        <label style=\"color: var(--text-secondary);\"><input type=\"checkbox\" class=\"bq-field\" value=\"user_pseudo_id\" checked> user_pseudo_id<\/label><br \/>\n        <label style=\"color: var(--text-secondary);\"><input type=\"checkbox\" class=\"bq-field\" value=\"event_date\" checked> event_date<\/label><br \/>\n        <label style=\"color: var(--text-secondary);\"><input type=\"checkbox\" class=\"bq-field\" value=\"event_name\" checked> event_name<\/label><br \/>\n        <label style=\"color: var(--text-secondary);\"><input type=\"checkbox\" class=\"bq-field\" value=\"param:page_location\" checked> page_location (param)<\/label><br \/>\n        <label style=\"color: var(--text-secondary);\"><input type=\"checkbox\" class=\"bq-field\" value=\"param:page_title\"> page_title (param)<\/label><br \/>\n        <label style=\"color: var(--text-secondary);\"><input type=\"checkbox\" class=\"bq-field\" value=\"param:transaction_id\"> transaction_id (param)<\/label><br \/>\n        <label style=\"color: var(--text-secondary);\"><input type=\"checkbox\" class=\"bq-field\" value=\"param:value\"> value (int\/float param)<\/label><br \/>\n        <label style=\"color: var(--text-secondary);\"><input type=\"checkbox\" class=\"bq-field\" value=\"param:source\"> source (param)<\/label><br \/>\n        <label style=\"color: var(--text-secondary);\"><input type=\"checkbox\" class=\"bq-field\" value=\"param:medium\"> medium (param)<\/label>\n    <\/div>\n<p>    <button id=\"build-bq-btn\" class=\"button\" style=\"background: var(--accent, #2ba6df); color: #0b1114; border: none; padding: 12px 24px; border-radius: 6px; font-weight: 700; cursor: pointer;\">Generate SQL Query<\/button><\/p>\n<pre id=\"bq-output\" style=\"background: #0b1114; border: 1px solid var(--border); color: #51cf66; padding: 20px; border-radius: 6px; font-family: monospace; margin-top: 20px; overflow-x: auto; white-space: pre-wrap;\"><\/pre>\n<\/div>\n<p><script>\nconst updateSQL = () => {\n    const NL = String.fromCharCode(10);\n    const SQ = String.fromCharCode(39);\n    const tableInput = document.getElementById(\"bq-table-id\").value.trim() || \"your_project.analytics_123456789.events_*\";\n    const table = \"`\" + tableInput.replace(\/`\/g, \"\") + \"`\";\n    const checkboxes = document.querySelectorAll(\".bq-field:checked\");\n    const fields = [];<\/p>\n<p>    checkboxes.forEach(cb => {\n        const val = cb.value;\n        if (val.startsWith(\"param:\")) {\n            const paramKey = val.replace(\"param:\", \"\");\n            if (paramKey === \"value\") {\n                fields.push(\n                    \"  COALESCE(\" + NL +\n                    \"    (SELECT value.double_value FROM UNNEST(event_params) WHERE key = \" + SQ + \"value\" + SQ + \"),\" + NL +\n                    \"    (SELECT value.int_value FROM UNNEST(event_params) WHERE key = \" + SQ + \"value\" + SQ + \")\" + NL +\n                    \"  ) AS value\"\n                );\n            } else {\n                fields.push(\"  (SELECT value.string_value FROM UNNEST(event_params) WHERE key = \" + SQ + paramKey + SQ + \") AS \" + paramKey);\n            }\n        } else {\n            fields.push(\"  \" + val);\n        }\n    });<\/p>\n<p>    if (fields.length === 0) {\n        fields.push(\"  user_pseudo_id\");\n    }<\/p>\n<p>    const lines = [\n        \"SELECT\",\n        fields.join(\",\" + NL),\n        \"FROM\",\n        \"  \" + table,\n        \"WHERE\",\n        \"  _TABLE_SUFFIX >= FORMAT_DATE(\" + SQ + \"%Y%m%d\" + SQ + \", DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY))\",\n        \"  AND event_name = \" + SQ + \"page_view\" + SQ,\n        \"LIMIT 100;\"\n    ];<\/p>\n<p>    document.getElementById(\"bq-output\").textContent = lines.join(NL);\n};<\/p>\n<p>document.getElementById(\"build-bq-btn\").addEventListener(\"click\", updateSQL);\ndocument.querySelectorAll(\".bq-field\").forEach(cb => cb.addEventListener(\"change\", updateSQL));\nupdateSQL();\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Generate optimized standard SQL for GA4 BigQuery exports with automatic UNNEST parameter logic.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":38,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"template-tool-base.php","meta":{"footnotes":""},"class_list":["post-8802","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>BigQuery GA4 Query &amp; UNNEST Builder - Lukas Wojcik - Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/bigquery-ga4-query-unnest-builder\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"BigQuery GA4 Query &amp; UNNEST Builder - Lukas Wojcik - Blog\" \/>\n<meta property=\"og:description\" content=\"Generate optimized standard SQL for GA4 BigQuery exports with automatic UNNEST parameter logic.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/bigquery-ga4-query-unnest-builder\/\" \/>\n<meta property=\"og:site_name\" content=\"Lukas Wojcik - Blog\" \/>\n<meta property=\"article:modified_time\" content=\"2026-08-05T12:01:35+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/toolbox\\\/bigquery-ga4-query-unnest-builder\\\/\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/toolbox\\\/bigquery-ga4-query-unnest-builder\\\/\",\"name\":\"BigQuery GA4 Query & UNNEST Builder - Lukas Wojcik - Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#website\"},\"datePublished\":\"2026-08-05T11:59:19+00:00\",\"dateModified\":\"2026-08-05T12:01:35+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/toolbox\\\/bigquery-ga4-query-unnest-builder\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/toolbox\\\/bigquery-ga4-query-unnest-builder\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/toolbox\\\/bigquery-ga4-query-unnest-builder\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Toolbox\",\"item\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/toolbox\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"BigQuery GA4 Query &#038; UNNEST Builder\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/\",\"name\":\"Lukas Wojcik - Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\",\"name\":\"luky\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"contentUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"width\":424,\"height\":636,\"caption\":\"luky\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\"},\"sameAs\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"BigQuery GA4 Query & UNNEST Builder - Lukas Wojcik - Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/bigquery-ga4-query-unnest-builder\/","og_locale":"en_US","og_type":"article","og_title":"BigQuery GA4 Query & UNNEST Builder - Lukas Wojcik - Blog","og_description":"Generate optimized standard SQL for GA4 BigQuery exports with automatic UNNEST parameter logic.","og_url":"https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/bigquery-ga4-query-unnest-builder\/","og_site_name":"Lukas Wojcik - Blog","article_modified_time":"2026-08-05T12:01:35+00:00","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/bigquery-ga4-query-unnest-builder\/","url":"https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/bigquery-ga4-query-unnest-builder\/","name":"BigQuery GA4 Query & UNNEST Builder - Lukas Wojcik - Blog","isPartOf":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#website"},"datePublished":"2026-08-05T11:59:19+00:00","dateModified":"2026-08-05T12:01:35+00:00","breadcrumb":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/bigquery-ga4-query-unnest-builder\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/bigquery-ga4-query-unnest-builder\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/bigquery-ga4-query-unnest-builder\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.lukaswojcik.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Toolbox","item":"https:\/\/www.lukaswojcik.com\/blog\/en\/toolbox\/"},{"@type":"ListItem","position":3,"name":"BigQuery GA4 Query &#038; UNNEST Builder"}]},{"@type":"WebSite","@id":"https:\/\/www.lukaswojcik.com\/blog\/#website","url":"https:\/\/www.lukaswojcik.com\/blog\/","name":"Lukas Wojcik - Blog","description":"","publisher":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.lukaswojcik.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9","name":"luky","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","contentUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","width":424,"height":636,"caption":"luky"},"logo":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg"},"sameAs":["https:\/\/www.lukaswojcik.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/pages\/8802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/comments?post=8802"}],"version-history":[{"count":0,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/pages\/8802\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/pages\/38"}],"wp:attachment":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/media?parent=8802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}