Using GA4 datalyer


Hi all,

I would like to set up Amplitude and migrate from GA4 to Amplitude. One of our prerequisites would be that Amplitude supports the GA4 datalayer for e-commerce events. As far as I have seen the datalayer is not supported, is this correct?


Our shop automatically pushes a datalayer object once an action has been triggered by the user. For example, a view_item event when a product detail page is viewed.

dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
event: "view_item",
ecommerce: {
currency: "USD",
value: 7.77,
items: [
item_id: "SKU_12345",
item_name: "Stan and Friends Tee",
affiliation: "Google Merchandise Store",
coupon: "SUMMER_FUN",
discount: 2.22,
index: 0,
item_brand: "Google",
item_category: "Apparel",
item_category2: "Adult",
item_category3: "Shirts",
item_category4: "Crew",
item_category5: "Short sleeve",
item_list_id: "related_products",
item_list_name: "Related Products",
item_variant: "green",
location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
price: 9.99,
quantity: 1

In other GTM templates, the datalayer is supported so we can use a datalayer variable to retreive data like this “ecommerce.currency (for the currency), ecommerce.value (to get the price) and ecommerce.items (to get the item scoped dimensions). 

How can I pass that information to Amplitude? If it is only one product I can easily use a datalayer variable to pass information like that ecommerce.items.0.item_id but we also have events like view_cart where we have multiple items to capture.


Best answer by dangrainger 16 March 2023, 17:21

View original

10 replies

Userlevel 3
Badge +8

Hi @Marius. We’ve done a similar migration, moving from GA Universal Analytics to Amplitude. When it comes to replicating GA’s Enhanced Ecommerce feature you’ll want to use Amplitude’s object arrays:

You can define whatever object array you like for splitting, pass whatever data points you like in it, and pass it with any event you like…so it’s way more powerful and flexible than Enhanced Ecom over in GA. As far as I’m aware the object arrays can’t just use GA’s ecommerce array from the data layer, so you’ll need to do a bit of work to convert/ freshly implement, but it’s certainly worth the effort.


Hi @dangrainger thanks for your answer. I read the article but I am not sure if I got it correctly.
Is there any documentation to use Custom HTML tags instead of the Amplitude GTM template because with the template we are unable to use the ecommerce.items object?

Maybe using Custom HTML tags would be an option so we can use Javascript to break down the ecommerce.items datalayer and push data to Amplitude. Would that be an option?

I found the following code in their documentation:

// Track a basic event

// Track events with optional properties
const eventProperties = {
item_id: '{{dlayer - ecommerce.item_id}}',
item_name: '{{dlayer - ecommerce.item_name}}',
item_brand: '{{dlayer - ecommerce.item_brand}}',
item_category: '{{dlayer - ecommerce.item_category}}',
// ....
amplitude.track('add_to_cart', eventProperties);

I don’t know if it is possible but to loop through the items array to push all relevant data to Amplitude. In the begin_checkout or purchase datalayer push we can have multiple items but I don’t find any examples of how Amplitude needs this kind of data.

Userlevel 3
Badge +8

I must have been low on coffee yesterday, ignore what I said…

Re-reading the above, you can create a data layer variable in GTM (or whatever TMS you’re using) that captures ecommerce.items from your data layer pushes. Then in the Amplitude tags for these ecom events, add an event property called products (or similar, choose what works for you) and assign the ecommerce.items variable as the value. Once you’ve got this published, Amplitude will take in the ecommerce.items array….head to that event property in the Data module of Amplitude and you’ll see a splitting option which you need to activate (

If you’ve got this working, you’ll see a bunch of new event properties appear in your Amplitude data schema which will match the elements of your GA items array (so you’ll see products.item_id, products.item_name….products.quantity). You’ll also see the full array retained as just the products variable.

Should work, and should be the quickest/ easiest way for you to get your GA4 items array into Amplitude. Note that I don’t think you can change the display name of the split out properties (yet)….so if you want the UI to display something like products.colour rather than products.item_variant you’re best requesting this feature from Amplitude for them to add to their list.


Hi @dangrainger , thanks for the update. Just to make sure. I will set up the GTM tag as seen in the screenshot and Amplitude will populate automatically key-values from the ecommerce.items array in the Amplitude dashboard after using the split option? Renaming the key-values is not important for us but thanks for letting me know.


Userlevel 3
Badge +8

Yeah that should work. Given you’ve called the variable for splitting “items” you’ll get items.item_id, items.item_name...etc as the variables it creates after the splitting


Thanks @dangrainger : I created all ecomm events and will check out these options once the data is populated in the dashboard. 

One of the most important tags is of course the revenue tracking. In the GTM template Amplitude offeres a tag type “revenue”. 

I am not really sure how to set up this one. GA4 uses a transcation_id to deduplicate purchases. How does Amplitude do this? Is it also possible to use the ecommerce.items array as event properties here? Should “Product Price” be the sum of all products? Same for quantity?



Hi @dangrainger , I tried to follow the documentation but I am not able to find the splitting option. Maybe I need coffee as well..


Userlevel 3
Badge +8

Might be this…



Thanks, I reached out to Amplitude. Do you have an idea about the revenue tracking?

Userlevel 3
Badge +8

Yes, we use it lots. And during implementation discovered from Amplitude solution consultants that you don’t need to fire a separate “revenue” tag type. Instead, we pass the revenue in our “booking confirmation” event tags as event properties like this…



...and yes you do need the dollar signs there for it to work. FYI that Amplitude currently only displays $ in the UI, but I’ve been assured that other currency symbols are being launched this quarter if you’re not using dollars.

In the above it’s passing a revenue amount for the booking, while the quantity field is 1 (for the transaction, NOT the number of items in the transaction). Once that’s in Amplitude you can configure custom metrics….things like (in our case) “Bookings", “Revenue”, “Average Booking Value”, and so on. You can build segmentation in to these custom metrics too….if for example you wanted a metric “Purchase Type X Revenue”, you can insert Purchase Type X as a condition in the metric builder.