Skip to main content

Change the tracking code for each trigger type/stage

Track the source of clicks by changing the campaign code in your cart layout based on the trigger type or stage.

Updated this week

You can change the campaign code in your cart layout to track whether clicks come from a Cart Abandonment, Browse Abandonment, or Purchase Complete email. This method uses Jinja logic to set different values based on the trigger type or the stage of a multi‑stage campaign. You can also combine these conditions to generate unique tracking codes for each type and stage.

To track performance by trigger type or stage, you can:

  • Create separate cart layouts and use a different layout for each trigger or stage, or

  • Set the campaign code dynamically using the example below.


Change the campaign code based on trigger type

Use the trigger.contact_type value to identify whether the email is a Cart Abandonment, Browse Abandonment, or Purchase Complete email.

{% if trigger.contact_type == 'b' %}{# Cart abandon #}
{% set ga_campaign_code = 'tms-cart-1' %}
{% elif trigger.contact_type = 'ba' %}{# Browse abandon #}
{% set ga_campaign_code = 'tms-browse-1' %}
{% elif trigger.contact_type == 't' %}{# Purchase complete #}
{% set ga_campaign_code = 'tms-pc-1' %}
{% endif %}

Change the campaign code based on the trigger stage

Use the active_action_index value to detect which stage of a multi‑stage campaign generated the email.

Example for a two-stage campaign:

{% if trigger.active_action_index < 2 %} {# 1st stage email #}
{% set ga_campaign_code='tms-cart-1' %}
{% else %} {# 2nd stage email -- for a two-stage campaign #}
{% set ga_campaign_code='tms-cart-2' %}
{% endif %}

Example for a three-stage campaign:

{% if trigger.active_action_index < 2 %} {# 1st stage email #}
{% set ga_campaign_code='tms-cart-1' %}
{% if trigger.active_action_index == 3 %} {# 2nd stage email #}
{% set ga_campaign_code='tms-cart-2' %}
{% else %} {# 3rd stage email -- for a three-stage campaign #}
{% set ga_campaign_code='tms-cart-3' %}
{% endif %}

Combining stage and type

You can also combine these two so you can track different trigger types and stages:

{% if trigger.contact_type == 'b' %}{# Cart abandon #}
{% if trigger.active_action_index < 2 %} {# 1st stage email #}
{% set ga_campaign_code='tms-cart-1' %}
{% else %} {# 2nd stage email -- for a two-stage campaign #}
{% set ga_campaign_code='tms-cart-2' %}
{% endif %}
{% elif trigger.contact_type == 'ba' %}{# Browse abandon #}
{% if trigger.active_action_index < 2 %} {# 1st stage email #}
{% set ga_campaign_code='tms-browse-1' %}
{% else %} {# 2nd stage email -- for a two-stage campaign #}
{% set ga_campaign_code='tms-browse-2' %}
{% endif %}
{% endif %}

Apply the tracking code to links

Once you have created the appropriate script to generate the campaign codes, you can include them on the links using the set_ga_tracking filter, like this:

<a href={{ product.u  | set_ga_tracking( utm_campaign=ga_campaign_code , utm_medium='email' , utm_source='tms' ) }}>

Did this answer your question?