Skip to content

Instantly share code, notes, and snippets.

@thomashandorf
thomashandorf / bqml_ga4.sql
Created December 18, 2023 08:34
BigQuery ML ARIMA Model on GA4 purchase data
CREATE OR REPLACE MODEL `your-project.arima_test.purchase_forecast`
OPTIONS(model_type='ARIMA_PLUS', time_series_timestamp_col='date', time_series_data_col='daily_purchases')
AS
SELECT
PARSE_DATE('%Y%m%d', event_date) as date,
COUNTIF(event_name = 'purchase') as daily_purchases
FROM
`bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE
_TABLE_SUFFIX BETWEEN '20201101' AND '20211231'