Handlebars Helper Function: buildUrl

Creates a URL that includes click tracking. Use this helper to add UTM parameters and custom query parameters to a link.

Availability 

This helper is available in the Winter ’27 release of Marketing Cloud Next.

Syntax 

1{{buildUrl base
2  [encode=true|false] [label=LABEL]
3  [noTracking=true|false] [sfmclinkid=LINK_ID]
4  [sfmclinkalias=LINK_ALIAS] [utm_campaign=CAMPAIGN]
5  [utm_content=CONTENT] [utm_medium=MEDIUM]
6  [utm_source=SOURCE] [utm_term=TERM]
7  [CUSTOM_KEY=CUSTOM_VALUE]
8}}

Parameters 

ParameterTypeDescription
baseStringRequired. The destination URL. The helper function preserves existing query parameters.
encodeBooleanWhen true, URL-encodes parameter values. The default is true. The base URL is never encoded.
labelStringA link alias for tracking. Don’t use with sfmclinkalias.
noTrackingBooleanWhen true, returns the composed URL without click tracking. The default is false.
sfmclinkidStringAn internal link identifier for tracking.
sfmclinkaliasStringA link alias for tracking. Don’t use with label.
utm_campaignStringThe campaign name or identifier.
utm_contentStringA value that differentiates links that point to the same URL.
utm_mediumStringThe marketing medium.
utm_sourceStringThe traffic source.
utm_termStringPaid-search keywords.
CUSTOM_KEYAnyA custom parameter to append to the URL.

Specify all optional parameters as named parameters.

The helper also applies link parameters configured for the content asset and business unit. Values provided directly in buildUrl take precedence over content-level values, which take precedence over business unit values. A direct parameter with a null or blank value removes the parameter from the URL.

Return Value 

The function returns a URL that has click tracking enabled. By default, it adds the composed destination URL to a tracking token. When noTracking=true, the function returns the composed destination URL directly.

If base is missing, null, or empty, the function throws an exception. It also throws an exception if you use a reserved tracking parameter as a custom parameter or specify both label and sfmclinkalias.

Usage Examples 

This example creates a tracked URL with a campaign parameter.

1{{buildUrl product.DetailUrl utm_campaign=$message.campaign.name}}

This example adds a custom parameter and turns off automatic encoding because the value is already encoded.

1{{buildUrl product.DetailUrl token=preEncodedToken encode=false}}

This example creates an untracked URL. Query parameters are still applied.

1{{buildUrl https://www.example.com noTracking=true}}

See Also