Blog
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.
| GA4 | Matomo |
|---|---|
| page_view | action_name |
| purchase | idgoal=0, ec_id, revenue |
| add_to_cart | e_c=Ecommerce, e_a=AddToCart |
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.