Template: GA4 Items Array to Dynamic Remarketing Format
GTM variable template that transforms GA4 ecommerce items array into Google Ads dynamic remarketing format, supporting multiple business verticals including retail, travel, flights, hotels, education, and jobs.
General Description
This template transforms ecommerce data from Google Analytics 4 (GA4) dataLayer into a format compatible with remarketing needs, adapting the data structure based on the business sector (google_business_vertical).

Resources
| GitHub Repository |
| Template Gallery |
Input
The script expects the following input data:
Use Data Layer: Checkbox that determines the data source, set totrueBusiness Vertical: String that identifies the business sectorGA4 Items: Array of objects containing item data. Follows the GA4 schema
Execution Flow
Data Acquisition
const ecommerce = copyFromDataLayer('ecommerce'); const ga4Items = data.useDataLayer ? ecommerce.items : data.items;- Retrieves data from dataLayer
- Selects appropriate data source based on
useDataLayercheckbox
Validation
if (!ga4Items) return;- Verifies that items exist for processing
Data Transformation The
rmktItemsfunction processes each item applying the following transformations:- Creates a base object with common properties
{ id: item.item_id, google_business_vertical: businessVertical }- Adds specific properties based on
google_business_vertical
Supported Business Verticals
The variable supports the following business sectors:
- Retail
- Education
- Flights
- Hotel and rental
- Job listings
- Local deals
- Real estate
- Travel
- Custom
For the sectors described below, specific parameters will be searched in the input array:
Jobs and Education Sector
Triggers: 'education', 'jobs'
{
id: item.item_id,
google_business_vertical: businessVertical,
location_id: item.location_id
}Travel Sector
Triggers: 'flights', 'hotel_rental', 'travel'
{
id: item.item_id,
google_business_vertical: businessVertical,
origin: item.origin,
destination: item.destination,
start_date: item.start_date,
end_date: item.end_date
}Output
The script returns an array of transformed objects, where each object contains:
- Base properties always present (
id,google_business_vertical) - Additional properties specific to the business sector
Usage Example
// Input data
const data = {
useDataLayer: true,
businessVertical: 'travel',
items: [
{
item_id: '12345',
origin: 'ROM',
destination: 'LON',
start_date: '2024-01-01',
end_date: '2024-01-07',
},
],
};
// Resulting output
[
{
id: '12345',
google_business_vertical: 'travel',
origin: 'ROM',
destination: 'LON',
start_date: '2024-01-01',
end_date: '2024-01-07',
},
];Important Notes
- The script handles different business categories differently
- Additional fields are only included if relevant to the specific sector
- No validation is performed on optional fields
- The
idandgoogle_business_verticalfields are always present in the output - The input array must have keys named the same as those expected in output. For example, the
start_dateparameter in output must also be present in the input array; if the key name is different, it will not be considered.