Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add user_id and session_number to session tables #189

Merged
merged 7 commits into from
Apr 27, 2023
Merged

Conversation

dgitis
Copy link
Collaborator

@dgitis dgitis commented Apr 26, 2023

Description & motivation

The way that our tables are currently architected, we can't get a daily user count and returning users without querying the client and user tables that aren't partitioned.

In order to let people get these metrics, this PR adds user_id and session_number to the fct_ga4__sessions_daily and fct_ga4__sessions tables.

This will allow users to get new and returning users by running queries like count(distinct case when session_number = 1 then ifnull(user_id, client_key) else null end) as new_users or count( distinct ifnull(user_id, client_key)) as users against the sessions table and not query all data for all time.

Checklist

  • [y ] I have verified that these changes work locally
  • [n/a ] I have updated the README.md (if applicable)
  • [ n/a ] I have added tests & descriptions to my models (and macros if applicable)
  • [ y] I have run dbt test and python -m pytest . to validate existing tests

@@ -4,18 +4,20 @@ select
client_key,
session_key,
stream_id,
user_id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of a multi-day session, user_id could be null on day 1 and have a value on day 2. This would result in 2 rows with the same session_key. Should we take the max(user_id) here as well?

@adamribaudo-velir
Copy link
Collaborator

@dgitis take a look at my updates and feel free to merge if they look good.

@dgitis
Copy link
Collaborator Author

dgitis commented Apr 27, 2023

I seem to have failed to commit changes that added max(user_id) to both models and that addressed the column name error. My apologies.

@dgitis dgitis merged commit c274f98 into main Apr 27, 2023
@dgitis dgitis deleted the session-enhancements branch April 27, 2023 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants