Add scripts to your Trigger program to ensure emails are sent only once or within specific timeframes.
If you have content in a particular stage of your Trigger program that you only want to send to a person once, add script to the Trigger program to check the person's history and ensure the email is only sent if they haven't received it before.
For example, if the second stage email in your cart abandonment program contains a coupon code with a short expiry, you might want to prevent that email from being sent more than once, so the expiry message isn't always seen after the first send.
Script to send email only once
Place the below script into the field on the Trigger Program labeled Script that controls whether the second action is run:
result.proceed = false;
var actions = person.actions;
var target_stage_sends = 0;
if (actions) {
for (i = 0; i < actions.length; i++) {
var action = actions[i];
// only check email queued actions
if (action.type && action.type == 1) {
// check trigger programs type, where b = cart, ba = browse, t = purchase
if (action.program && action.program.program_type && action.program.program_type == 'b') {
// check for trigger stage, where 1 = stage 1, 3 = stage 2, 5 = stage 3
if (action.program.action_index && action.program.action_index == 3) {
target_stage_sends += 1;
}
}
}
}
if (!target_stage_sends) {
result.proceed = true;
}
}
Script to send email if not received in the past 6 months
Alternatively, you can choose to only send the second stage email if someone has not received it within the past six months:
result.proceed = false;
var actions = person.actions;
var target_stage_sends = 0;
var now = new Date();
if (actions) {
for (i = 0; i < actions.length; i++) {
var action = actions[i];
// only check email queued actions
if (action.type && action.type == 1) {
// check trigger programs type, where b = cart, ba = browse, t = purchase
if (action.program && action.program.program_type && action.program.program_type == 'b') {
// check for trigger stage, where 1 = stage 1, 3 = stage 2, 5 = stage 3
if (action.program.action_index && action.program.action_index == 3) {
// check the date/time of the action
if (action.dt) {
var action_date = new Date(action.dt);
// check if matching action was within the last 6 months, in milliseconds
if ((now.getTime() - action_date.getTime()) < 15552000000) {
target_stage_sends += 1;
}
}
}
}
}
}
// only send if there were no matching actions
if (!target_stage_sends) {
result.proceed = true;
}
}