Skip to content

Commit

Permalink
add activations counter solution
Browse files Browse the repository at this point in the history
  • Loading branch information
tdroberto committed Jan 27, 2025
1 parent 2b1eb76 commit fb57634
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scenarios/activations_counter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Activations counter

----
## Overview

This project provides a solution to notifying a TD user by email that the last 3 activation attempts of a given activation have not activated any records.
Simply change the code to adjust the attempt count or the activated record count.

----
## Implementation
1. Copy and paste the code into a custom script in Treasure Workflows.

----
## Considerations

N/A

----
## Questions

Please feel free to reach out to [email protected] with any questions you have about using this code.
29 changes: 29 additions & 0 deletions scenarios/activations_counter/activation_counter.dig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
timezone: Asia/Tokyo

_export:
td:
database: activation_counter_db
table: activation_counter_tbl

+echo_activation_actions_parameters:
echo>: segment_id ==> ${segment_id}, segment_name ==> ${segment_name}, activation_id ==> ${activation_id}, audience_id ==> ${audience_id}

+register_count:
td>: queries/count_activated_records.sql
insert_into: ${td.table}
database: ${td.database}

+check_counts:
td>: queries/check_counts.sql
database: ${td.database}
store_last_results: true

+send_email:
if>: ${td.last_results.cnt == 3 && td.last_results.sum == 0}
_do:
mail>: notifications/email.txt
subject: "Treasure Data Activation ${td.last_results.act_id} warning"
to: [[email protected]]
html: true
+sent:
echo>: Email sent!
50 changes: 50 additions & 0 deletions scenarios/activations_counter/notifications/email.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<html>
<body>
<head>
<style>
/* Reset styles */
body,
h1,
p {
margin: 0;
padding: 0;
}

body {
font-family: Arial, sans-serif;
line-height: 1.6;
background-color: #f9f9f9;
margin: 0;
padding: 0;
}
/* Footer styles */
.footer {
text-align: center;
padding: 20px 0;
background-color: #007bff;
color: #fff;
}

.footer p {
font-size: 14px;
}
/* Button styles */
.button {
display: inline-block;
background-color: #ffffff;
color: #fff;
text-decoration: none;
padding: 10px 20px;
border-radius: 5px;
font-weight: bold;
margin: 30px auto;
}
</style>
</head>
<h1>Treasure Data Activation ${td.last_results.act_id} has not syndicated a single record during its 3 previous runs.</h1>
<h2><a href="https://console-next.treasuredata.com/app/ps/${audience_id}/e/${segment_id}/sb/ac/${activation_id}/ea" class="button">Visit the Activation</a></h2>
<div class="footer">
<p>This email was sent automatically. Please do not reply.</p>
</div>
</body>
</html>
19 changes: 19 additions & 0 deletions scenarios/activations_counter/queries/check_counts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SELECT
act_id,
SUM(rec_cnt) AS "sum",
COUNT(1) AS cnt
FROM
(
SELECT
act_id,
rec_cnt
FROM
${td.table}
WHERE
act_id = ${activation_id}
ORDER BY
time DESC
LIMIT 3
)
GROUP BY
act_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT
COUNT(1) AS rec_cnt,
${activation_id} AS act_id
FROM
${activation_actions_db}.${activation_actions_table}

0 comments on commit fb57634

Please sign in to comment.