SQL Queries

  • SQL To Compare GA4 Events Against Previous Activity

    This query is preparing your GA4 event data for session reconstruction. The goal is: “For every event, look at the event immediately before it for the same user.” That allows you to detect: You start with raw GA4 events like this: user_pseudo_id event_timestamp source A 10:00 google A 10:05 google A 11:00 facebook B…

  • Calculating Sessions in BigQuery GA4: Addressing Discrepancies

    Calculating the number of sessions in BigQuery GA4 provides immense flexibility and granularity. However, it can often lead to discrepancies when compared to the GA4 user interface (UI). Understanding these differences and how to mitigate them is key to accurate analysis. How to Calculate Sessions in BigQuery GA4 The most accurate and robust method…

  • How to Calculate GA4 Sessions in BigQuery: A Simple Step-by-Step Guide

    Google Analytics 4 (GA4) stores event-based data in BigQuery, where sessions are derived from event timestamps and session identifiers. Below are the steps to calculate the number of sessions from GA4 BigQuery exports, including an example SQL query. Step 1: Understanding Sessions in GA4 Step 2: Writing the SQL Query Use the following SQL…