Tracking pageview conversions
You can fire a custom event when a visitor reaches a specific page on your site, such as a thank-you page, signup confirmation, or order completion page. This lets you track conversions without requiring the visitor to click anything.
How it works
Add a script that checks the current page URL and fires an event if it matches. Place this before the closing </body> tag and after your GoodMetrics tracking script.
Tracking a single page
<script>
if (window.location.pathname === '/thank-you') {
gmTrackEvent('Newsletter Signup');
}
</script>
This fires the event whenever a visitor lands on /thank-you.
Tracking multiple pages
You can track conversions on several pages by checking for each one:
<script>
var conversions = {
'/thank-you': 'Newsletter Signup',
'/signup-complete': 'Signup Completed',
'/demo-booked': 'Demo Booked'
};
var path = window.location.pathname;
if (conversions[path]) {
gmTrackEvent(conversions[path]);
}
</script>
Tracking with a value
You can combine pageview conversions with event values. For example, tracking a purchase confirmation page with the order total:
<script>
if (window.location.pathname === '/order-confirmed') {
var orderTotal = 4999; // $49.99 in cents
gmTrackEvent('Order Confirmed', { value: orderTotal });
}
</script>
See Tracking event values for more on passing values with events.