Setting up Metronome with Remix + Express / Remix Blues Stack

Install Metronome

Install Metronome's react and express prerelease packages.
Terminal
$npm install @metronome-sh/react @metronome-sh/express
alternatively, you can use yarn:
Terminal
$yarn add @metronome-sh/react @metronome-sh/express

Create config file

The
metronome.config.js
is used to set what your project sends to Metronome. Create it by running the command below.
Terminal
$npx metronome init

Configure Metronome in your root.tsx file

To be able to track your app's Web Vitals and Web Analytics, you need to set up the client side with
@metronome-sh/react
.
Import
withMetronome
from
@metronome-sh/react
and add wrap your App component with it.
root.tsx
// ...
import { withMetronome } from "@metronome-sh/react";
// Remove the default export of App
function App() {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<Meta />
<Links />
</head>
<body>
<Outlet />
<ScrollRestoration />
<Scripts />
<LiveReload />
</body>
</html>
);
}
// Set withMetronome as the default export
export default withMetronome(App);

Configuring Metronome in your in you server.js file

In your
server.js
, just replace the import of
createRequestHandler
from
@remix-run/express
to
@metronome-sh/express
function with the following:
// import { createRequestHandler } from "@remix-run/express";
import { createRequestHandler } from "@metronome-sh/express";
This will enable Metronome to handle the requests and responses.It essentially invokes the
createRequestHandler
from
@remix-run/express
for you and augments it using Metronome's code.

Set your API key in your production environment

Add the
METRONOME_API_KEY
environment variable in your production server. You can find it in the settings section of your Metronome project.