Skip to content

Commit fb57634

Browse files
committed
add activations counter solution
1 parent 2b1eb76 commit fb57634

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Activations counter
2+
3+
----
4+
## Overview
5+
6+
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.
7+
Simply change the code to adjust the attempt count or the activated record count.
8+
9+
----
10+
## Implementation
11+
1. Copy and paste the code into a custom script in Treasure Workflows.
12+
13+
----
14+
## Considerations
15+
16+
N/A
17+
18+
----
19+
## Questions
20+
21+
Please feel free to reach out to [email protected] with any questions you have about using this code.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
timezone: Asia/Tokyo
2+
3+
_export:
4+
td:
5+
database: activation_counter_db
6+
table: activation_counter_tbl
7+
8+
+echo_activation_actions_parameters:
9+
echo>: segment_id ==> ${segment_id}, segment_name ==> ${segment_name}, activation_id ==> ${activation_id}, audience_id ==> ${audience_id}
10+
11+
+register_count:
12+
td>: queries/count_activated_records.sql
13+
insert_into: ${td.table}
14+
database: ${td.database}
15+
16+
+check_counts:
17+
td>: queries/check_counts.sql
18+
database: ${td.database}
19+
store_last_results: true
20+
21+
+send_email:
22+
if>: ${td.last_results.cnt == 3 && td.last_results.sum == 0}
23+
_do:
24+
mail>: notifications/email.txt
25+
subject: "Treasure Data Activation ${td.last_results.act_id} warning"
26+
27+
html: true
28+
+sent:
29+
echo>: Email sent!
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<html>
2+
<body>
3+
<head>
4+
<style>
5+
/* Reset styles */
6+
body,
7+
h1,
8+
p {
9+
margin: 0;
10+
padding: 0;
11+
}
12+
13+
body {
14+
font-family: Arial, sans-serif;
15+
line-height: 1.6;
16+
background-color: #f9f9f9;
17+
margin: 0;
18+
padding: 0;
19+
}
20+
/* Footer styles */
21+
.footer {
22+
text-align: center;
23+
padding: 20px 0;
24+
background-color: #007bff;
25+
color: #fff;
26+
}
27+
28+
.footer p {
29+
font-size: 14px;
30+
}
31+
/* Button styles */
32+
.button {
33+
display: inline-block;
34+
background-color: #ffffff;
35+
color: #fff;
36+
text-decoration: none;
37+
padding: 10px 20px;
38+
border-radius: 5px;
39+
font-weight: bold;
40+
margin: 30px auto;
41+
}
42+
</style>
43+
</head>
44+
<h1>Treasure Data Activation ${td.last_results.act_id} has not syndicated a single record during its 3 previous runs.</h1>
45+
<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>
46+
<div class="footer">
47+
<p>This email was sent automatically. Please do not reply.</p>
48+
</div>
49+
</body>
50+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SELECT
2+
act_id,
3+
SUM(rec_cnt) AS "sum",
4+
COUNT(1) AS cnt
5+
FROM
6+
(
7+
SELECT
8+
act_id,
9+
rec_cnt
10+
FROM
11+
${td.table}
12+
WHERE
13+
act_id = ${activation_id}
14+
ORDER BY
15+
time DESC
16+
LIMIT 3
17+
)
18+
GROUP BY
19+
act_id
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT
2+
COUNT(1) AS rec_cnt,
3+
${activation_id} AS act_id
4+
FROM
5+
${activation_actions_db}.${activation_actions_table}

0 commit comments

Comments
 (0)