Velocity script tokens as an alternative for dynamic content | Community
Skip to main content
Michaela_Iery3
Level 3
August 14, 2016

Velocity script tokens as an alternative for dynamic content

Following up on @Kristen Carmean's awesome blog post with great examples of Velocity scripting, I’ve got another example of a basic email token Velocity script that allows you to serve up dynamic content without segmentation or snippets.

While Marketo's segmentation functionality is terrific, there are times when it isn't what you need when you want to deliver dynamic content based on the customer's data. Especially when the dynamic content you need isn't based on an either/or scenario like salutations (Mr. v. Ms. or U.S. v. Canada).

I’ve had multiple requests for a use case similar to the following:

A lead fills out a form or otherwise has data in their record indicating interest in multiple products/topics/requests. The lead can choose more than one topic, making segmentation and snippets undesirable, as you can be in only one segment at a time within a segmentation and building a segmentation for each topic area is not always feasible in many Marketo instances. The lead then receives an email response with dynamic content based on the topics they requested.

For our example here, we will be a fictional company offering a variety of dog-related topics (Training Tips, Toys and Accessories, Nutrition and Health and Adoptions) that customers can get a monthly email update about by registering via a form. This data about their interest is captured in individual custom fields in Marketo, though it could also be associated with the lead via CRM fields as well.

We will send out an email auto response confirming the topics they signed up for and providing a brief update on each topic. Only the topics they signed up for will be in the email copy.

To accomplish this, we leverage very basic Velocity #if and #end functionality. (If the value is “X,” make this text appear and then end the script.) You can do this all within one token and have the script address each value one after the other. In this case, our fields = "1" when a lead has selected that topic.

#if (${lead.mktoAdoptionsandRescues} == "1")

Adoptions and Rescues: Meet our latest furry friend, Charlotte, who is available for adoption. Charlotte is a mature, 7-year-old basset hound who would love nothing more than finding her forever home and would do well…

#end

#if (${lead.mktoToys} == "1")

Toys and Products: All of our dog companions here are just wild about the new backyard tug toy  from ACME Dog. Your dog gets all of the yanking and pulling play time he love, without the strain on your arms…

#end

#if (${lead.mktoTrainingTips} == "1")

Training Tips: Are you saying "Down" but the rest of your household says "Off"? Consistency is key to your dog understanding what you want. We've got a top 10 list of dog training Dos and Donts …

#end

#if (${lead.mktoNutrition} == “1”)

Nutrition and Health: Dogs can get the flu too – it’s time to start thinking about Fido’s annual vaccination. Talk with your vet about…

#end

I’ve saved this email script token as {{my.Dog Content Updates}} and have placed the token within the body of the email.Note that in my own record, I have only signed up for the Adoptions and Training topics, and those are the only pieces of content that appear, and without obvious space/breaks between the topic script pieces that don’t apply.

Bonus Tip One: Not strong on html writing? (Neither am I.) Build an email where you write and format the copy as you like it. Embed links, create bolded headlines, etc. Then go into the html of that email and copy the text as formatted. For example, the script piece for Adoptions actually is in my token as

<p><b>Adoptions and Rescues</b><br>

Meet our latest furry friend, Charlotte, who is available for adoption. Charlotte is a mature, 7-year-old basset hound who would love nothing more than finding her forever home. <a href="http://www.cbhr.com" target="_blank">Learn more</a>...</p> (Depending on how your email template is se

Bonus Tip Two: Consider your content carefully. Each topic/brand/request needs to be able to stand alone, as the lead may or may not have requested two that you are tying together. Also consider content length – if each piece is long and the lead signs up for all of them, this could make for a very long, unwieldy email (and depending on your email template, might look a bit clunky). For the same reason, I would be cautious about the total number of topics/brands/requests that can be selected in this type of delivery. It’s a balancing act – the more topics, the shorter the content should be. I might only use 4-5 for a content piece like the above, where you’re delivering almost newsletter “blurb” pieces of content of a few sentences. For an email that is simply listing a customer’s selections without additional content (say, confirming someone’s subscription choices without providing content for them), you might be able to get away with 10-12 choices.

I should add that I'm not in the least fluent in Velocity script - but I suspect many of you may be in the same boat. This is just a simple script token that I think can be applied in many typical, fairly straightforward use cases for Marketo.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

16 replies

October 9, 2017

Thank you. Here's the thread: Advanced dynamic content

Translate
SanfordWhiteman
Level 10
October 9, 2017

If you open a new thread in Products I'll answer over there.

Translate
October 9, 2017

Great Tip - thanks.

I have one question though - how would the code/approach change if all the information would be stored in one, not separate fields in Marketo?

For example - I have a form in a landing page where people have to select their pet preferences (bird, cat, dog, pig) and they can select multiple pets. My goal would then be to send them a thank you email mentioning their pet and giving link for additional information.

I tried making segments and added dynamic content to the email template, but that approach seems to not really work if there are several values/ifs.

As far as I know - it's not also possible to edit the Marketo Form field that each checkbox/answer goes to a separate field in Marketo database - all the selected information can go to one particular field, not several.

So I guess the only way would be this approach described here only changing the code slightly? Switching from "=="to "contains"?

Translate
Neil_Robertson6
Level 4
August 21, 2016

There is no question that Velocity is great feature but it does have its fairly significant drawbacks - can't be used with Snippets, spome of the more useful VTL libs are not switched to name a few.

Translate
SanfordWhiteman
Level 10
August 18, 2016

Not about Velocimacros yet. Starting smaller with maps/dictionaries.  Also put this up in the interim, as you know: http://blog.teknkl.com/marketo-vtl-strings-all-the-way-down/

Translate
Neil_Robertson6
Level 4
August 18, 2016

To remove any of the gaps in content created by velocity - add a ## at the of each variable you output - this will remove it.

Translate
Nicholas_Manojl
Level 8
August 16, 2016

Well I officially have your blog in my feed now so I look forward to that.

also.. is it about macros? I have to test that out..

Translate
SanfordWhiteman
Level 10
August 16, 2016

I find the opposite. As I'm describing in my blog post, stacking everything in a big script leads people to add newlines to break up components for easier reading. Problem is those newlines actually end up in the email, where they can create maddening layout bugs.

I actually agree with Nicholas about separating large text blocks, but I'm also looking at a wider "architectural" approach.  Will post the link here when it's published!

Translate
Michaela_Iery3
Level 3
August 16, 2016

Hi, @Nicholas Manojlovic​:

I have taken that approach in the past and it can be useful - but I've also found that unlike the all-in-one approach, it can create "gaps" in the content. But I would defer to @Sanford Whiteman​ on the reasons why that might occur, as he definitely knows script better than I do!

Translate
SanfordWhiteman
Level 10
August 16, 2016

I sort of agree, sort of don't. 

Let's see if my next blog post can convince you to use a different way entirely.

Translate