Velocity Script a trackable URL? | Community
Skip to main content
Adam_Glasser1
Level 2
October 3, 2018
Question

Velocity Script a trackable URL?

  • October 3, 2018
  • 2 replies
  • 5565 views

Currently, we are using velocity scripting within a my.token to pull data from a field within a custom object in Marketo. The data is an order number, which populates a portion of a URL so that when we send a link we can reference a specific order within our database.

The URL looks like this:  printingforless1.com/ps/Survey/NPS?order= {{my.Order Number}}

The velocity script for {{my.Order Number}} looks like this:

#if( $pFLOrders_cList && !$pFLOrders_cList.isEmpty() )

#set( $firstItem = $pFLOrders_cList[0] )

#set( $lastItem = $pFLOrders_cList[$math.sub($pFLOrders_cList.size(),1)] )

#end

$lastItem.orderNumber


This is working fine when we are not tracking link clicks, but when I do click the button to track clicks this link stops working when I trigger the email to go out on a test lead. It will however work when I preview the email as that same test lead. I saw in this post https://nation.marketo.com/message/191133-re-marketo-tracking-links-breaking-when-velocity-script-tokens-used#comment-19…  that this is a known issue, and that we need to velocity script the entire URL. I have been reading through Marketo's developer resources on email scripting, as well as the Velocity User Guide, and am still quite confused about how to write this script.

Does anyone have suggestions on developers who may be interested in taking on a project this small? Or standard velocity code I might be able to use to velocity script this entire URL?

Thank you!

Adam

2 replies

Casey_Grimes2
Level 10
October 3, 2018

Hi Adam,

You're already 90 percent of the way there; you just need to alter your last line to

<a href='printingforless1.com/ps/Survey/NPS?order=$lastItem.orderNumber'>Take our NPS survey</a>

or similar, and then just place that token where you'd place the link.

SanfordWhiteman
Level 10
October 3, 2018
SanfordWhiteman
Level 10
October 3, 2018

You should read all the seminal Velocity + Marketo posts at

     blog.teknkl.com/tag/velocity


To your direct question, you absolutely can include tracked links in Velocity-generated content. Across my instances, this happens 100,000+ times per day, at least.

The problems occur when you try to use the same Velocity variable to generate multiple <a> tags. Because of the way Marketo introspects the output from the Velocity parser, that won't work. When doing this, you unfortunately have to follow poor programming practices and preallocate different variables, up to the max number of links you will support in a single email (instead of using the same var in a loop, or properties of an object, or a list, since those all use the same variable).

Adam_Glasser1
Level 2
October 5, 2018

Thanks Sanford, I will take a look at this. In the case of this email, I only want to track a singly velocity generated link.