Skip to main content
These snippets solve problems marketers usually handle with Marketo My Tokens: tracking links, the current year, a safe greeting. Paste one into the email’s design, then change the field names to match your template. For the fields you can use, see the Merge field reference.

Build a campaign name for UTM parameters

Turn a copy field such as name into a lowercase, dash-separated value. “Spring Sale: 20% Off!” becomes spring-sale-20-off.
If your campaign names contain only letters and spaces, a shorter version works:
The short version keeps punctuation. “Spring Sale: 20% Off!” becomes spring-sale:-20%-off!, which breaks in many analytics tools. Add one remove for each character your names use. Use the button’s label as utm_content so reports show which button got the click.
“See the report” becomes see-the-report. A link might already have a question mark. Check before you add the first parameter.

Dates and times

send.sentAt is the moment the email sends. Use it instead of typing a date, so a nurture email stays correct for years. For other days, change 604800, which is seven days in seconds. One day is 86400.

Count the days until an event

Subtract the send time from the event time, then round up with ceil.
Date math returns decimals unless you finish with ceil or floor. Without it, you can see “7.6 days”. ceil rounds up, so 7.6 becomes 8.

Find the Nth weekday of a month

Say your community meets on the 4th Wednesday of each month, and you want the invite to state the date without anyone typing it. Set the week number and the weekday at the top. The weekday is a number: Sunday is 0, Monday is 1, up to Saturday as 6.
The recipe finds the first day of the month, counts how far it is to your weekday, and then adds whole weeks. It works for any week from 1 to 4. Week 5 does not exist in every month, so avoid it. To invite people to next month’s meeting, start from next month instead of the send month:
Put these lines in place of the first ym line above and keep the rest. A send in December gives a January date in the next year.

Greet by time of day

Read the hour in the recipient’s own time zone.
If a person has no time zone on file, the hour uses the platform’s time zone, so some people see the wrong greeting. Use a neutral greeting for lists with many blank time zones.

Greetings and fallbacks

Fall back when a name is blank

Each default applies when the field to its left is empty. This chain tries first name, then company, then a plain greeting.

Drop a blank name from the subject

A subject like ”, your report is ready” looks broken. Print the name and its comma only when a name exists.

Pull a first name or domain out of another field

The first returns the first word of the full name. The second returns the part of the email after the at sign, such as acme.com.

Clean text

Merge fields aren’t escaped for you. A company name with an ampersand or a quote can break the HTML around it. Add escape to any person field you place inside text or an attribute.

Singular or plural

More than two outcomes

Add elsif branches, or use case when you test one field.