Track Custom Events on GA Ecommerce Data layers


I want to create and track Product Detail View as a custom event tag and add Product ID in a variable in one of the Custom Event Data Fields(Category, Action, Name e.g). On our site, we have a standard EEC DataLayer from our setup for GA that is looking like this e.g Product details:


And I also want to do the same for this dataLayer:


The tags and triggers are working as we are getting data in Piwik Pro. However, as you can see the data layer is not being populated with data in Custom event name(where we have the data layer variable grabbing the product ID( and List(

From my understanding in Piwik Pro Tag Manager, it’s not possible to refer to nested attributes of a datalayer object directly.

So my question is, what is the best solution/workaround to populate these fields with data from our datalayers?

Thanks in advance.


if you need to access, you can use a JavaScript variable and either access the latest push or find / filter the specific event that holds the data you need and then return the desired value. Like

return dataLayer[dataLayer.length-1]


return dataLayer[dataLayer.length-1][0].id

for the id of your first ecommerce product. At least this is the only way I know and hope it solves your problem, even if there might be a better solution.


Hi @mbaersch ,

Thanks for the reply. I tried but still got no value(undefined) in the PPTM Debugger. How would the Javascript variable look like to access the latest push or find/filter the specific event?

The code below only returns the value after we access it if I understand you correctly?

return dataLayer[dataLayer.length-1]


it would be the inner part of a JS variable function… but it is not very elegant or error-proof (which is handled by the tag manager) - and only works if the last push to tha dataLayer contains the desired ecommerce information.

You can use the following code in a JS variable to find the last dataLayer push containing an payload and return the actionField. You could adapt that example to filter the dataLayer by event name or anything else to find the data you want to parse and return a specific value from.

function() {
  //access dataLayer
  var dl = window.dataLayer;
  if (!dl) return;
  //filter all dataLayer pushes with
  var eecClicks = dataLayer.filter(function(x){return x && x.ecommerce &&});
  if (!eecClicks) return;
  //use latest push and return actionField.list (if it exists)
  var actionField = eecClicks.slice(-1)[0]||{};
  return actionField.list;

hope that helps


1 Like

Thanks @mbaersch , works like a charm!

1 Like