Talk to us

1.
What is the BigQuery GA4 Daily Export Schema?

Before we dive into the nitty-gritty, let's get a bird's eye view.

  • Definition: The BigQuery GA4 daily export schema is a structured format for the data exported from Google Analytics 4 (GA4) to BigQuery.

  • Purpose: It allows you to perform in-depth analysis and build custom reports that go beyond the standard GA4 capabilities.

  • Components: The schema includes various tables and fields that capture user interactions, events, and more.

The Big Picture: Understanding the Daily Export Table

What Each Row Represents

  • Each row in the daily export table represents a single event (that occurred) on your website or app. This is a fundamental shift from Universal Analytics' session-based data model to GA4's event-based model.

  • Event-centric: Each row is an event (e.g., page view, click, purchase).

  • Granular Data: Every user interaction is captured as an event, providing more detailed insights.

Key Components of the Schema

The Event Table

The heart of the GA4 export schema is the event table. This is where the magic happens.

  • event_name: The name of the event (e.g., 'page_view', 'click').

  • event_timestamp: When the event occurred (in microseconds).

  • user_id: Unique identifier for the user (if set).

User Properties

These fields provide insights into who your users are.

  • user_pseudo_id: Anonymised ID to track users across sessions.

  • user_properties: Custom properties you've set for users (e.g., 'preferred_language')

Event Parameters

Event parameters add context to your events.

  • param_name: The parameter's name (e.g., 'button_text').

  • param_value: The value of the parameter.

GA4 BigQuery export turns raw data into an opportunity to gain insights, with every event shedding light on user behaviour.

Zac Nash

Data Engineering Director

E-commerce and Items: A Key Feature

One of the GA4 export schema's most valuable aspects for e-commerce businesses is the detailed tracking of e-commerce events and item data.

E-commerce Fields

These fields provide comprehensive information about the various e-commerce events.

  • ecommerce.total_item_quantity: Total number of items included in the event.

  • ecommerce.purchase_revenue: Revenue generated from the purchase event.

  • ecommerce.tax_value: Tax value for the event.

  • ecommerce.shipping_value: Shipping cost for the event.

  • ecommerce.refund_value: Refund value for the event.

  • ecommerce.transaction_id: Unique identifier for the transaction.

  • ecommerce.unique_items: Number of unique items in the event.

Item-level Data

Each e-commerce event can also include detailed item-level data, providing granular insights into product performance.

  • items.item_id: Unique identifier for the item.

  • items.item_name: Name of the item.

  • items.item_brand: Brand of the item.

  • items.item_category: Category of the item.

  • items.item_variant: Variant of the item.

  • items.item_price: Price of the item.

  • items.item_quantity: Quantity of the item.

Breaking Down a Typical E-commerce Event

Let's take a closer look at a purchase event to see how these components come together.

  • event_name: 'purchase'

  • event_timestamp: 1622547800000000

  • user_pseudo_id: 'ABCDEFG12345'

  • user_properties: { 'preferred_language': 'en' }

  • ecommerce: {

  • total_item_quantity: 3,

  • purchase_revenue: 120.50,

  • tax_value: 10.50,

  • shipping_value: 5.00,

  • transaction_id: 'TX123456',

  • unique_items: 2 }

  • items: [ { 'item_id': 'SKU123', 'item_name': 'Running Shoes', 'item_brand': 'BrandX', 'item_category': 'Sportswear', 'item_variant': 'Red', 'item_price': 60.25, 'item_quantity': 1 }, { 'item_id': 'SKU124', 'item_name': 'Water Bottle', 'item_brand': 'Brandy', 'item_category': 'Accessories', 'item_variant': 'Blue', 'item_price': 30.00, 'item_quantity': 2 } ]

Interestingly, in the BigQuery GA4 daily export schema, a single purchase event encapsulates multiple levels of data—each providing different insights.

  • Event Level: Captures the overall transaction with fields like event_name and event_timestamp. There's one event for the entire purchase.

  • E-commerce Level: Provides aggregated details about the transaction such as total_item_quantity (total items bought, here 3), purchase_revenue (total revenue, here 120.50), tax_value, shipping_value, and unique_items (distinct products, here 2).

  • Item Level: Lists detailed information for each product in the items array. For instance, one Running Shoes with item_quantity of one and two Water Bottles with item_quantity of two. Each item entry includes specifics like item_id, item_name, item_brand, item_category, item_variant, item_price, and item_quantity. This shows a breakdown of how we get to the three total items bought, and the two unique items, at the e-commerce level.

