Skip to content

Instantly share code, notes, and snippets.

@WouterNieuwerth
Last active August 24, 2023 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WouterNieuwerth/e2d2aef4d3e149ccac11bd237640941b to your computer and use it in GitHub Desktop.
Save WouterNieuwerth/e2d2aef4d3e149ccac11bd237640941b to your computer and use it in GitHub Desktop.
Example SQL with incremental tables
config {
type: "incremental",
description: "Counts the amount of specific events per session per day.",
schema: "monitoring",
tags: ["ga4"],
bigquery: {
partitionBy: "event_date",
}
}
select
CAST(event_date AS DATE FORMAT 'YYYYMMDD') as event_date,
count(distinct concat(user_pseudo_id,(select value.int_value from unnest(event_params) where key = 'ga_session_id'))) as value
from
${ when (incremental(), ref(dataform.projectConfig.vars.GA4_TABLE))}
${ when(!incremental(), `\`${constants.GA4_DATABASE}.${constants.GA4_DATASET}.events_*\``) }
${ when(!incremental(), "where contains_substr(_TABLE_SUFFIX, 'intraday') is not true") }
group by
event_date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment