In order to track the source of clicks and see how each abandonment type and stage is performing, you can either:
Create separate cart layouts and use a different one for each trigger/stage
or set the campaign code by using/adapting the code below in your cart template (put it at the top).
Change the campaign code based on trigger type
To track whether clicks are coming from a Cart or Browse Abandonment email, or a Purchase Complete email, you can look at the contact type:
{% 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
To track whether clicks are coming from each stage of a multi-stage campaign, you can look at the active action index:
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 %}
Applying 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' ) }}>