From 6493051db2d804e6f1534f9fb5712ebde9719828 Mon Sep 17 00:00:00 2001 From: David Booke Date: Wed, 30 Oct 2024 12:36:43 -0500 Subject: [PATCH] Use environment variables for project, dataset, property ID when not set as project variables --- macros/base_select.sql | 3 ++- models/staging/src_ga4.yml | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/macros/base_select.sql b/macros/base_select.sql index 8919388f..7603d446 100644 --- a/macros/base_select.sql +++ b/macros/base_select.sql @@ -36,7 +36,8 @@ , ecommerce.transaction_id , items , {%- if var('combined_dataset', false) != false %} cast(left(regexp_replace(_table_suffix, r'^(intraday_)?\d{8}', ''), 100) as int64) - {%- else %} {{ var('property_ids')[0] }} + {%- elif var('property_ids', false) != false %} {{ var('property_ids')[0] }} + {%- else %} {{ env_var('BIGQUERY_PROPERTY_ID') }} {%- endif %} as property_id {% endmacro %} diff --git a/models/staging/src_ga4.yml b/models/staging/src_ga4.yml index 29104767..8f29701d 100644 --- a/models/staging/src_ga4.yml +++ b/models/staging/src_ga4.yml @@ -4,11 +4,13 @@ sources: - name: ga4 database: | # Source from target.project if multi-property, otherwise source from source_project {%- if var('combined_dataset', false) != false -%} {{target.project}} - {%- else -%} {{var('source_project')}} + {%- elif var('source_project', false) != false -%} {{var('source_project')}} + {%- else -%} {{env_var('BIGQUERY_PROJECT')}} {%- endif -%} schema: | # Source from combined property dataset if set, otherwise source from original GA4 property {%- if var('combined_dataset', false) != false -%} {{var('combined_dataset')}} - {%- else -%} analytics_{{var('property_ids')[0]}} + {%- elif var('property_ids', false) != false -%} analytics_{{var('property_ids')[0]}} + {%- else -%} analytics_{{env_var('BIGQUERY_PROPERTY_ID')}} {%- endif -%} tables: - name: events