This article describes how to set up a repeat trigger on a specific day of the month (for example, the first Tuesday or second Friday of the month) using a repeat trigger followed by a condition node using Jinja.
It isn't possible to use only a repeat trigger for a specific day, so the Jinja code includes a condition that accounts for the timezone offset as well.
How to
Let's assume you want to trigger a campaign only on the first Tuesday of each month, considering the Canada/Eastern timezone. To do so, you can follow these steps:
-
In your scenario, add "Repeat trigger", set it to "Weekly", and pick "Tuesday" as it will trigger only this specific day:
-
Add a condition node and choose the code editor where you insert the Jinja code below:
{% set timezone = 'Canada/Eastern' %} {% set offset = (time - time | from_timestamp('%x %X %f') | to_timestamp('%x %X %f', timezone=timezone)) %} {% set weekday=(time+offset)|from_timestamp('%A') %} {% set week= (time+offset) | from_timestamp('%-W') | int %} {% set day_of_month = (time+offset) | from_timestamp('%-d') | int %} {% if weekday == "Tuesday" and 1 <= day_of_month < 8 %} true {% else %} false {% endif %}
Describing Jinja code and how to adjust it based on your needs
For example, if you want to trigger a campaign on the second Friday of the month, considering the Canada/Eastern timezone, you can follow these steps:
In the first line of the code, you can customize the timezone by changing the value of the timezone variable. For example, you can replace 'Canada/Eastern' with the timezone you want to use for your scenario, such as 'Europe/Prague'. It allows the condition to check dates and times according to your selected timezone. Since Jinja operates in UTC, you must always consider the offset.
{% set timezone = 'Europe/Prague' %}In Jinja code, two conditions need to be satisfied.
- Verifies if today is the day of the week that you want to trigger, using the weekday variable
- Makes sure that it is within the range of days of that week based on the day_of_month variable
If both conditions are true, the customer will continue with the scenario's flow, as they meet the "second Friday of the month" requirements in your chosen timezone. If not, the customer will not proceed in this scenario and will be excluded from this flow. Hence, if you want to trigger only on the second Friday of the month, you can do it by specifying it in the IF condition for the weekday and day_of_month variables like this:
{% if weekday == "Friday" and 8 <= day_of_month < 15 %}
true
{% else %}
false
{% endif %}