diff --git a/activation_actions/incremental_wf/README.md b/activation_actions/incremental_wf/README.md new file mode 100644 index 00000000..3196ae12 --- /dev/null +++ b/activation_actions/incremental_wf/README.md @@ -0,0 +1,18 @@ +# Incremental Activation as a Custom workflow for Activation Actions + +Activation Actions enables you to run a user-defined custom workflow to execute these desired actions during an activation process. An instance of this workflow is triggered automatically during every activation event. The overall status of the activation is tied to this integrated workflow. The activation would have a successful status only when both the activation and triggered workflow are successful. By using a custom workflow within the Activation process, you can extend and customize your data activation capabilities to meet specific operational needs. + +For more detail about Activation Actions, please refer to [this doc](https://docs.treasuredata.com/articles/#!pd/activation-actions). + +This example code considers `add` (new profiles) and `delete` (dropped profiles) changes only from your activated profiles. When there is no difference between the profile of the current run and the previous run, the diff table won’t be generated. The attributes used here (e.g., profile_id) are just for example - user may have to use their attributes in the queries according to the data schema in the context + +## How to use this workflow for Activation Actions + +1. Download this folder into your local. +2. Upload the workflow `td wf push incremental_wf` (Require td command installation) +3. Change key_column field in incremental_wf.dig depending on your required watermark. (Default: td_client_id) +4. Set `incremental_wf` as a custom workflow of the Activation Action in Audience Studio. + +## Available Parameters for Activation Actions + +On Treasure Workflow, various built-in parameters are available for Workflow and SQL files. Please refer to [Doc](https://docs.treasuredata.com/articles/#!pd/activation-actions-parameters) diff --git a/activation_actions/incremental_wf/calc_diff.sql b/activation_actions/incremental_wf/calc_diff.sql new file mode 100644 index 00000000..530a35a2 --- /dev/null +++ b/activation_actions/incremental_wf/calc_diff.sql @@ -0,0 +1,18 @@ +INSERT INTO diff +SELECT * FROM ( + SELECT DISTINCT + '${session_id}' as session_id, + '${attempt_id}' as attempt_id, + CASE + WHEN h.${key_column} IS NULL THEN 'add' + WHEN a.${key_column} IS NULL THEN 'delete' + ELSE 'modified' -- no change or modified + END as change + , coalesce(h.${key_column}, a.${key_column}) as ${key_column} + FROM + previous_profiles h + FULL OUTER JOIN ${activation_actions_table} a + ON h.${key_column} = a.${key_column} +) +WHERE + change != 'modified' \ No newline at end of file diff --git a/activation_actions/incremental_wf/incremental_wf.dig b/activation_actions/incremental_wf/incremental_wf.dig new file mode 100644 index 00000000..4ceca2b8 --- /dev/null +++ b/activation_actions/incremental_wf/incremental_wf.dig @@ -0,0 +1,60 @@ +_export: + td: + database: '${activation_actions_db}' + key_column: 'td_client_id' # Pleaes update your key id for diff + +# tables: +# - 'previous_profiles': table that contains the profiles of the previous run +# - '${activation_actions_table}': table that contains the profiles of the current run +# - 'diff': table that contains the diff between the previous and the current run +# - 'diff_history': table that contains all the diffs from the beginning + ++preparation: + td_ddl>: + create_tables: ["previous_profiles", "diff_history"] + ++cleanup_intermindate_table: + td_ddl>: + empty_tables: ['diff'] + ++preparation_schema_previous_profiles: + td>: + query: "ALTER TABLE IF EXISTS previous_profiles ADD COLUMN IF NOT EXISTS ${key_column} varchar; ALTER TABLE IF EXISTS previous_profiles ADD COLUMN IF NOT EXISTS change varchar;" + ++preparation_schema_diff: + td>: + query: "ALTER TABLE IF EXISTS diff ADD COLUMN IF NOT EXISTS ${key_column} varchar; ALTER TABLE IF EXISTS diff ADD COLUMN IF NOT EXISTS change varchar;" + ++calc_diff: + td>: calc_diff.sql + +# +# do the actual activation(s) +# + ++activation_for_added_profiles: + td>: + query: "SELECT * FROM ${activation_actions_table} WHERE ${key_column} in (SELECT ${key_column} FROM diff WHERE change = 'add')" + # result_connection: 'authentication-1' + # result_settings: 'authentication-1-setting-1' + # Enable above if you want to activate to the setting 1 + ++activation_for_deleted_profiles: + td>: + query: "SELECT * FROM previous_profiles WHERE ${key_column} in (SELECT ${key_column} FROM diff WHERE change = 'delete')" + # result_connection: 'authentication-2' + # result_settings: 'authentication-2-setting-1' + # Enable above if you want to activate to the setting 2 + ++insert_diff_into_history: + td>: + query: "INSERT INTO diff_history SELECT * FROM diff;" + ++drop_diff: + td_ddl>: + drop_tables: ['diff', 'previous_profiles'] + ++insert_profiles_into_history: + td>: + query: "SELECT '${session_id}' as session_id, '${attempt_id}' as attempt_id, * FROM ${activation_actions_table};" + create_table: 'previous_profiles' \ No newline at end of file diff --git a/activation_actions/restrict_and_add_column/README.md b/activation_actions/restrict_and_add_column/README.md new file mode 100644 index 00000000..9b77aa99 --- /dev/null +++ b/activation_actions/restrict_and_add_column/README.md @@ -0,0 +1,17 @@ +## Restrict and Add Column using Custom Workflow for Activation Actions + +Activation Actions enables you to run a user-defined custom workflow to execute these desired actions during an activation process. An instance of this workflow is triggered automatically during every activation event. The overall status of the activation is tied to this integrated workflow. The activation would have a successful status only when both the activation and triggered workflow are successful. By using a custom workflow within the Activation process, you can extend and customize your data activation capabilities to meet specific operational needs. + +For more detail about Activation Actions, please refer to [this doc](https://docs.treasuredata.com/articles/#!pd/activation-actions). + +This sample code restricts the profiles output by using a filter in Custom Workflow for Activaiton Actions. + +### How to use + +1. Download this folder into your local. +2. Upload the workflow `td wf push restrict_and_add_column` (Require td command installation). Default: Email is defined as exported field. +3. Set `restrict_and_add_column` as a custom workflow of the Activation Action in Audience Studio. + +## Available Parameters for Activation Actions + +On Treasure Workflow, various built-in parameters are available for Workflow and SQL files. Please refer to [Doc](https://docs.treasuredata.com/articles/#!pd/activation-actions-parameters) diff --git a/activation_actions/restrict_and_add_column/activate_restricted.sql b/activation_actions/restrict_and_add_column/activate_restricted.sql new file mode 100644 index 00000000..1461aabc --- /dev/null +++ b/activation_actions/restrict_and_add_column/activate_restricted.sql @@ -0,0 +1 @@ +SELECT *, 'gmail' as domain FROM ${activation_actions_table} WHERE email like '%gmail%' \ No newline at end of file diff --git a/activation_actions/restrict_and_add_column/restrict_and_add_column.dig b/activation_actions/restrict_and_add_column/restrict_and_add_column.dig new file mode 100644 index 00000000..357b546d --- /dev/null +++ b/activation_actions/restrict_and_add_column/restrict_and_add_column.dig @@ -0,0 +1,9 @@ +_export: + td: + database: '${activation_actions_db}' + ++activation_for_added_profiles: + td>: activate_restricted.sql + result_connection: ${result_connection_name} + result_settings: ${result_connection_settings} + \ No newline at end of file