Build dbt models for web session quality analysis with engagement scoring, conversion probability, and behavioral analytics to optimize digital marketing spend and identify UX improvement opportunities.
harbor run -t snowflake-labs/web-session-quality-scoringharbor download snowflake-labs/web-session-quality-scoringBuild dbt models for web session quality analysis with engagement scoring and conversion probability.
Add dbt models to the existing dbt project that create web session quality metrics.
/app/dbt_models_duckdb/models//app/dbt_models_snowflake/models/This task supports both DuckDB and Snowflake. Run echo $DB_TYPE in a shell BEFORE you write any code or spawn any subagents — the live env determines which backend the verifier runs against. Do NOT assume a default from this prose. Both /app/dbt_models_duckdb/ and /app/dbt_models_snowflake/ exist on disk; the verifier only checks the project matching the live $DB_TYPE.
DB_TYPE=duckdb$DUCKDB_PATH (default: /app/database/retail.duckdb)DB_TYPE=snowflakeSNOWFLAKE_ACCOUNTSNOWFLAKE_USERSNOWFLAKE_PASSWORDSNOWFLAKE_DATABASE - The clone database to useSNOWFLAKE_SCHEMASNOWFLAKE_WAREHOUSESNOWFLAKE_ROLE (optional)Note: For Snowflake, the entrypoint automatically creates a clone database and sets SNOWFLAKE_DATABASE. The clone is destroyed when the task completes.
You must configure dbt to connect to the database:
profiles.yml in the dbt project directory with profile name retail_dw_masterDBT_PROFILES_DIR environment variable to the directory containing profiles.ymlConfigure with type: duckdb and the database path from $DUCKDB_PATH.
Configure with type: snowflake using password authentication:
schema: to $SNOWFLAKE_SCHEMA — do NOT leave it blank. A blank or omitted schema makes Snowflake silently default to PUBLIC, so your models get built in the wrong schema and the verifier cannot find them.Use existing staging models: stg_digital__* in models/staging/digital/
models/intermediate/digital/)One row per session_id from stg_digital__web_page_views and stg_digital__web_events.
| Column | Description |
|---|---|
| session_id | Group key |
| total_pageviews | Total page views for this session |
| unique_pages_viewed | Number of distinct pages viewed |
| total_time_on_pages_seconds | Total time spent on pages, default 0 |
| avg_scroll_depth_percent | Average scroll depth across all page views, default 0 |
| product_page_views | Number of page views with page_type = 'PRODUCT' |
| category_page_views | Number of page views with page_type = 'CATEGORY' |
| cart_page_views | Number of page views with page_type = 'CART' |
| checkout_page_views | Number of page views with page_type = 'CHECKOUT' |
| add_to_cart_events | Number of events with event_type = 'ADD_TO_CART' |
| video_play_events | Number of events with event_type = 'VIDEO_PLAY' |
| search_events | Number of events with event_type = 'SEARCH' |
One row per session_id from stg_digital__shopping_carts.
| Column | Description |
|---|---|
| session_id | Group key |
| cart_created | TRUE if session has a cart |
| cart_item_count | Maximum item count in cart, default 0 |
| cart_subtotal | Maximum cart subtotal, default 0 |
| cart_converted | TRUE if cart was converted |
One row per session_id from stg_digital__web_page_views, stg_digital__shopping_cart_items, and stg_digital__wishlist_items.
| Column | Description |
|---|---|
| session_id | Group key |
| unique_products_viewed | Count of distinct product_id from product page views |
| products_added_to_cart | Count of distinct variant_id added to cart in this session |
| products_wishlisted | Count of distinct variant_id added to wishlist in this session |
| cart_item_quantity | Total quantity of items added to cart, default 0 |
| avg_product_price | Average unit_price of items added to cart, default 0 |
| has_high_value_item | TRUE if any cart item unit_price > 100 |
| wishlist_to_cart_ratio | products_wishlisted divided by products_added_to_cart, default 0 if no cart items |
| product_interest_score | Weighted score: (unique_products_viewed x 2) + (products_added_to_cart x 5) + (products_wishlisted x 3), capped at 100, rounded to 2 decimals |
models/marts/digital/)One row per session_id from stg_digital__web_sessions with int_session_engagement and int_session_cart_activity.
| Column | Description |
|---|---|
| session_id | From stg_digital__web_sessions |
| visitor_id | From stg_digital__web_sessions |
| customer_id | From stg_digital__web_sessions, NULL if anonymous |
| session_start | From stg_digital__web_sessions |
| session_date | Date of session start |
| session_duration_seconds | From stg_digital__web_sessions.duration_seconds |
| session_duration_minutes | Duration in minutes, rounded to 2 decimals |
| page_views | From stg_digital__web_sessions.page_views |
| unique_pages_viewed | From int_session_engagement |
| landing_page | From stg_digital__web_sessions |
| device_type | From stg_digital__web_sessions |
| utm_source | From stg_digital__web_sessions, NULL if not available |
| utm_medium | From stg_digital__web_sessions, NULL if not available |
| utm_campaign | From stg_digital__web_sessions, NULL if not available |
| traffic_source | utm_source if available, otherwise 'direct' |
| product_views_count | From int_session_engagement.product_page_views |
| added_to_cart | TRUE if session has cart activity |
| cart_value | From int_session_cart_activity.cart_subtotal, default 0 |
| did_convert | TRUE if session or cart converted |
| engagement_score | Weighted engagement score (see below) |
| is_bounce | TRUE if single page view with duration under 10 seconds |
| bounce_type | 'IMMEDIATE' if bounce under 3 seconds, 'SHORT_VISIT' if bounce, NULL otherwise |
| conversion_probability | Predicted conversion probability (see below) |
| session_quality_tier | 'HIGH' if engagement_score >= 70, 'MEDIUM' if >= 40, 'LOW' otherwise |
| expected_value | conversion_probability multiplied by 150.0 |
One row per visitor_id from stg_digital__web_sessions with int_session_product_interest.
| Column | Description |
|---|---|
| visitor_id | Group key |
| total_sessions | Count of sessions for this visitor |
| sessions_with_product_views | Count of sessions where unique_products_viewed > 0 |
| total_products_viewed | Sum of unique_products_viewed across all sessions |
| avg_products_per_session | total_products_viewed divided by total_sessions, rounded to 2 decimals |
| total_products_carted | Sum of products_added_to_cart across all sessions |
| total_products_wishlisted | Sum of products_wishlisted across all sessions |
| cart_conversion_rate | Sessions with cart divided by total_sessions, rounded to 2 decimals |
| wishlist_preference_score | total_products_wishlisted divided by (total_products_carted + total_products_wishlisted), default 0, rounded to 2 decimals |
| browse_to_action_ratio | total_products_viewed divided by (total_products_carted + total_products_wishlisted), default 0 if no actions, rounded to 2 decimals |
| high_value_shopper | TRUE if has_high_value_item in any session |
| visitor_segment | Categorize visitor behavior (see below) |
| first_session_date | Earliest session_start date |
| last_session_date | Latest session_start date |
| days_active | Days between first and last session, default 0 if single session |
Weighted composite score capped at 100:
Round to 2 decimals. Default 0 for NULL values.
Score based on session behavior:
Round to 2 decimals.
Categorize visitors based on behavior patterns: