SOLVED

Re: Referencing Program Token in Email Scripting Token

Go to solution
LP_IMS_KJB_7016
Level 2

Referencing Program Token in Email Scripting Token

Good afternoon,

 

I would like to understand how to reference a Text Token within an Email Script Token, both within the same Email Program.

 

The Email Program contains 3 Text tokens that are used to set UTM values - {{my.UTM-Campaign}}, {{my.UTM-Source}}, & {{my.UTM-Medium}} - and each token contains a string value, e.g. em_20241113, mkto & email-organic.

 

These tokens are used elsewhere within the Program and email content but I would also like to utilise them in an Email Script token also within the same Program.

 

For context, the Email Script Token builds href URLs to be inserted into HTML, using a combination of hard coded elements, lead fields (language & country) and Product IDs, which are extracted from a SFDC Custom Product Object linked to the Person object, i.e. each person can have multiple product preferences and the email displays an image and Product name for each associated product both with the constructed URL included to allow recipients to navigate to the relevant product webpage.

 

Once the URL has been constructed, I want to append the UTM parameters and want to understand how those Text Tokens can be referenced within the Email Script Token.

 

I am currently hard-coding the values as follows and this method works when I use those variable further into the script to construct the appended UTM string:

 

## Set UTM values from Program tokens
#set( $utmSource = "marketo" )
#set( $utmMedium = "email-organic" )
#set( $utmCampaign = "em-reports")

 ## Set URL
#set( $uRLFull = "www.webpage.com/" )
#set( $uRLUTM = "?utm_source=${utmSource}&utm_medium=${utmMedium}&utm_campaign=${utmCampaign}" )
#set( $uRLBuild = "${uRLFull}${uRLUTM}" )

<a href="https://${uRLBuild}" target="_blank" style="font-weight:700; color:#16293F; text-decoration:none">

 

I have attempted the following approaches to retrieve the token values from the Text Program tokens but to no avail:

 

## 1st Attempt - Failed
#set( $utmSource = ${my.UTM-Source} )
#set( $utmMedium = ${my.UTM-Medium} )
#set( $utmCampaign = ${my.UTM-Campaign})

## 2nd Attempt - Failed
#set( $utmSource = $my.UTM-Source )
#set( $utmMedium = $my.UTM-Medium )
#set( $utmCampaign = $my.UTM-Campaign)

## 3rd Attempt - Failed
#set( $utmSource = {{my.UTM-Source}} )
#set( $utmMedium = {{my.UTM-Medium}} )
#set( $utmCampaign = {{my.UTM-Campaign}} )

 

Could you please advise on how I can correctly reference the 3 text Program tokens within the Email Script token and create the full required URL, including the 3 UTM parameters?

 

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Referencing Program Token in Email Scripting Token

Nope, that won’t work. That’s a reference to the Velocity object $my with property UTM-campaign, which will not exist.

 

You need to output the Text {{my.token}} in-between Velocity #define and #end, known among experts as the “defineburger” technique.

 

Velocity token {{my.grab utm_campaign}}:

 

#define( $my_utm_campaign )

 

 

Velocity token {{my.end grab token}}:

 

#end

 

 

Then include in this order:

 

{{my.grab utm_campaign}}
{{my.utm_campaign}}
{{my.end grab token}}

 

 

View solution in original post

5 REPLIES 5
ABabb_1
Level 2

Re: Referencing Program Token in Email Scripting Token

Hi @LP_IMS_KJB_7016,

 

It has been a while since I set up something similar, but it looks like you are missing quotations on your second attempt.

Try the below:

#set($utmSource = "${my.UTM-Source}")
#set($utmMedium = "${my.UTM-Medium}")
#set($utmCampaign = "${my.UTM-Campaign}")
SanfordWhiteman
Level 10 - Community Moderator

Re: Referencing Program Token in Email Scripting Token

Nope, that won’t work. That’s a reference to the Velocity object $my with property UTM-campaign, which will not exist.

 

You need to output the Text {{my.token}} in-between Velocity #define and #end, known among experts as the “defineburger” technique.

 

Velocity token {{my.grab utm_campaign}}:

 

#define( $my_utm_campaign )

 

 

Velocity token {{my.end grab token}}:

 

#end

 

 

Then include in this order:

 

{{my.grab utm_campaign}}
{{my.utm_campaign}}
{{my.end grab token}}

 

 

LP_IMS_KJB_7016
Level 2

Re: Referencing Program Token in Email Scripting Token

Hi @SanfordWhiteman & @ABabb_1,

 

thank you both for your replies and apologies for the delayed response.

 

As per your advice @SanfordWhiteman, I created the following:

 

{{my.grab utm-source}}:

#define( $my_utm_source )

 

{{my.end grab token}}:

#end

 

And the existing {{my.UTM-Source}}:

marketo

I incorporated all of the above as stipulated and attempted to reference the defined variable ($my_utm_source ) in a subsequent #set statement in the {{my.Product-Preferences}} token as follows:

## Set the UTM values from Program tokens

## Retrieve the UTM-Source token value to be used below
{{my.grab utm_source}}
{{my.UTM-Source}}
{{my.end grab token}}

#set( $utmMedium = "email-organic" )
#set( $utmCampaign = "em-investment-reports")

#set( $uRLUTM = "?utm_source=${my_utm_source}&utm_medium=${utmMedium}&utm_campaign=${utmCampaign}" )

 

However, when I reference that token in the email, the literal values appear as per the defineburger statements

LP_IMS_KJB_7016_2-1732111686068.png

LP_IMS_KJB_7016_4-1732111902015.png

Please advise where I am going amiss?

 

Regards

 

 

 

 

LP_IMS_KJB_7016
Level 2

Re: Referencing Program Token in Email Scripting Token

Good morning @SanfordWhiteman,

 

would it be possible to review my previous response please. I appreciate your input to date and would be grateful if you're able to assist with this requirement.

 

Kind regards

SanfordWhiteman
Level 10 - Community Moderator

Re: Referencing Program Token in Email Scripting Token

Not completely clear from your post, but it seems like you misinterpreted my suggestion.

 

The “defineburger” is used in the email or template itself. Not in a Velocity token.

 

That is, you create the 2 Velocity tokens for begin and end.

 

Then in the email you put

{{my.begin}}
{{my.whatever else you want to read into Velocity}}
{{my.end}}