2.
Practical Examples and Use Cases

  1. Analysing User Behaviour

    By examining the event table, you can identify which pages are most popular, where users drop off, and what actions they take.

    Example: Use SQL queries to find the most viewed pages.

    ``sql SELECT event_params.value.string_value AS page_location, COUNT() as page_views FROM your_project.your_dataset.events_, UNNEST(event_params) AS event_params WHERE event_name = 'page_view' AND event_params.key = 'page_location' GROUP BY page_location ORDER BY page_views DESC; ``

  2. E-commerce Performance

    Track the performance of your products and transactions using e-commerce-specific fields.

    Example: Query to extract e-commerce transaction data.

    ``sql SELECT ecommerce.total_item_quantity, ecommerce.purchase_revenue, ecommerce.tax_value, ecommerce.shipping_value, ecommerce.transaction_id, ecommerce.unique_items FROM your_project.your_dataset.events_* WHERE event_name = 'purchase' LIMIT 100; ``

  3. Item Performance

    Dive deeper into item-level data to understand which products are driving sales.

    Example: Query to extract item performance data.

    ``sql SELECT items.item_id, items.item_name, items.item_brand, items.item_category, items.item_variant, items.item_price, items.item_quantity FROM your_project.your_dataset.events_*, UNNEST(items) AS items WHERE event_name = 'purchase' LIMIT 100; ``

3.
Primary Differences Between GA4 UI and BigQuery Daily Export

1. Data Processing and Aggregation

  • GA4 UI: The data shown in the GA4 interface often includes aggregated and sampled data to deliver quick insights. Metrics like user counts and session durations might be approximated using algorithms, which can lead to small discrepancies (1-4%) compared to raw data. In the consent mode era, the data can be completely different depending on the reporting identity.

  • BigQuery Export: This provides raw, unaggregated event-level data, allowing for more precise and detailed analysis. However, replicating the aggregated metrics shown in the UI might require more complex querying.

2. Metric Definitions and Calculations

User Metrics:

  • GA4 UI: It uses a default of 'Active Users' to quantify users rather than 'Total Users'. Depending on the reporting identity, this may also include modelled Users. Again, more on this is in the consent mode section.

  • BigQuery: Relies on user_pseudo_id and user_id (if set), giving a direct count of users based on events. Google Signals data and AI-driven predictions are not exported to BigQuery, which can lead to differences in user and session counts. Active users are also a possible metric you can extract from the BigQuery Export.

Session Metrics:

  • GA4 UI: Sessions are calculated using the session_start event and might be combined over multiple days if no session timeout occurs.

  • BigQuery: It requires explicit querying to combine user_pseudo_id with ga_session_id to calculate session metrics accurately. Sessions spanning multiple days need to be handled differently compared to the UI.

3. Data Retention and Historical Data

  • GA4 UI: Data retention policies may limit access to historical data (typically up to 14 months for non-standard reports)

  • BigQuery: It retains data indefinitely from the point of activation, allowing long-term historical analysis. Activating BigQuery export early is crucial as it does not backfill historical data.

Consent Mode isn't a simple feature; it dynamically adjusts how data is collected based on user consent, helping you maintain data integrity while respecting privacy preferences.

Zac Nash

Data Engineering Director

Accessing Traffic Source and Medium in GA4 BigQuery

In GA4's BigQuery export, traffic sources are represented primarily by the traffic_source table. Within this table, you can access vital fields such as:

  • traffic_source.source (the source of the traffic, like Google or Bing)

  • traffic_source.medium (the marketing medium, like "organic" or "CPC")

To map these fields into GA4's default channel groupings, you can query them directly from BigQuery using SQL. Here's a simplified query for obtaining the source and medium:

``sql SELECT traffic_source.source, traffic_source.medium, traffic_source.campaign FROM your_project.your_dataset.ga4_export_* WHERE _TABLE_SUFFIX BETWEEN '20240101' AND '20241231' ``

