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:
ecommerce.click.products.0.id
And I also want to do the same for this dataLayer:
ecommerce.click.actionField.list
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(ecommerce.click.products.0.id) and List(ecommerce.click.actionField.list).
if you need to access ecommerce.click.actionField.list, 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
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.
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?
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 ecommerce.click 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 ecommerce.click
var eecClicks = dataLayer.filter(function(x){return x && x.ecommerce && x.ecommerce.click});
if (!eecClicks) return;
//use latest push and return actionField.list (if it exists)
var actionField = eecClicks.slice(-1)[0].ecommerce.click.actionField||{};
return actionField.list;
}