Blog

Forward conversion data to a self-hosted Matomo through sGTM

A working pattern for sending GA4-style events to a Matomo instance.

If you run Matomo alongside or instead of GA4, your sGTM container can forward events to Matomo using its tracking API.

Map GA4 events to Matomo

GA4Matomo
page_viewaction_name
purchaseidgoal=0, ec_id, revenue
add_to_carte_c=Ecommerce, e_a=AddToCart

A Custom Tag in sGTM

const params = {
  idsite: data.siteId, rec: 1,
  url: getEventData('page_location'),
  action_name: getEventData('page_title')
};
if (data.eventName === 'purchase') {
  params.idgoal = 0;
  params.ec_id = getEventData('transaction_id');
  params.revenue = getEventData('value');
}
sendHttpRequest('https://matomo.example.com/matomo.php?' + encodeUriParameters(params));

Matomo uses _id for visitor identification. Generate per-user and store in a first-party HttpOnly cookie.