{"id":38773,"date":"2022-01-28T15:08:30","date_gmt":"2022-01-28T14:08:30","guid":{"rendered":"https:\/\/clicktrust.be\/blog\/non-classifiee\/tutorial-linking-google-analytics-4-to-google-bigquery\/"},"modified":"2023-07-07T15:21:40","modified_gmt":"2023-07-07T13:21:40","slug":"tutorial-linking-google-analytics-4-to-google-bigquery","status":"publish","type":"post","link":"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/","title":{"rendered":"Introduction to GA4 linking with BigQuery and connecting with R"},"content":{"rendered":"[vc_row type=&#8221;in_container&#8221; full_screen_row_position=&#8221;middle&#8221; column_margin=&#8221;default&#8221; column_direction=&#8221;default&#8221; column_direction_tablet=&#8221;default&#8221; column_direction_phone=&#8221;default&#8221; scene_position=&#8221;center&#8221; top_padding=&#8221;50&#8243; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221; row_border_radius=&#8221;none&#8221; row_border_radius_applies=&#8221;bg&#8221; overflow=&#8221;visible&#8221; advanced_gradient_angle=&#8221;0&#8243; overlay_strength=&#8221;0.3&#8243; gradient_direction=&#8221;left_to_right&#8221; shape_divider_position=&#8221;bottom&#8221; bg_image_animation=&#8221;none&#8221; gradient_type=&#8221;default&#8221; shape_type=&#8221;&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_tablet=&#8221;inherit&#8221; column_padding_phone=&#8221;inherit&#8221; column_padding_position=&#8221;all&#8221; column_element_direction_desktop=&#8221;default&#8221; column_element_spacing=&#8221;default&#8221; desktop_text_alignment=&#8221;default&#8221; tablet_text_alignment=&#8221;default&#8221; phone_text_alignment=&#8221;default&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; column_backdrop_filter=&#8221;none&#8221; column_shadow=&#8221;none&#8221; column_border_radius=&#8221;none&#8221; column_link_target=&#8221;_self&#8221; column_position=&#8221;default&#8221; gradient_direction=&#8221;left_to_right&#8221; overlay_strength=&#8221;0.3&#8243; width=&#8221;1\/1&#8243; tablet_width_inherit=&#8221;default&#8221; animation_type=&#8221;default&#8221; bg_image_animation=&#8221;none&#8221; border_type=&#8221;simple&#8221; column_border_width=&#8221;none&#8221; column_border_style=&#8221;solid&#8221;][vc_column_text]<span style=\"font-weight: 300;\">In one of our previous posts, we already explained <a href=\"https:\/\/clicktrust.be\/blog\/analytics\/google-bigquery-for-marketing\/\" target=\"_blank\" rel=\"noopener noreferrer\">what Google BigQuery is and why you should use it as a markete<\/a>r. In this post, we will explain how you can create your very first BigQuery project with Google Analytics data.<\/span><\/p>\n<h2>1) Create a Google Cloud project<\/h2>\n<p><span style=\"font-weight: 300;\">Google organizes your account with different projects. Each has its own scope, rights, and governance.<\/span><\/p>\n<p><span style=\"font-weight: 300;\">You\u2019ll need to set up a project. It\u2019s free if you stay on the free tier.\u00a0<\/span><\/p>\n<p><b>Step 1<\/b><span style=\"font-weight: 300;\">: Navigate to the <\/span><a href=\"https:\/\/console.cloud.google.com\/bigquery\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-weight: 300;\">Google BigQuery Platform<\/span><\/a><\/p>\n<p><b>Step 2<\/b><span style=\"font-weight: 300;\">: Click on the drop-down menu and create a new project.<\/span><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-41880\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Google-BigQuery-SQL-workspace.png\" alt=\"\" width=\"614\" height=\"116\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Google-BigQuery-SQL-workspace.png 614w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Google-BigQuery-SQL-workspace-300x57.png 300w\" sizes=\"(max-width: 614px) 100vw, 614px\" \/><img decoding=\"async\" class=\"alignnone size-full wp-image-41883\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Create-a-new-project-in-Google-BigQuery.png\" alt=\"\" width=\"772\" height=\"168\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Create-a-new-project-in-Google-BigQuery.png 772w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Create-a-new-project-in-Google-BigQuery-300x65.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Create-a-new-project-in-Google-BigQuery-768x167.png 768w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 300;\"><strong>Step 3<\/strong>: Give your project a name, and an organization if relevant. Click on CREATE, you should see your project in the list.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 300;\"><img decoding=\"async\" class=\"alignnone size-full wp-image-41886\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/How-to-create-a-new-project-in-Google-BigQuery.png\" alt=\"\" width=\"561\" height=\"545\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/How-to-create-a-new-project-in-Google-BigQuery.png 561w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/How-to-create-a-new-project-in-Google-BigQuery-300x291.png 300w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 300;\">If you\u2019re in an organization, check that you have proper rights, and your project fits in the organization\u2019s governance. You may need additional rights to go further (for example, if you want to enable the billing).<\/span><\/p>\n<p><span style=\"font-weight: 300;\">When you created the project, if you don\u2019t see it in the list, and you didn\u2019t set an organization, check on the drop-down list above: \u201cNo Organization\u201d.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-41889\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Select-an-organization-in-Google-BigQuery.png\" alt=\"\" width=\"752\" height=\"156\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Select-an-organization-in-Google-BigQuery.png 752w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Select-an-organization-in-Google-BigQuery-300x62.png 300w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><b>Step 4<\/b><span style=\"font-weight: 300;\">: Enable the BigQuery API on this project : on the left menu, click API &amp; Services, then Library. Activate BigQuery.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2>2) Link GA4 with the BigQuery project<\/h2>\n<p><b>Step 5<\/b><span style=\"font-weight: 300;\">: Go to your analytics account (https:\/\/www.google.com\/analytics) and click on Admin. Then Big Query Linking under \u201cproduct linking\u201d<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-41892\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Link-Google-Analytics-4-to-Google-BigQuery.png\" alt=\"\" width=\"984\" height=\"783\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Link-Google-Analytics-4-to-Google-BigQuery.png 984w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Link-Google-Analytics-4-to-Google-BigQuery-300x239.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Link-Google-Analytics-4-to-Google-BigQuery-768x611.png 768w\" sizes=\"(max-width: 984px) 100vw, 984px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><b>Step 6<\/b><span style=\"font-weight: 300;\">: Then click on <\/span><span style=\"font-weight: 300;\">Link<\/span><span style=\"font-weight: 300;\">. You\u2019ll see Google projects you have access to. It\u2019s possible to link with a Google project you don\u2019t own. But you\u2019ll need admin rights on the Google Analytics properties and editing on the google project.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-41895\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/BigQuery-linking-in-Google-Analytics-4.png\" alt=\"\" width=\"880\" height=\"253\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/BigQuery-linking-in-Google-Analytics-4.png 880w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/BigQuery-linking-in-Google-Analytics-4-300x86.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/BigQuery-linking-in-Google-Analytics-4-768x221.png 768w\" sizes=\"(max-width: 880px) 100vw, 880px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><b>Step 7<\/b><span style=\"font-weight: 300;\">: Then, on Choose a Big Query project and click on <\/span><span style=\"font-weight: 300;\">Confirm<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-41898\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Link-to-a-BigQuery-project-I-have-access-to-1024x186.png\" alt=\"\" width=\"1024\" height=\"186\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Link-to-a-BigQuery-project-I-have-access-to-1024x186.png 1024w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Link-to-a-BigQuery-project-I-have-access-to-300x54.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Link-to-a-BigQuery-project-I-have-access-to-768x139.png 768w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Link-to-a-BigQuery-project-I-have-access-to.png 1162w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-41901\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Create-a-link-with-BigQuery-in-Google-Analytics-4.png\" alt=\"\" width=\"850\" height=\"534\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Create-a-link-with-BigQuery-in-Google-Analytics-4.png 850w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Create-a-link-with-BigQuery-in-Google-Analytics-4-300x188.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Create-a-link-with-BigQuery-in-Google-Analytics-4-768x482.png 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><span style=\"font-weight: 300;\">For longer explanations, check the <a href=\"https:\/\/support.google.com\/analytics\/answer\/9823238?hl=en&amp;utm_id=ad#zippy=%2Cin-this-article\" target=\"_blank\" rel=\"noopener noreferrer\">documentation<\/a>.<\/span><\/p>\n<p><span style=\"font-weight: 300;\">If you go to the settings of the link, there are two options of updates: Daily (each night) or streaming (continuously). You\u2019ll need to enable billing for streaming.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2>3) Add the User ID (optional) in the Google Analytics Setup.<\/h2>\n<p>To do multidevice analysis on GA4\/BQ, you\u2019ll need a user ID, that is valid across all devices. That\u2019s not the case of Google Analytics (id), called user_pseudo_id, which lies in the GA cookie.<\/p>\n<p>If you pass a UserID to GA4, it will be present in the BigQuery under the field \u201cUser ID\u201d and therefore enable multi-device\/session analytics, without being dependent on cookies.<\/p>\n<p>There are several ways to do it. It will depend on the implementation of your Google Analytics on your website. The simplest is to call add a code snippet on your site, after the gtag function<\/p>\n<pre><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0gtag('config', '**YOUR GA property ID**, { 'user_id': 'User_ID'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, 'ad_storage': 'denied' });\u00a0 <\/span><\/pre>\n<p><span style=\"font-weight: 300;\">Be careful: from now on, you track the behavior of your consumers with a personal\u00a0 identifier. Therefore, you are a processor of personal data and must fill your legal duties like getting consent. Act with caution: it is considered as server-to-server tracking, so may be out of your cookie policy. You can set limits to the usage of this user_id, by example setting the parameter \u201cad_storage : \u2018denied\u2019).<\/span><\/p>\n<h2>4) Play with data on the UI<\/h2>\n<p><span style=\"font-weight: 300;\">Go to the <a href=\"https:\/\/console.cloud.google.com\/bigquery\" target=\"_blank\" rel=\"noopener noreferrer\">Big Query platform<\/a><\/span><\/p>\n<p><span style=\"font-weight: 300;\">You\u2019ll see on the left the projects: expand and click on events_ (intraday) if you chose streaming)<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-41904\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/How-to-use-the-BigQuery-platform-1024x683.png\" alt=\"\" width=\"1024\" height=\"683\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/How-to-use-the-BigQuery-platform-1024x683.png 1024w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/How-to-use-the-BigQuery-platform-300x200.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/How-to-use-the-BigQuery-platform-768x512.png 768w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/How-to-use-the-BigQuery-platform-1536x1024.png 1536w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/How-to-use-the-BigQuery-platform-900x600.png 900w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/How-to-use-the-BigQuery-platform.png 1728w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 300;\">Tip: a day of data is valid for only 60 days. You can expand by going in the DETAILS tab, then EDIT and specify a new expiration date. You\u2019ll need to make it for each day, one by one, though.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-41907\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Expanding-the-expiration-time-in-Google-BigQuery-1024x546.png\" alt=\"\" width=\"1024\" height=\"546\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Expanding-the-expiration-time-in-Google-BigQuery-1024x546.png 1024w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Expanding-the-expiration-time-in-Google-BigQuery-300x160.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Expanding-the-expiration-time-in-Google-BigQuery-768x410.png 768w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Expanding-the-expiration-time-in-Google-BigQuery.png 1029w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 300;\">You can preview the data on the tab Preview. If you\u2019re used to MS SQL, you\u2019ll see something new: nested tables.\u00a0 It\u2019s like a table in a cell.<\/span><\/p>\n<p><span style=\"font-weight: 300;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-41910\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Preview-data-in-Google-BigQuery-1024x284.png\" alt=\"\" width=\"1024\" height=\"284\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Preview-data-in-Google-BigQuery-1024x284.png 1024w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Preview-data-in-Google-BigQuery-300x83.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Preview-data-in-Google-BigQuery-768x213.png 768w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Preview-data-in-Google-BigQuery.png 1389w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/span><\/p>\n<p><span style=\"font-weight: 300;\">If you add the CRM id in the customer data ID of Google (User ID in Big query), you\u2019re able to merge the online behavior of your customers with their sales and offline behavior.<\/span><\/p>\n<p><span style=\"font-weight: 300;\">If you click on Query, you can write your first query<\/span><\/p>\n<pre style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">SELECT<\/span> <span style=\"font-weight: 400;\">*<\/span> <span style=\"font-weight: 400;\">FROM<\/span> <span style=\"font-weight: 400;\">`mediadata-249609.analytics_249502555.events_20220104`<\/span> <span style=\"font-weight: 400;\">LIMIT<\/span> <span style=\"font-weight: 400;\">1000<\/span><\/pre>\n<p><span style=\"font-weight: 300;\">In the upper right corner, you\u2019ll see how much data the query will process.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 300;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-41913\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Writing-queries-in-Google-BigQuery-1024x71.png\" alt=\"\" width=\"1024\" height=\"71\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Writing-queries-in-Google-BigQuery-1024x71.png 1024w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Writing-queries-in-Google-BigQuery-300x21.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Writing-queries-in-Google-BigQuery-768x54.png 768w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Writing-queries-in-Google-BigQuery.png 1392w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/span><\/p>\n<p><span style=\"font-weight: 300;\">(you won\u2019t be charged for the first TB per month).<\/span><\/p>\n<p><span style=\"font-weight: 300;\">You can read all the days by setting an asterisk on the table name :\u00a0<\/span><\/p>\n<pre style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">SELECT<\/span> <span style=\"font-weight: 400;\">*<\/span> <span style=\"font-weight: 400;\">FROM<\/span> <span style=\"font-weight: 400;\">`mediadata-249609.analytics_249502555.events_*`<\/span> <span style=\"font-weight: 400;\">LIMIT<\/span> <span style=\"font-weight: 400;\">1000<\/span><\/pre>\n<p><span style=\"font-weight: 300;\">Beware of data consumption! Try your queries on a specific day, then expand it on the whole data set when you\u2019re sure.<\/span><\/p>\n<p><span style=\"font-weight: 300;\">If you click on run, you should see your data<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-41916\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Running-a-query-in-Google-BigQuery-1024x510.png\" alt=\"\" width=\"1024\" height=\"510\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Running-a-query-in-Google-BigQuery-1024x510.png 1024w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Running-a-query-in-Google-BigQuery-300x149.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Running-a-query-in-Google-BigQuery-768x383.png 768w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Running-a-query-in-Google-BigQuery-670x335.png 670w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Running-a-query-in-Google-BigQuery.png 1407w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>You can also visualize your data in DataStudio.<\/p>\n<p>You may review your SQL to use this platform. Useful tips to consider :<\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\">Dates: you can parse date with the parse_date function. If you type the following code in your Select code, you\u2019ll have a nice YYYY-MM-DD formatted date<\/li>\n<\/ul>\n<pre style=\"padding-left: 80px;\">parse_date('%Y%m%d',event_date) as event_date,<\/pre>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\">Nested data : You see that a single cell can hold an entire table. Event_params is a table, in a single record. To \u201cunnest\u201d the nested table, you must use unnest function in a nested SQL query.<\/li>\n<\/ul>\n<pre style=\"padding-left: 80px;\">Select\r\n(select key from unnest(event_params) where key = 'page_location') as event_key,\r\n(select value.string_value from unnest(event_params) where key = 'page_location') as event_string_value,\r\nFrom `mediadata-249609.analytics_249502555.events_20220104`<\/pre>\n<p>You\u2019ll have a good old two-dimensional table:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-41919\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Two-dimensional-table-in-Google-BigQuery-1024x388.png\" alt=\"\" width=\"1024\" height=\"388\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Two-dimensional-table-in-Google-BigQuery-1024x388.png 1024w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Two-dimensional-table-in-Google-BigQuery-300x114.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Two-dimensional-table-in-Google-BigQuery-768x291.png 768w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Two-dimensional-table-in-Google-BigQuery.png 1388w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Good news: the user_id mentioned in point 3 is there, and it has different ga_session_id\u2019s. So it\u2019s possible to analyze its behavior cross-session and device.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-41922\" src=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Query-results-in-Google-BigQuery.png\" alt=\"\" width=\"864\" height=\"423\" srcset=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Query-results-in-Google-BigQuery.png 864w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Query-results-in-Google-BigQuery-300x147.png 300w, https:\/\/clicktrust.be\/wp-content\/uploads\/2022\/01\/Query-results-in-Google-BigQuery-768x376.png 768w\" sizes=\"(max-width: 864px) 100vw, 864px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>5) Connect with R<\/h2>\n<p>Using the UI of BigQuery is nice, but besides using Data Studio connectors, you can\u2019t visualize or process data without paying BigQuery processing fees.<\/p>\n<p>Odds are you want to analyze that data with a language that allows you to create machine learning algorithms . Python, like other programming languages, is well <a href=\"https:\/\/cloud.google.com\/bigquery\/docs\/reference\/libraries\" target=\"_blank\" rel=\"noopener noreferrer\">documented<\/a>.<\/p>\n<p>I personally use the bigrquery package (https:\/\/github.com\/r-dbi\/bigrquery) , which works well with that code :<\/p>\n<pre style=\"padding-left: 80px;\">library(bigrquery)\r\n\r\nbq_conn &lt;-\u00a0 dbConnect(bigquery(),\u00a0\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0project = \"project ID\",\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0dataset = \" name of dataset\",\u00a0\r\n\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0use_legacy_sql = FALSE\r\n)\r\n\r\nSQLSTR &lt;- \u201cSelect * FROM table\u201d\r\n\r\n\u00a0\u00a0billing &lt;- \"project ID\"\u00a0 # replace this with your GCP project ID\u00a0\r\n\r\n \u00a0tb &lt;- bq_project_query(billing, SQLSTR)\r\n\r\n \u00a0df &lt;- bq_table_download(tb)\r\n\r\nprint(df)<\/pre>\n[\/vc_column_text][\/vc_column][\/vc_row][vc_row type=&#8221;in_container&#8221; full_screen_row_position=&#8221;middle&#8221; column_margin=&#8221;default&#8221; column_direction=&#8221;default&#8221; column_direction_tablet=&#8221;default&#8221; column_direction_phone=&#8221;default&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221; row_border_radius=&#8221;none&#8221; row_border_radius_applies=&#8221;bg&#8221; overflow=&#8221;visible&#8221; overlay_strength=&#8221;0.3&#8243; gradient_direction=&#8221;left_to_right&#8221; shape_divider_position=&#8221;bottom&#8221; bg_image_animation=&#8221;none&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_tablet=&#8221;inherit&#8221; column_padding_phone=&#8221;inherit&#8221; column_padding_position=&#8221;all&#8221; column_element_direction_desktop=&#8221;default&#8221; column_element_spacing=&#8221;default&#8221; desktop_text_alignment=&#8221;default&#8221; tablet_text_alignment=&#8221;default&#8221; phone_text_alignment=&#8221;default&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; column_backdrop_filter=&#8221;none&#8221; column_shadow=&#8221;none&#8221; column_border_radius=&#8221;none&#8221; column_link_target=&#8221;_self&#8221; column_position=&#8221;default&#8221; gradient_direction=&#8221;left_to_right&#8221; overlay_strength=&#8221;0.3&#8243; width=&#8221;1\/1&#8243; tablet_width_inherit=&#8221;default&#8221; animation_type=&#8221;default&#8221; bg_image_animation=&#8221;none&#8221; border_type=&#8221;simple&#8221; column_border_width=&#8221;none&#8221; column_border_style=&#8221;solid&#8221;][nectar_global_section id=&#8221;31229&#8243;][\/vc_column][\/vc_row]\n","protected":false},"excerpt":{"rendered":"<p>[vc_row type=&#8221;in_container&#8221; full_screen_row_position=&#8221;middle&#8221; column_margin=&#8221;default&#8221; column_direction=&#8221;default&#8221; column_direction_tablet=&#8221;default&#8221; column_direction_phone=&#8221;default&#8221; scene_position=&#8221;center&#8221; top_padding=&#8221;50&#8243; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221; row_border_radius=&#8221;none&#8221; row_border_radius_applies=&#8221;bg&#8221; overflow=&#8221;visible&#8221; advanced_gradient_angle=&#8221;0&#8243; overlay_strength=&#8221;0.3&#8243; gradient_direction=&#8221;left_to_right&#8221; shape_divider_position=&#8221;bottom&#8221; bg_image_animation=&#8221;none&#8221; gradient_type=&#8221;default&#8221; shape_type=&#8221;&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_tablet=&#8221;inherit&#8221; column_padding_phone=&#8221;inherit&#8221; column_padding_position=&#8221;all&#8221;&#8230;<\/p>\n","protected":false},"author":21,"featured_media":43196,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"two_page_speed":[],"footnotes":""},"categories":[189],"tags":[240,238],"level":[199],"class_list":{"0":"post-38773","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-analytics","8":"tag-bigquery-fr","9":"tag-google-analytics-4-fr","10":"level-channel-specialist-fr"},"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Tutorial: Linking Google Analytics 4 to Google BigQuery | CLICKTRUST<\/title>\n<meta name=\"description\" content=\"In this blog post, we explain how to create your first Google BigQuery project with Google Analytics 4 data.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tutorial: Linking Google Analytics 4 to Google BigQuery | CLICKTRUST\" \/>\n<meta property=\"og:description\" content=\"In this blog post, we explain how to create your first Google BigQuery project with Google Analytics 4 data.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/\" \/>\n<meta property=\"og:site_name\" content=\"Clicktrust\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/clicktrustbrussels\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-28T14:08:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-07T13:21:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/clicktrust.be\/wp-content\/uploads\/2021\/12\/google-bigquery-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nicolas Schnock\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u00c9crit par\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nicolas Schnock\" \/>\n\t<meta name=\"twitter:label2\" content=\"Dur\u00e9e de lecture est.\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tutorial: Linking Google Analytics 4 to Google BigQuery | CLICKTRUST","description":"In this blog post, we explain how to create your first Google BigQuery project with Google Analytics 4 data.","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:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/","og_locale":"fr_FR","og_type":"article","og_title":"Tutorial: Linking Google Analytics 4 to Google BigQuery | CLICKTRUST","og_description":"In this blog post, we explain how to create your first Google BigQuery project with Google Analytics 4 data.","og_url":"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/","og_site_name":"Clicktrust","article_publisher":"https:\/\/www.facebook.com\/clicktrustbrussels\/","article_published_time":"2022-01-28T14:08:30+00:00","article_modified_time":"2023-07-07T13:21:40+00:00","og_image":[{"width":1024,"height":1024,"url":"https:\/\/clicktrust.be\/wp-content\/uploads\/2021\/12\/google-bigquery-1.jpg","type":"image\/jpeg"}],"author":"Nicolas Schnock","twitter_card":"summary_large_image","twitter_misc":{"\u00c9crit par":"Nicolas Schnock","Dur\u00e9e de lecture est.":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/#article","isPartOf":{"@id":"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/"},"author":{"name":"Nicolas Schnock","@id":"https:\/\/clicktrust.be\/fr\/#\/schema\/person\/7e569f5ae5038eac490bc39872079144"},"headline":"Introduction to GA4 linking with BigQuery and connecting with R","datePublished":"2022-01-28T14:08:30+00:00","dateModified":"2023-07-07T13:21:40+00:00","mainEntityOfPage":{"@id":"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/"},"wordCount":1277,"publisher":{"@id":"https:\/\/clicktrust.be\/fr\/#organization"},"keywords":["BigQuery","Google Analytics 4"],"articleSection":["Analytics"],"inLanguage":"fr-BE"},{"@type":"WebPage","@id":"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/","url":"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/","name":"Tutorial: Linking Google Analytics 4 to Google BigQuery | CLICKTRUST","isPartOf":{"@id":"https:\/\/clicktrust.be\/fr\/#website"},"datePublished":"2022-01-28T14:08:30+00:00","dateModified":"2023-07-07T13:21:40+00:00","description":"In this blog post, we explain how to create your first Google BigQuery project with Google Analytics 4 data.","breadcrumb":{"@id":"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/#breadcrumb"},"inLanguage":"fr-BE","potentialAction":[{"@type":"ReadAction","target":["https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/clicktrust.be\/fr\/blog\/analytics\/tutorial-linking-google-analytics-4-to-google-bigquery\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/clicktrust.be\/fr\/"},{"@type":"ListItem","position":2,"name":"Brainfood","item":"https:\/\/clicktrust.be\/blog\/"},{"@type":"ListItem","position":3,"name":"Analytics","item":"https:\/\/clicktrust.be\/fr\/category\/analytics\/"},{"@type":"ListItem","position":4,"name":"Introduction to GA4 linking with BigQuery and connecting with R"}]},{"@type":"WebSite","@id":"https:\/\/clicktrust.be\/fr\/#website","url":"https:\/\/clicktrust.be\/fr\/","name":"Clicktrust","description":"We are CLICKTRUST. Full transparency","publisher":{"@id":"https:\/\/clicktrust.be\/fr\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/clicktrust.be\/fr\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"fr-BE"},{"@type":"Organization","@id":"https:\/\/clicktrust.be\/fr\/#organization","name":"Clicktrust","url":"https:\/\/clicktrust.be\/fr\/","logo":{"@type":"ImageObject","inLanguage":"fr-BE","@id":"https:\/\/clicktrust.be\/fr\/#\/schema\/logo\/image\/","url":"","contentUrl":"","caption":"Clicktrust"},"image":{"@id":"https:\/\/clicktrust.be\/fr\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/clicktrustbrussels\/","https:\/\/www.youtube.com\/channel\/UCKKPuTA6ssQo_w1Kzs9Ldwg","https:\/\/www.linkedin.com\/company\/clicktrust-marketing\/","https:\/\/instagram.com\/clicktrust?igshid=YmMyMTA2M2Y"]},{"@type":"Person","@id":"https:\/\/clicktrust.be\/fr\/#\/schema\/person\/7e569f5ae5038eac490bc39872079144","name":"Nicolas Schnock","image":{"@type":"ImageObject","inLanguage":"fr-BE","@id":"https:\/\/clicktrust.be\/fr\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/61b3b96546950eacbe8786d4fe4c09c681671912e79d8cc4d9fcb7d27c0946db?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/61b3b96546950eacbe8786d4fe4c09c681671912e79d8cc4d9fcb7d27c0946db?s=96&d=mm&r=g","caption":"Nicolas Schnock"},"description":"CTO","url":"https:\/\/clicktrust.be\/fr\/author\/nicolas-schnock\/"}]}},"_links":{"self":[{"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/posts\/38773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/comments?post=38773"}],"version-history":[{"count":0,"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/posts\/38773\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/media\/43196"}],"wp:attachment":[{"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/media?parent=38773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/categories?post=38773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/tags?post=38773"},{"taxonomy":"level","embeddable":true,"href":"https:\/\/clicktrust.be\/fr\/wp-json\/wp\/v2\/level?post=38773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}