Skip to content

How to create a link tracking profile

This article shows you how to create a link tracking profile, so tracking parameters are added to the links in your emails automatically.

A link tracking profile is a set of query parameters, such as utm_source and utm_campaign, that EmailShepherd adds to links when an email is exported. You decide whether each parameter always has the same value, or whether the person building the email fills it in. Nobody has to add the parameters to each link by hand.

The profile is applied to links in url fields and rich_text fields. To track other links in a component, see The track_link filter.

  1. In the sidebar, click Dynamic Content, then select the Link Tracking Profiles tab.
  2. Click Add Link Tracking Profile.
  3. In Name, enter a name for the profile, e.g. “Newsletter UTMs”.
  4. Click Add Parameter for each parameter you want to add to links. For each one:
    1. In Parameter, enter the parameter’s name as it appears in the URL, e.g. utm_source.
    2. In Value type, choose where the value comes from:
      • Fixed Value: the same value is added to every link. Enter it in Value, e.g. newsletter.
      • Editor Field Value: the person building the email enters a value for each link.
      • Editor Component Instance Field Value: the person building the email enters one value for each component, which is used for every link in it.
      • Editor Global Field Value: the person building the email enters one value for the whole email, which is used for every link in it.
    3. For the editor value types, you can also enter a Label (optional) to show in the editor instead of the parameter name, and a Hint (optional) to show below the input, e.g. “Use the campaign name in lowercase”.
  5. Click Save Changes.

To apply the profile to an email, see How to add link tracking to an email.

By default, the profile adds each parameter to the end of the link, e.g. https://example.com/?utm_source=newsletter. If you need the link built a different way, such as with values from the email itself, use a custom template.

A custom template is written in Liquid. Whatever the template outputs becomes the tracked link. In the template, you can use:

  • url_value: the link as it was entered in the editor.
  • parameters: the values of the parameters you added to the profile, e.g. parameters.utm_source.
  • render_context: details about the email and component the link is in. See the render context for everything it contains.

To use a custom template:

  1. In the link tracking profile, select Use a custom template.
  2. In Custom template, enter your template.
  3. In Test URL, enter a link to check the template against. The Preview shows the link the template creates.
  4. Click Save Changes.

This template does the same as the default, for two parameters named utm_source and utm_campaign:

{%- if url_value contains '?' -%}
{%- assign first_separator = '&' -%}
{%- else -%}
{%- assign first_separator = '?' -%}
{%- endif -%}
{{- url_value -}}{{first_separator}}utm_source={{parameters.utm_source | url_encode}}&utm_campaign={{parameters.utm_campaign | url_encode}}

Here’s what each part does:

  • The if block checks whether the link already has a query string. If it does, the parameters are added after an &. If not, they start with a ?.
  • {{- url_value -}} outputs the original link.
  • {{parameters.utm_source | url_encode}} outputs the value of the utm_source parameter. The url_encode filter makes sure characters such as spaces are safe to use in a link.

The - inside {%- and -%} removes the spaces and line breaks around each tag, so the template outputs the link on one line.

This template doesn’t need any parameters in the profile. It sets utm_campaign to the email’s name, and utm_content to the name of the component the link is in:

{%- if url_value contains '?' -%}
{%- assign first_separator = '&' -%}
{%- else -%}
{%- assign first_separator = '?' -%}
{%- endif -%}
{{- url_value -}}{{first_separator}}utm_campaign={{render_context.email.name | url_encode}}&utm_content={{render_context.component_instance.component_name | url_encode}}

Because each link records the component it’s in, you can tell which one a recipient clicked, even when the same link appears more than once in an email.

Section titled “Example: track links differently for each locale”

You can use Liquid’s if tag to build links differently depending on the email. This template checks the email’s locale:

{% if render_context.email.locale == 'en-US' %}
{{url_value}}...
{% else %}
{{url_value}}...
{% endif %}

Replace ... with the parameters for each locale.

  1. In the sidebar, click Dynamic Content, then select the Link Tracking Profiles tab.
  2. Beside the profile, click the edit icon or the delete icon.
    • Edit: change the profile, then click Save Changes.
    • Delete: confirm that you want to delete the profile.