---
schema_version: "1"
id: 887606d94569af64246ce2405c823eb36f7ce636fbe15ac8a277b2cc1e8b6d52
title: "Handlebars Helper Function: buildUrl"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/handlebars/reference/content/mcn-handlebars-reference-content-buildurl.md
canonical_url: https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-content-references/mcn-handlebars-reference-content-buildurl.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7733276b04b24b5e188b7403aee520ce67086f61456f6514d756e2aacac59c3e
products:
  - Handlebars for Marketing Cloud Next
  - Marketing Cloud
---
# 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

```
{{buildUrl base
  [encode=true|false] [label=LABEL]
  [noTracking=true|false] [sfmclinkid=LINK_ID]
  [sfmclinkalias=LINK_ALIAS] [utm_campaign=CAMPAIGN]
  [utm_content=CONTENT] [utm_medium=MEDIUM]
  [utm_source=SOURCE] [utm_term=TERM]
  [CUSTOM_KEY=CUSTOM_VALUE]
}}
```

## Parameters

| Parameter       | Type    | Description                                                                                        |
| --------------- | ------- | -------------------------------------------------------------------------------------------------- |
| `base`          | String  | Required. The destination URL. The helper function preserves existing query parameters.            |
| `encode`        | Boolean | When `true`, URL-encodes parameter values. The default is `true`. The `base` URL is never encoded. |
| `label`         | String  | A link alias for tracking. Don't use with `sfmclinkalias`.                                         |
| `noTracking`    | Boolean | When `true`, returns the composed URL without click tracking. The default is `false`.              |
| `sfmclinkid`    | String  | An internal link identifier for tracking.                                                          |
| `sfmclinkalias` | String  | A link alias for tracking. Don't use with `label`.                                                 |
| `utm_campaign`  | String  | The campaign name or identifier.                                                                   |
| `utm_content`   | String  | A value that differentiates links that point to the same URL.                                      |
| `utm_medium`    | String  | The marketing medium.                                                                              |
| `utm_source`    | String  | The traffic source.                                                                                |
| `utm_term`      | String  | Paid-search keywords.                                                                              |
| `CUSTOM_KEY`    | Any     | A 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.

```handlebars
{{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.

```handlebars
{{buildUrl product.DetailUrl token=preEncodedToken encode=false}}
```

This example creates an untracked URL. Query parameters are still applied.

```handlebars
{{buildUrl https://www.example.com noTracking=true}}
```

## See Also

- [encodeURI](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/hb_http_helpers/mcn-handlebars-reference-http-encodeuri.md)
- [encodeURIComponent](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/hb_http_helpers/mcn-handlebars-reference-http-encodeuricomponent.md)
