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 Activation Actions #408

Merged
merged 5 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions activation_actions/incremental_wf/README.md
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions activation_actions/incremental_wf/calc_diff.sql
Original file line number Diff line number Diff line change
@@ -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'
60 changes: 60 additions & 0 deletions activation_actions/incremental_wf/incremental_wf.dig
Original file line number Diff line number Diff line change
@@ -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'
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 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)
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}