Recently, GA4 introduced a new dimension, session_traffic_source_last_click, which captures the last click attribution for a session. This data is available within nested fields in BigQuery and can provide more accurate attribution than the standard traffic_source fields. To retrieve this data, you can unnest the session_traffic_source_last_click field:

``sql SELECT event_date, session_traffic_source_last_click.manual_campaign.source AS session_source, session_traffic_source_last_click.manual_campaign.medium AS session_medium FROM your_project_id.your_dataset_id.ga4_table_name ``

Mapping to Default Channel Grouping

GA4's default channel groupings are rule-based classifications. These can be created in BigQuery by applying regex-based rules to the source and medium fields. For example:

``sql SELECT CASE WHEN traffic_source.source = 'google' AND traffic_source.medium = 'organic' THEN 'Organic Search' WHEN traffic_source.source = 'facebook' AND traffic_source.medium = 'social' THEN 'Social' ELSE 'Other' END AS default_channel_grouping FROM your_project.your_dataset.ga4_export_* ``

Differences from GA4 UI

In the GA4 Analytics UI, the traffic source and medium fields are readily available through predefined reports (like the Acquisition report). However, the UI's default channel grouping is predefined and cannot be customised directly. In BigQuery, you have much more flexibility, allowing for custom channel groupings and deeper attribution models. Additionally, the session_traffic_source_last_click field is exclusive to BigQuery and provides more accurate last-click attribution, which differs from the UI's built-in model.

Using BigQuery allows you to create custom rules and tweak the attribution models, offering more control than the GA4 interface.

By integrating the traffic_source fields and the session_traffic_source_last_click, you can gain a more comprehensive understanding of your traffic channels and their performance.

4.
Be Careful: Common Pitfalls and Considerations

1. Data Sampling and Estimates

The GA4 UI often uses sampled data for faster reporting, which can lead to discrepancies. In contrast, BigQuery uses raw data without sampling, which is more accurate but may require more computational resources to process.

2. Event Count Discrepancies

Differences in event counts can arise due to the exclusion of certain events or parameters in the GA4 UI, while BigQuery includes every raw event logged. Custom Parameters that GTM is collecting (or otherwise) will only show in the UI if a corresponding custom dimension has been set up. Custom Parameters will always be sent to BigQuery.

3. Complex Querying in BigQuery

  • To replicate some of the metrics from the UI in BigQuery, it involves handling nested and repeated fields and may not be straightforward.

  • Nested Fields: Fields within fields (e.g., event_params and user_properties) require special handling to access their data.

  • Repeated Fields: Arrays of values (e.g., items in a purchase event) need to be unnested to query effectively.

  • Example: To extract parameters from nested fields, using the UNNEST function.

``sql SELECT event_name, param.key AS param_key, param.value.string_value AS param_value FROM your_project.your_dataset.events_*, UNNEST(event_params) AS param WHERE event_name = 'purchase'; ``

4. Cost Considerations

BigQuery charges for data storage and query processing. While initial usage might be covered under free tiers, extensive querying and large datasets can incur significant costs. Google has information for best practices to help with BigQuery Costs.

"Mastering BigQuery with GA4 isn't about avoiding complexity; it's about using that complexity to reveal clarity and unlock hidden patterns."

>

— Zac Nash, Data Engineer

Mastering BigQuery with GA4 isn't about avoiding complexity; it's about using that complexity to reveal clarity and unlock hidden patterns.

Zac Nash

Data Engineering Director

5.
Understanding Consent Mode

6.
Conclusion

Unlock the full potential of your GA4 data

The BigQuery GA4 daily export schema might seem like a daunting puzzle at first, but with some practice, you'll navigate it like a pro. By understanding the key components and leveraging practical examples, you can unlock the full potential of your GA4 data. So go ahead, put on your detective hat, and explore the rich insights hidden in your data.

If you need a Watson to help crack the case (or Eggs!), drop us a message.

Get Fresh Thinking in your inbox

Get expert insights, event invites, and practical guides on digital marketing - every fortnight, in our newsletter.

This site is protected by reCAPTCHA.
You may unsubscribe from these communications at any time. Please review our Privacy Policy.