This Variable for Google Tag Manager Server-side (SGTM) turns the Ecommerce Item array (e.g. [{item_id: '12', quantity: 1},{item_id: '34', quantity: 2}]) into a string (e.g. '12|34'), or sums Item Values (e.g 3). When summing values you can choose to multiply the value with quantity (e.g. [{price: 10, quantity: 1},{price: 20, quantity: 2}]) which will give the result 50).
This Template is available in the Google Tag Manager Template Gallery.
- Select Mapping Method
- GA4 Standard Ecommerce Events
- Custom Mapping
- Select Item Parameter Type & Action
- Create String from Item Parameter
- Standard Item Parameters
- Custom Item Parameters
- Choose Delimiter
- Return Unique Items
- Sum Values from Item Parameter
- Standard Item Parameters
- Custom Item Parameters
- Multiply Item Value with Item Quantity
- Create String from Item Parameter
A similiar Variable for Google Tag Manager (Web) does also exist:
Mapping can be done using GA4 Standard Ecommerce Events or Custom Mapping.
Mapping simply means that only values that are mapped should return a result.
Image shows how to map using GA4 Standard Ecommerce Events.
Image shows how to do Custom Mapping.
- Type in the value in the Custom Parameter Field that should be matched against the selected Variable. This means the Selected Variable should be able to return the value in this field.
- Select Variable to map against.
Image shows how to Create a String from a Custom Item Parameter. Choosing Standard Item Parameters can be done using the Select Item Type dropdown.
In the example Unique Items are returned. E.g. [{item_color: 'Blue'},{item_color: 'Red'},{item_color: 'Blue'}] will return the result 'Blue|Red'.
Image shows how to Sum Item Values using Standard Item Parameters. You can also use Custom Item Parameters to sum values.
In this example price will be multiplied with quantity.
Image shows how to Create Strings using Custom Mapping and Custom Item Parameters.
Image shows how to Sum Item Values using GA4 Standard Ecommerce Events and Standard Item Parameters.