Ecommerce tracking with GTM serverside and UA lib

Hey All,
Was hopping for some guidance, currently got a client that has GA (UA) tags set up with enhanced ecommerce and Piwik tag in GTM SS, how would you recommend best way to make sure all ecommerce events gets to Piwik to?
@kuba / @Piotrek any ideas?

Hi. For sure some sort of mapping could be done to forward that data to Piwik PRO as well. We’ll take a note here and consider that while working on the extension of our current template.

@kuba The lack of ecommerce support in the server-side template is a dealbreaker for many of my customers at the moment (all webshops). Can you provide a timeline when the template will be updated to support ecommerce events?

I have decided to create my own tag template for GTM. Is it OK to base it on your code base and share the new version with the GTM community as open source? I will try to provide support for:

  1. GA4 Client
  2. Enhanced Ecommerce
1 Like

Hi. Totally fine with that. Thanks in advance for any contributions! :slight_smile:


you might want to start with my already existing additions in a separate fork at GitHub - mbaersch/server-side-template-for-gtm: Piwik PRO Analytics template for server-side Google Tag Manager or even contribute to this one


I think two approaches should be available. One Tag Template based on GA3 Enhanced Ecommerce (for the people who don’t want to switch to GA4 and are moving towards Piwik Pro instead) and another template based on Google Analytics 4 (for the more advanced customers who might already have migrated towards GA4 or added it to their implementation next to UA).

Therefore, I will create a new template. The start is already there, currently supporting the ‘purchase’ event already. Tomorrow I will try to expand it. Feel free to add or to borrow code for the UA template :slight_smile:

1 Like

I am struggling a bit with the lack of documentation at the moment. Can you add some example HTTP API calls for the following ecommerce events so that I will know how to send those events through the HTTP API? I am aware that some events might not be supported, please indicate if so:

  1. add_to_cart: when a product is added to the cart
  2. remove_from_cart: when a product is removed from the cart
  3. view_cart: when the cart page is viewed
  4. view_item: view a product page
  5. view_item_list: view a category page
  6. select_item: when a product is clicked in a category page
  7. begin_checkout: when the checkout page is viewed
  1. Here you have to list all products and set the goal conversion id to 0.
  1. You have to repeat the same thing as in point 1, but without the removed item.
  2. There’s no dedicated event for that. So it could be mapped to a page view or a custom event.
  3. Product view is tracked using standard page vies with additional custom variables set for sku, name and price (this solution most likely will be changed in the future). Example api call:
  1. For that we can track the category view. It’s done in a similar way to point 4. Example call:
  1. No dedicated event for that. Could be addressed via custom event.
  2. No dedicated event for that. Could be addressed via custom event.

Adding also an example of call used to track ecommerce order. It’s really similar to updating the cart:


Hi kuba. That is a bit more clear, but hereby some feedback and additional questions:

  1. The parameter ‘_idn’ in your example request is not documented in the HTTP API. For my requests I probably don’t need it, but maybe good to add it in the documentation.

  2. The approach on the cart info is too different from GA. GA basically allows you to send ‘add’ and ‘remove’ events and ‘view_cart’ and ‘begin_checkout’ events that will together determine what is inside the users cart for each session. Meaning that if the ‘add_to_cart’ event triggers, I will have no data on what other products are already inside the cart (from previous actions). Therefore, I cannot update the entire cart with the full contents of the cart at this stage. I can only do that at the begin_checkout event (which is of course always a step to take before placing an order). Since Piwik PRO requires access to the full content of the cart at any stage of updating the cart (add, remove) this will be imposible to integrate at the moment. From an ecommerce developer perspective I think not many ecommerce platform are used to exposing full cart data outside the cart of checkout itself (also due to performance issues related to discount calculations etc…). You mights want to rethink the Piwik PRO approach about that. If you need more info from me, I would be happy to schedule a call and explain more about my position in that case.

  3. You are mentioning the usage of the ‘cvar’ parameter. Is this the same as using the ‘dimension’ parameter?

  4. About the ‘cvar’ parameter: In your example it contains ‘_pkp’, _pks’ etc… Are these reserved names or just the names you created manually as custom dimension first? If so, am I correct that thus clients are required to create the custom dimensions first in their account before they can use this?

  5. For the select_promotion, view_promotion, select_item and select_content events of GA4 it might be most appropriate to use your ContentInteraction events (c_i and c_n parameters). Agreed?

  6. Since the add_to_cart and remove_from_cart cannot really be used I was thinking of sending this as custom event. Should I include the items list also with cvar as best practice maybe?

  7. Can you take a look at my GIT-repo and see if I assigned the event-name, event-action and event-category the right values for the events or do you see room for improvement?

The current work I provided already works and I tested it in some of my accounts. So almost ready for a full release if we can discuss the points above so that I can finish the rest of the work.

Hope you guys find my work helpful :slight_smile:

My general note: we’re aware that the current design of ecommerce tracking isn’t ideal. Our current solution is based on the one known from Matomo (it’s part of our legacy). In the coming months we’re going to work intensively to make our ecommerce more similar to UA/GA4 by adding new features and reports.

  1. You can skip it. This parameter is ignored and will be removed from the js tracking lib soon.
  2. See my general note. I totally understand your point and given that our tracker backend is really flexible now, it shouldn’t be hard to implement.
  3. Our tracking library for ecommerce is based on the one from Matomo, thus we have such solutions still live. Custom variables are currently deprecated. You could use custom dimensions for that, but it adds additional step to the process - you have to create these dimensions. Our future solution will have dedicated dimensions to store that.
  4. Those are most likely keys for the custom vars. Custom vars allowed to set both the key and value via API. Those names are not reserved, but our js tracker uses them.
  5. I’d go with custom events but fur sure there might be other opinions on that. In the future, we should have dedicated events for that.
  6. That would be hard. I don’t recommend using custom vars and custom dimensions require additional steps to be taken. For now, I wouldn’t include the items to keep it simple. You could also do it in a similar way to the one from step 7.
  7. It looks good. With current limitations, I can’t think of something more useful.

We’re always very happy to see the contributions from the community. We hope that’s just the beginning. :facepunch: