From 8c7c3e84cf5db8fc38369ab88285f7029375f326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20Roqu=C3=A9=20Paniagua?= Date: Mon, 19 May 2025 08:40:14 +0000 Subject: [PATCH] Merged PR 5246: Ordered services in HS and added new boolean # Description Improvements on onboarding data: * Hubspot services that clients expressed their interest in are now sorted alphabetically. This is needed for: * A new boolean to compare current active services applied in listings vs. services that captured the interest of the client on onboarding. This can help identify clients that we might need to follow up to ensure all programs are created and applied. # Checklist - [X] The edited models and dependants run properly with production data. - [X] The edited models are sufficiently documented. - [X] The edited models contain PK tests, and I've ran and passed them. - [ ] I have checked for DRY opportunities with other models and docs. - [ ] I've picked the right materialization for the affected models. # Other - [ ] Check if a full-refresh is required after this PR is merged. Related work items: #30249 --- .../cross/int_new_dash_deal_onboarding.sql | 9 ++++++- models/intermediate/cross/schema.yml | 11 +++++++++ models/staging/hubspot/schema.yml | 5 ++-- models/staging/hubspot/stg_hubspot__deals.sql | 24 ++++++++----------- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/models/intermediate/cross/int_new_dash_deal_onboarding.sql b/models/intermediate/cross/int_new_dash_deal_onboarding.sql index f9e3182..ec9cdf1 100644 --- a/models/intermediate/cross/int_new_dash_deal_onboarding.sql +++ b/models/intermediate/cross/int_new_dash_deal_onboarding.sql @@ -278,5 +278,12 @@ select <> services_in_programs_applied_to_listings then true else false - end as has_account_changed_services_applied_in_listings + end as has_account_changed_services_applied_in_listings, + case + when + active_services_in_programs_applied_to_listings + <> expressed_service_interest + then true + else false + end as are_active_services_different_from_expressed_interest from combination_of_sources diff --git a/models/intermediate/cross/schema.yml b/models/intermediate/cross/schema.yml index 012314d..bc91f64 100644 --- a/models/intermediate/cross/schema.yml +++ b/models/intermediate/cross/schema.yml @@ -3931,3 +3931,14 @@ models: although it's also possible that the account has changed from a certain low-level tier to a higher-level one (ex: from Basic Protection to Protection Pro). + + - name: are_active_services_different_from_expressed_interest + data_type: boolean + description: | + True if the services that are currently applied to listings + are different than the ones that were expressed as interest + during onboarding. + This can indicate a potential need for upselling for business + teams to act upon, although it's also possible that the account + has added new services that where not expressed as interest + during onboarding. diff --git a/models/staging/hubspot/schema.yml b/models/staging/hubspot/schema.yml index a7aa896..b692464 100644 --- a/models/staging/hubspot/schema.yml +++ b/models/staging/hubspot/schema.yml @@ -441,8 +441,9 @@ models: The services that captured the interest of the potential client during onboarding calls, for New Dash. This field has been processed by applying a standardized separation - "|" and an upper case. Be aware that this is not how data is - presented in HubSpot. + "|" and an upper case. Additionally, services are ordered alphabetically + for future comparison with Backend data. Be aware that this is not how + data is presented in HubSpot. Not to be confused with the actual services that host has applied. For the later, check backend data. It can be null. diff --git a/models/staging/hubspot/stg_hubspot__deals.sql b/models/staging/hubspot/stg_hubspot__deals.sql index 0f80737..ed45a7e 100644 --- a/models/staging/hubspot/stg_hubspot__deals.sql +++ b/models/staging/hubspot/stg_hubspot__deals.sql @@ -106,20 +106,16 @@ with -- a string with multiple values separated by ; and these can contain -- leading or trailing spaces. -- In the following field we apply a standardization to the - -- values by replacing the separators with | and converting the values - -- to uppercase. The regex applied is: - -- \s* → Matches any leading or trailing spaces. - -- [;] → Matches ; as separator. - -- \s* → Again, ensures spaces around the separator are also replaced. - -- 'g' → Applies the replacement globally (to all occurrences in the - -- string). - upper( - regexp_replace( - {{ adapter.quote("properties") }} ->> 'services', - '\s*[;]\s*', - '|', - 'g' - ) + -- values by replacing the separators with |, converting the values + -- to uppercase and ensuring the final order is alphabetically. + ( + select string_agg(upper(trim(item)), '|' order by upper(trim(item))) + from + unnest( + string_to_array( + {{ adapter.quote("properties") }} ->> 'services', ';' + ) + ) as item ) as expressed_service_interest, {{ adapter.quote("properties") }} as properties, {{ adapter.quote("createdAt") }} as created_at_utc,