# `@lightspeed/react-new-relic-script`

[![npm version](https://badge.fury.io/js/%40lightspeed%2Freact-new-relic-script.svg)](https://badge.fury.io/js/%40lightspeed%2Freact-new-relic-script)

## Introduction

In serverside rendered React apps, this component renders to the browser timing header for clientside New Relic instrumentation.

## Quick Start

1. Install the dependency in your webapp.

```sh
yarn add newrelic @lightspeed/react-new-relic-script
```

2. 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](https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration). You will at least need to set the `app_name` and `license_key` configurations.

3. Add `require('newrelic');` as the first line of your application's entry point. Modules syncronously loaded New Relic will be instrumented appropriately.

4. In your serverside rendered document component, render the `<NewRelicScript />` component in the `<head />` of your document. For example, in a `Next.js` app with serverside rendering, use the component as follows:

```tsx
// 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>
    );
  }
}
```
