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:

Hi,

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

best,
Markus

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.
/ppms.php?idgoal=0&revenue=15.5&ec_items=%5B%5B%220123456789%22%2C%22Ecommerce%20Analytics%20Book%22%2C%5B%22Books%22%2C%22Best%20sellers%22%5D%2C9.99%2C1%5D%5D&idsite=40446cce-14be-445c-b625-56833a7066ab&rec=1&r=741517&h=9&m=44&s=20&url=http%3A%2F%2Fmydev.com%2F&_id=b7083d88dcd3ae1e&_idts=1658736788&_idvc=3&_idn=0&_viewts=1661499356&send_image=0&ts_n=jstc_tm&ts_v=2.7.2&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=0&java=0&gears=0&ag=0&cookie=1&res=1512x982&gt_ms=2
  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:
/ppms.php?action_name=Page%20Title&idsite=40446cce-14be-445c-b625-56833a7066ab&rec=1&r=270285&h=9&m=39&s=53&url=http%3A%2F%2Fmydev.com%2F&_id=b7083d88dcd3ae1e&_idts=1658736788&_idvc=3&_idn=0&_viewts=1661499356&send_image=0&ts_n=jstc_tm&ts_v=2.7.2&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=0&java=0&gears=0&ag=0&cookie=1&res=1512x982&cvar=%7B%222%22%3A%5B%22_pkp%22%2C9.99%5D%2C%223%22%3A%5B%22_pks%22%2C%220123456789%22%5D%2C%224%22%3A%5B%22_pkn%22%2C%22Ecommerce%20Analytics%20Book%22%5D%2C%225%22%3A%5B%22_pkc%22%2C%22Books%22%5D%7D&gt_ms=11
  1. For that we can track the category view. It’s done in a similar way to point 4. Example call:
/ppms.php?action_name=Page%20Title&idsite=40446cce-14be-445c-b625-56833a7066ab&rec=1&r=509573&h=9&m=43&s=10&url=http%3A%2F%2Fmydev.com%2F&_id=b7083d88dcd3ae1e&_idts=1658736788&_idvc=3&_idn=0&_viewts=1661499356&send_image=0&ts_n=jstc_tm&ts_v=2.7.2&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=0&java=0&gears=0&ag=0&cookie=1&res=1512x982&cvar=%7B%225%22%3A%5B%22_pkc%22%2C%22Books%22%5D%7D&gt_ms=3
  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:

ppms.php?idgoal=0&ec_id=000123&revenue=10.99&ec_st=9.99&ec_tx=1.5&ec_sh=1&ec_items=%5B%5B%2201234567890%22%2C%22Ecommerce%20Analytics%20Book%22%2C%22Books%22%2C9.99%2C1%5D%5D&idsite=40446cce-14be-445c-b625-56833a7066ab&rec=1&r=347789&h=9&m=50&s=13&url=http%3A%2F%2Fmydev.com%2F&_id=b7083d88dcd3ae1e&_idts=1658736788&_idvc=3&_idn=0&_viewts=1661499356&send_image=0&ts_n=jstc_tm&ts_v=2.7.2&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=0&java=0&gears=0&ag=0&cookie=1&res=1512x982&gt_ms=2

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: