Returns the current ecommerce.items array enriched with list / promotion
attribution previously captured by the Ecommerce Attribution Capture tag.
Drop-in replacement for your raw data-layer items variable as the items
parameter on GA4 Event tags for add_to_cart, view_cart, begin_checkout,
add_shipping_info, add_payment_info, purchase, refund.
GA4's item-level attribution fields (item_list_id, item_list_name,
promotion_id, promotion_name) are typically only present on list/promotion
events. This variable joins them back onto downstream ecommerce events so you
can build true item-level "product listing" and "promotion" attribution reports
and pass the same attribution to Meta CAPI, Google Ads, and BigQuery.
- Reads
ecommerce.itemsfrom the data layer (path is configurable). - Reads the stored attribution blob from
localStorage. - For each item, looks up its stored attribution by
item_id(oritem_nameas fallback). - Merges stored attribution into the item (respecting your Overlay / Override mode and per-field toggles).
- Returns the enriched array. If no attribution is stored, the original
itemsarray is returned unchanged.
This variable is the read side of the storage contract written by the
companion Ecommerce Attribution Capture tag. Both must be installed, and
both must share the same localStorage key.
| Field | Type | Default |
|---|---|---|
| Items data layer path | Text | ecommerce.items |
| localStorage key | Text | bdt_ecom_attr_v1 |
| TTL (minutes) — stale reads filter | Number | 30 |
| Enrichment mode | Radio | Overlay (recommended) / Override |
Enrich item_list_id |
Checkbox | ON |
Enrich item_list_name |
Checkbox | ON |
Enrich promotion_id |
Checkbox | ON |
Enrich promotion_name |
Checkbox | ON |
Enrich page_location |
Checkbox | ON |
Enrich page_type |
Checkbox | ON |
| Optional diagnostic parameter name | Text | empty (e.g. attribution_source) |
| Debug mode | Checkbox | OFF |
- Overlay (recommended): data-layer values on the item always win. Stored attribution only fills fields that are empty on the item. Safest for round-tripping events that legitimately already carry item-level attribution.
- Override: stored attribution always wins over the item's data-layer value. Use only when you know the developers push attribution inconsistently and you want the captured truth to dominate.
If you set Optional diagnostic parameter name to e.g. attribution_source,
every enriched item gets that extra parameter populated with the event name
that produced the attribution (select_item, view_item_list, …). Useful in
audits and BigQuery queries. Off by default to keep the GA4 schema clean. If
you enable this, register the parameter as a GA4 custom dimension (scope: item)
to see it in reports.
access_local_storage— read-only on keys matchingbdt_ecom_attr_*read_data_layer—ecommerce,ecommerce.*logging— debug environment only
- Install from the GTM Community Template Gallery (search for "Ecommerce
Enriched Items"), or import
template.tplmanually. - Install the companion Ecommerce Attribution Capture tag (separate template).
- Create a new User-Defined Variable → type = Ecommerce Enriched Items.
Name it something like
DLV - ecommerce.items (enriched). - On each GA4 Event tag for
add_to_cart,view_cart,begin_checkout,add_shipping_info,add_payment_info,purchase, andrefund, set theitemsevent parameter value to this new variable instead of the raw dataLayer items variable. - Verify in Preview Mode: trigger
select_itemon a category page, navigate to the PDP, and fireadd_to_cart. Theadd_to_carthit in GA4 DebugView should now carryitems[0].item_list_id,item_list_name,page_locationandpage_type.
If any of the following are true for a given item, the item is returned unchanged (safe fallback):
- No stored attribution blob.
- No entry for the item's
item_id(oritem_namefallback). - Stored entry is older than the configured TTL.
- Item has no
item_idand noitem_name.
Apache 2.0. See LICENSE.
File issues on this GitHub repository. Issues must remain enabled per Gallery policy.