diff --git a/samples/attribution_project/models/profiles.yaml b/samples/attribution_project/models/profiles.yaml index 43338b24a..9c967a230 100644 --- a/samples/attribution_project/models/profiles.yaml +++ b/samples/attribution_project/models/profiles.yaml @@ -25,10 +25,12 @@ models: conversion: touchpoints: # Defines the user journey sequence allowing us to evaluatel first, last and multi-touch models - from: inputs/rsMarketingPages + where: 4 < {{user.Var('first_invoice_amount')}} conversion_vars: # What are the activities, outcomes, etc. that we actually want to measure. You can define more than 1. You can also define a value in addition to the count. - name: sf_order timestamp: user.Var('first_order_date') value: user.Var('first_invoice_amount') # Optional - adding this creates an extra column called __value (ex: signup_first_touch_value) + conversion_window: 60d - name: sf_subscription timestamp: user.Var('subscription_start_date') campaign: diff --git a/src/predictions/profiles_mlcorelib/py_native/attribution_report.py b/src/predictions/profiles_mlcorelib/py_native/attribution_report.py index 020ca7aef..a2102e6cd 100644 --- a/src/predictions/profiles_mlcorelib/py_native/attribution_report.py +++ b/src/predictions/profiles_mlcorelib/py_native/attribution_report.py @@ -37,6 +37,7 @@ class AttributionModel(BaseModelType): "type": "object", "properties": { "from": {"type": "string"}, + "where": {"type": "string"}, }, "required": ["from"], "additionalProperties": False, @@ -565,9 +566,18 @@ def _create_user_journey_cte( journey_info_timestamp = material.de_ref( journey_info["from"] ).model.time_filtering_column() - select_info = f"SELECT {entity_id_column_name}, {campaign_id_column_name}, {journey_info_timestamp} AS timestamp" - from_info = f"FROM {{{{{prefix}{counter}}}}}" - where_info = f"WHERE {campaign_id_column_name} is not NULL" + select_info = f"SELECT a.{entity_id_column_name}, a.{campaign_id_column_name}, a.{journey_info_timestamp} AS timestamp" + from_info = f"FROM {{{{{prefix}{counter}}}}} a" + where_info = f"WHERE (a.{campaign_id_column_name} is not NULL)" + + if "where" in journey_info: + if ".Var" in journey_info["where"]: + join_info = f"JOIN {{{{entity_var_table}}}} ON a.{entity_id_column_name} = {{{{entity_var_table}}}}.{entity_id_column_name}" + else: + join_info = "" + + from_info += f" {join_info}" + where_info += f" AND ( {journey_info['where']} )" journey_query = f"""{journey_query} {union_op}