GA4 ecommerce to UA enhanced ecommerce

Do you want to implement the standardardised GA4 ecommerce datalayer according to Google's developer documentation, while still supporting Universal Analytics' Enhanced Ecommerce functionality? This variable turns a GA4 ecommerce datalayer object into Universal Analytics (GA3) Enhanced Ecommerce format.

GTM variable to convert GA4 ecommerce objects to Universal Analytics enhanced ecommerce format

Description

This variable requires one piece of input: the GA4 ecommerce event name. It is needed to dertermine which enhanced ecommerce object to build. When a valid GA4 ecommerce event is passed, the variable will take the most recent ecommerce object from the datalayer and perform the mapping to enhanced ecommerce format. Objects are created based on the following table:

GA4 ecommerce event name Enhanced ecommerce measurement
view_promotion promoView
select_promotion promoClick
view_item_list impressions
select_item click
view_item detail
add_to_cart add
add_to_wishlist N/A
view_cart N/A
remove_from_cart remove
begin_checkout checkout (step: 1)
add_shipping_info checkout (step: 2, option: shipping_tier)
add_payment_info checkout (step: 3, option: payment_type)
purchase purchase

Some notes on item (product) level mapping:

  • Parameters 'item_category' through 'item_category5' are automatically combined into 'category' (delimited by '/').
  • Enhanced ecommerce variables position and list are only added for the click and detail measurements, since enhanced ecommerce performs product list attribution against product id.
  • If you have any custom item parameters, you can map these to product scoped custom dimensions and/or metrics in the variable. Map to the exact key that enhanced ecommerce expects, so 'dimensionX' or 'metricY'.

Recommended use

An ecommerce tracking implementation suggestion that would work well with this variable:

  • Have all ecommerce datalayer pushes start with 'ecommerce_' and then the event name as needed for GA4.
  • Right before each new ecommerce datalayer push, push {ecommerce: null} to the datalayer to make sure any previous ecommerce object is cleared.
  • Create a custom javascript variable to strip the 'ecommerce_' start from the (built-in) {{Event}} variable, which means it returns the ecommerce event name.
  • Use this variable to provide the GA4 event tag with the correct event name. Also use it as input for the template variable and to send event action in the UA event tag.
  • Trigger the GA4 event tag on all datalayer events that start with 'ecommerce_'.
  • Add all relevant ecommerce parameters to the GA4 tag with datalayer variables. When a certain parameter is not in a datalayer push (such as transaction_id for any event that is not purchase) it will simply be dropped from the hit, which is what you want.
  • Enable enahanced ecommerce on the UA tag, with the option 'Read data from variable'. Use the template variable for that.
  • Trigger the UA tag on all datalayer events that start with 'ecommerce_', but let the trigger fire only when the template variable does not equal undefined.

I have created a demo of the recommendation above, so you can see how it would work.

Check out the demo here

Release notes

Date Notes
2021-11-26 Bug fix for when the purchase event contains a product list.
2021-07-21 Initial release.