@lightspeed/react-new-relic-script
v0.1.16
Published
React New Relic browser timing header script component for SSR pages
Downloads
72
Keywords
Readme
@lightspeed/react-new-relic-script
Introduction
In serverside rendered React apps, this component renders to the browser timing header for clientside New Relic instrumentation.
Quick Start
- Install the dependency in your webapp.
yarn add newrelic @lightspeed/react-new-relic-script
Configure New Relic by either creating a
newrelic.js
configuration file at the root directory of your webapp, or setting environment variables as described here. You will at least need to set theapp_name
andlicense_key
configurations.Add
require('newrelic');
as the first line of your application's entry point. Modules syncronously loaded New Relic will be instrumented appropriately.In your serverside rendered document component, render the
<NewRelicScript />
component in the<head />
of your document. For example, in aNext.js
app with serverside rendering, use the component as follows:
// app/_document.tsx
import React from 'react';
import Document, { Head, Main, NextScript, NextDocumentContext } from 'next/document';
import NewRelicScript from '@lightspeed/react-new-relic-script';
export default class MyDocument extends Document {
render() {
return (
<html>
<Head nonce={this.props.nonce}>
<title>Lightspeed Retail - Cool Page</title>
<NewRelicScript />
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
);
}
}