Skip to content

Commit

Permalink
Add Activation Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
toru-takahashi committed Jul 16, 2024
1 parent 83bf2e8 commit 381fb9f
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 0 deletions.
17 changes: 17 additions & 0 deletions activation_actions/incremental_wf.dig/README.md
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 20 additions & 0 deletions activation_actions/incremental_wf.dig/calc_diff.sql
Original file line number Diff line number Diff line change
@@ -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 <> '???'
;
47 changes: 47 additions & 0 deletions activation_actions/incremental_wf.dig/incremental_wf.dig
Original file line number Diff line number Diff line change
@@ -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} ;"
17 changes: 17 additions & 0 deletions activation_actions/restrict_and_add_column/README.md
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT *, 'gmail' as domain FROM ${activation_actions_table} WHERE email like '%gmail%'
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 381fb9f

Please sign in to comment.