How do I implement "setEcommercView" with Tag Manager?

Hi all,
I’m currently trying to implement: a “trackPageView” after “setEcommerceView” (since
Calling trackPageView is required when tracking a product view, see https://matomo.org/docs/ecommerce-analytics/#tracking-product-page-views-category-page-views-optional).

I created

  • a “Matomo Analytics” Tag
  • a custom HTML Tag, containing setEcommerceView.

Unfortunately the 1st Tag is always fired BEFORE the 2nd Tag.

I achieved it:

  1. Custom HTML Tag (ProductDetail as data layer variable):
<script>
window._paq = window._paq || [];
console.log({{ProductDetail}});

if ({{ProductDetail}}) {
var productDetail = {{ProductDetail}};
window._paq.push(['setEcommerceView',
productDetail.sku, 
productDetail.name,
productDetail.categories,
productDetail.price 
]);
}
</script>
  1. Set Pageview trigger for both tags: Matomo Analytics and Custom HTML Tag. Advanced setting for Custom HTML Tag: priority = 100 (<999)

Is there a way so that my Custom HTML Tag doesn’t have to be fired on every page?

Thanks in advance!

Your Custom HTML should be only triggered if there is eg. a productdetail page event.
To do this you must send a data layer push only on any product detail page.
This information can be provided via a static data layer which exists before Tag Manager is loaded.

1. // Static Data Layer //
2. _mtm.push({
        'event': 'productDetailView',
    });
3. // Matomo Tag Manager Script //

The Custom HTML is only triggered if the event is pushed to the data layer.

Try it out.
Could be that there are some timing issues.
But even then you could set up a tag which pushes the ‘event’: ‘productDetailView’, only on pages with a specific URL-path and with some delay…

Many many options. :smiley:
But try to control it via the back-end if possible.

Many thanks @Trackingninja for your suggestions.
I started with an event 'productDetailView" in the data layer. The custom HTML tag was only fired at this event, but unfortunately too late (after Matomo Analytics Tag with ‘trackPageView’). Same thing with a trigger for a specific url path.

Advanced setting for tags only seem to work within the same trigger.

So it’s all about timing.

I image you can create an exception for the standard Pageview?
That this one should not be triggered if there is a productDetailView event before.

Create another trigger for your standard Pageview.
This one fire if it’s a product detail page on dom ready or window loaded.

Or try to control the rules via a separate script.

So you can ensure your ecommerve view is pushed before, and any other Tag is fired afterwards.