Re: Velocity Script a trackable URL?

Adam_Glasser1
Level 1

Velocity Script a trackable URL?

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:  http://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-to...  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

6 REPLIES 6
Casey_Grimes
Level 10

Re: Velocity Script a trackable URL?

Hi Adam,

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

<a href='http://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 - Community Moderator

Re: Velocity Script a trackable URL?

Adam_Glasser1
Level 1

Re: Velocity Script a trackable URL?

Hi Courtney,

I am confused about what you mean by "last line". I have tried inserting that line into the velocity code in my {{my.token}} and in the html of my email, and neither are working for me. Can you expand on this a little more?

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script a trackable URL?

Meaning you must emit *the entire <a> tag from Velocity* including the closing </a> and everything in between.

You don't generate only a URL in VTL, but the full link. Then you plug {{my.token name}} into the email where the link should go.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script a trackable URL?

You should read all the seminal Velocity + Marketo posts at

     https://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 1

Re: Velocity Script a trackable URL?

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.