diff --git a/activation_actions/incremental_wf.dig/README.md b/activation_actions/incremental_wf.dig/README.md new file mode 100644 index 00000000..4db87524 --- /dev/null +++ b/activation_actions/incremental_wf.dig/README.md @@ -0,0 +1,17 @@ +# 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 td_load_gcs` (Require td command installation) +3. Set `incremental_wf.dig` 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.dig/calc_diff.sql b/activation_actions/incremental_wf.dig/calc_diff.sql new file mode 100644 index 00000000..a1c105fd --- /dev/null +++ b/activation_actions/incremental_wf.dig/calc_diff.sql @@ -0,0 +1,20 @@ +SELECT * FROM ( + SELECT DISTINCT + '${session_id}' as session_id, + '${attempt_id}' as attempt_id, + CASE + WHEN h.profile_id IS NULL THEN 'add' + WHEN a.profile_id IS NULL THEN 'delete' + ELSE '???' -- no change or modified + END as change + , coalesce(h.profile_id, a.profile_id) as profile_id + --, h.* + --, a.* + FROM + previous_profiles h + FULL OUTER JOIN ${activation_actions_table} a + ON h.profile_id = a.profile_id +) +WHERE + change <> '???' +; \ No newline at end of file diff --git a/activation_actions/incremental_wf.dig/incremental_wf.dig b/activation_actions/incremental_wf.dig/incremental_wf.dig new file mode 100644 index 00000000..ec170e6c --- /dev/null +++ b/activation_actions/incremental_wf.dig/incremental_wf.dig @@ -0,0 +1,47 @@ +_export: + td: + database: '${activation_actions_db}' + +# 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'] + +# +# do the actual activation(s) +# + ++activation_for_added_profiles: + td>: + query: "SELECT * FROM ${activation_actions_table} WHERE profile_id in (SELECT profile_id 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 profile_id in (SELECT profile_id 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: "CREATE TABLE previous_profiles AS SELECT '${session_id}' as session_id, '${attempt_id}' as attempt_id, * FROM ${activation_actions_table} ;" \ 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..1d2c7ecc --- /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 td_load_gcs` (Require td command installation) +3. Set `restrict_and_add_column.dig` 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_restricteed.sql b/activation_actions/restrict_and_add_column/activate_restricteed.sql new file mode 100644 index 00000000..1461aabc --- /dev/null +++ b/activation_actions/restrict_and_add_column/activate_restricteed.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