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 constant properties for conversion metrics #410

Closed
wants to merge 5 commits into from

Conversation

WilliamDee
Copy link
Contributor

@WilliamDee WilliamDee commented Jan 19, 2023

Change

Follow up on #352 by adding a new configuration constant_properties

constant_properties:
  - name: _string_ # optional.
     base_expr: _string_ # optional. Even if name above is expressed. defaults to name above. solves for role also
     conversion_expr: _string_ # same as base above

This allows users to specify properties to constant when calculating conversion metrics.

Example with Data

Suppose we hold a constant property session_id and we have an opportunity table (visits) and conversion table (buy) as follows,

VISITS
| date       | session_id  | user |
|:-----------|-------------|-----:|
| 2022-12-31 | s1          |    u1| <-- Successful conversion to BUY1
| 2023-01-03 | s2          |    u1| <-- Not a conversion (However, this would be a successful conversion if we didn't hold session_id constant as it is the closer than above to the BUY1 event)
| 2023-01-09 | s3          |    u2| <-- Not a conversion
| 2023-01-12 | s4          |    u2| <-- Successful conversion to BUY2

BUYS
| date       | session_id  | user |
|:-----------|-------------|-----:|
| 2023-01-05 | s1          |    u1| <-- BUY1
| 2023-01-13 | s4          |    u2| <-- BUY2

SQL Example

By adding a constant_property, we would append a new column reference to the partition by that and append a new AND condition to the join

SELECT
  distinct first_value(subq_0.ds) OVER (PARTITION BY subq_1.ds, subq_1.user_id, subq_1.constant_property ORDER BY subq_0.ds DESC) AS visit_ds
  , first_value(subq_0.user_id) OVER (PARTITION BY subq_1.ds, subq_1.user_id, subq_1.constant_property ORDER BY subq_0.ds DESC) AS visit_user
  , first_value(subq_0.referrer_id) OVER (PARTITION BY subq_1.ds, subq_1.user_id, subq_1.constant_property ORDER BY subq_0.ds DESC) AS visit_referrer_id
  , ...
  , subq_1.*
FROM {mf_test_session_state.mf_system_schema}.fct_visits subq_0
INNER JOIN {mf_test_session_state.mf_system_schema}.fct_buys subq_1
ON
  (
    subq_0.user_id = subq_1.user_id
  ) AND (
    subq_0.ds <= subq_1.ds AND subq_0.ds > subq_1.ds - INTERVAL 7 day
  ) AND (
    subq_0.constant_property = subq_1.constant_property
  )

@WilliamDee WilliamDee changed the base branch from main to will/conversion-metrics January 19, 2023 21:04
@WilliamDee WilliamDee force-pushed the will/constant-properties branch from 348b4f3 to ddd11c2 Compare January 19, 2023 21:19
@WilliamDee WilliamDee requested a review from tlento January 23, 2023 20:08
@WilliamDee WilliamDee force-pushed the will/conversion-metrics branch 2 times, most recently from 57fc8ec to 865ec0c Compare January 26, 2023 20:24
@WilliamDee WilliamDee force-pushed the will/constant-properties branch from ddd11c2 to dd09ccc Compare January 26, 2023 21:34
Copy link
Contributor

@tlento tlento left a comment

Choose a reason for hiding this comment

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

See base PR, just annotating things.

@WilliamDee
Copy link
Contributor Author

reopened in #916

@WilliamDee WilliamDee closed this Dec 30, 2023
@WilliamDee WilliamDee deleted the will/constant-properties branch October 7, 2024 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants