Step 2: Create Variable in Google Tag Manager
In this step, you'll create a variable in Google Tag Manager that contains the value you want to pass to Ternair.
Instructions
- Open Google Tag Manager
- Go to Variables in the left menu
- Under "User-Defined Variables", click New
- Give the variable a clear name (e.g.,
dlv - Product ID) - Click Variable Configuration
- Choose the correct type:
- Data Layer Variable — for values directly from the dataLayer
- Custom JavaScript — for processed or derived values
- Configure the variable as needed
- Click Save
Variable types
Data Layer Variable
Use this type when the value is directly available in the dataLayer. For example:
ecommerce.items.0.item_iduser.idpage.category
Custom JavaScript
Use this type when you need to process or derive the value. For example, when you need to extract a value from an array.
Example: Custom JavaScript variable
function() {
var ecommerce = {{dlv – ecommerce.items}};
if (ecommerce && ecommerce.length > 0) {
return ecommerce[0].product_id;
}
return null;
}
This function:
- Retrieves the ecommerce items array from the dataLayer
- Checks if there are items
- Returns the
product_idof the first item - Returns
nullif there are no items
Tip
Give your variables a consistent naming convention, for example with prefix dlv - for Data Layer variables or js - for JavaScript variables.
Next step
Go to Step 3: Link Variable to connect the variable to the Ternair tag.