How to track goal conversions by User ID
When User ID tracking is enabled, Matomo automatically associates all tracked activity such as page views, events, and goals with the User ID of the logged-in visitor. Matomo attributes every goal conversion to a visit. If that visit has a User ID, all conversions completed during logged-in sessions are linked to the same User ID for analysis in reports, segments, and visitor profiles.
This guide has two examples showing how to trigger goals manually for logged-in users.
- The first goal is triggered when users complete their profile and click on a specific button like Complete Profile. Your site’s code logic determines when enough information is provided to send an event to Matomo when an action occurs.
- The second goal is triggered when users upgrade their subscription plan and get directed to a Thank you or Upgrade success page.
Before you start, Matomo tracking must be set up and consistently tracking User IDs. Learn how to set up User ID tracking.
Set up goals for logged-in users
- In Matomo, go to Goals > Manage Goals.
- Click Add a Goal and provide a custom name (for example,
User profile completeorUser subscription upgrade). - Define how to trigger a goal in Matomo, either automatically with built-in triggers or manually. The examples in this guide use manually triggered events.
- Use the drop-down for Goal is triggered and select the option: manually.
- Complete the required fields and click Add Goal to save.
Track user profile completion goal
Tracking profile completion goals measures how many logged-in users finish setting up their accounts. By defining a goal that triggers when a profile_complete event occurs, you can analyse how users progress from sign-up and where they drop off in the onboarding process.
Matomo JavaScript tracking code
- Define the goal that will be triggered manually.
- Ensure the Matomo tracking code is configured for User ID tracking and placed before the closing
</head>tag on the pages you want to track. - You need to include additional code for goal tracking in your website page where the profile completion action occurs. The example script includes ‘trackGoal’ to track when the user clicks the Complete Profile button.
// When the user clicks "Complete Profile", track the event in Matomo
document.getElementById('completeProfileBtn').addEventListener('click', function() {
// Track the profile completion event
_paq.push(['trackGoal', 1]); // Replace with your goal ID
Read the section at the end on testing goal tracking.
Matomo Tag Manager
- Define the goal that will be triggered manually.
- Ensure Tag Manager is configured for User ID tracking and the container snippet is placed before the closing
</head>tag on the pages you want to track. - You need to include additional code for event tracking in your website page where the profile completion event occurs. The following example script pushes the event to the
mtmdata layer when the user clicks the Complete Profile button.
// Add to the web page. When the user clicks "Complete Profile", track the event in Matomo
document.getElementById('completeProfileBtn').addEventListener('click', function() {
//** Add mtm code after the button action occurs ** //
window._mtm = window._mtm || [];
window._mtm.push({
event: 'profile_complete',
buttonType: 'profile',
label: 'Complete Profile'
});
...
</script>
Set up goal tracking
- In Tag Manager, go to Tags and click Create New Tag.
- Choose the Matomo Analytics tag and provide a custom name to identify the tag.
- The selected Matomo Configuration Variable should contain the User ID (configured when setting up User ID with Matomo Tag Manager).
- For the Tracking Type, select Goal and enter the Goal ID (for the goal created previously).
- Optionally assign a value in the Goal Revenue field.
- Choose an All Clicks Trigger with a condition that identifies the button, for example Click ID equals
<button id>.
- Click Create New Tag to save.
Read the section at the end on testing goal tracking.
Track user subscription upgrade goal
By tracking subscription upgrades, you can measure how many logged-in users upgrade their current plans. This helps with understanding conversion performance, analysing upgrade behaviour, and linking conversions to individual User IDs for detailed user insights.
Matomo JavaScript tracking code
- Define the goal that will be triggered manually.
- Ensure the Matomo tracking code is configured for User ID tracking and placed before the closing
</head>tag on the pages you want to track. - Since the Upgrade Successful page represents the conversion (and is only reached by logged-in users after upgrading), the event should fire automatically on page load, setting the User ID, tracking the goal, and logging the page view.
- You need to include the
trackGoalcall after the pageview event in your tracking code.
<!-- SAMPLE SCRIPT DO NOT COPY -->
<script>
var _paq = window._paq = window._paq || [];
// Track the page view for analytics
_paq.push(['trackPageView']);
// Track the goal conversion (replace 2 with your actual goal ID)
_paq.push(['trackGoal', 2]);
Enable link tracking and set up tracker configuration
_paq.push(['enableLinkTracking']);
(function() {
var u = "https://mysite.matomo.cloud/"; // Replace with your Matomo instance URL
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setSiteId', '1']); // Replace with your site ID
})();
</script>
<script src="https://cdn.matomo.cloud/mysite.matomo.cloud/matomo.js"></script>
<!-- End Matomo Code -->
Read the section at the end on testing goal tracking.
Matomo Tag Manager
- Define the goal that will be triggered manually.
- Ensure Tag Manager is configured for User ID tracking and the container snippet is placed before the closing
</head>tag on the pages you want to track. - Since the Upgrade Successful page represents the conversion (and is only reached by logged-in users), the event should fire automatically on page load, setting the User ID, tracking the goal, and logging the page view.
Set up goal tracking
- In Tag Manager, go to Tags and click Create New Tag.
- Choose the Matomo Analytics tag and provide a custom name to identify the tag.
- The selected Matomo Configuration Variable should contain the User ID (configured when setting up User ID with Matomo Tag Manager).
- For the Tracking Type, select Goal and enter the Goal ID (for the goal created previously).
- Optionally assign a value in the Goal Revenue field.
- Choose a Pageview Trigger with a condition that identifies the URL for the Upgrade Successful page, for example use Page URL equals
<url_for_upgrade_success_page>.
- Click Create New Tag to save.
Test the goal tracking setup
- Open your website and log in as a customer.
- Perform test steps to complete the tracked action.
- In the browser developer tools (F12). Go to the Network tab and look for the request to
matomo.phpand confirm that the URL contains theuidparameter with your test User ID value. - If tracking with Tag Manager, use Preview and Debug mode while performing the required action on your website.
- In Matomo, go to the Visitors > Real-time and Visits Log to see the goal conversion for completing a user profile or the goal conversion for upgrading a plan.
Once User ID and Goal tracking is configured, you can analyse conversion rates and user journeys across all Matomo reports. Use the Reporting API, create Segments, and track Ecommerce purchases for repeat conversions and customer loyalty analysis.