Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

gatsby-plugin-newrelic

newrelic26.2kApache-22.9.0

Gatsby plugin for implementing the New Relic Browser agent

gatsby, gatsby-plugin, gatsby-source

readme

Community Project header

New Relic Gatsby Plugin

Known Vulnerabilities npm status badge

The New Relic Gatsby Plugin provides a simple to use configuration option for instrumenting your Gatsby site with New Relic's Browser Agent.

Installation

  1. If you don't already have a New Relic account, sign-up for our free forever tier - no credit-card required!
  2. Go to https://one.newrelic.com
  3. Click on "Add more data" to add your website
  4. In the "Browser metrics" section, select "New Relic Browser"
  5. Select "Copy/Paste Javascript code" and copy the code
  6. Follow the steps to configure your instrumentation
  7. Enter your app name
  8. Click "Enable"
  9. Paste the JS snippet provided into a text editor
  10. Open your gatsby-config.js file for your project
  11. You'll need to copy information from the JS snippet, which looks like this:

    // use this line for the `settings` object
    window.NREUM || (NREUM = {});
    NREUM.init = {
      distributed_tracing: { enabled: true },
      privacy: { cookies_enabled: true },
      ajax: { deny_list: ["bam-cell.nr-data.net"] },
    };
    
    // use these lines for the `config` object
    NREUM.loader_config = {
      accountID: "<your account id>",
      trustKey: "<some integer>",
      agentID: "<some integer>",
      licenseKey: "<your license key>",
      applicationID: "<some integer>",
    };
    NREUM.info = {
      beacon: "bam.nr-data.net",
      errorBeacon: "bam.nr-data.net",
      licenseKey: "<your license key>",
      applicationID: "<some integer>",
      sa: 1,
    };

    and turn it into a gatsby-config object, adding it to gatsby-config.js as a plugin

    {
     resolve: 'gatsby-plugin-newrelic',
     options: {
       config: {
           instrumentationType: 'proAndSPA',
           accountId: '<some integer>',
           trustKey: '<some integer>',
           agentID: '<some integer>',
           licenseKey: '<the license key>',
           applicationID: '<some integer>',
           beacon: 'bam.nr-data.net',
           errorBeacon: 'bam.nr-data.net'
           settings: {
             distributed_tracing: { enabled: true },
             privacy: { cookies_enabled: true },
             ajax: { deny_list: ["bam-cell.nr-data.net"] },
           }
       }
     }
    }

    If you have a need for multiple environments, you can configure this like:

    {
      resolve: 'gatsby-plugin-newrelic',
      options: {
        config: {
            instrumentationType: 'proAndSPA',
            accountId: '<some integer>',
            trustKey: '<some integer>',
            agentID: '<some integer>',
            licenseKey: '<the license key>',
            applicationID: process.env.YOUR_ENVIRONMENT_KEY === "production" ? '<some integer>' : '<some other integer>',
            beacon: 'bam.nr-data.net',
            errorBeacon: 'bam.nr-data.net'
        }
      }
    }

    If you have selected custom Session Replay values for block_selector or mask_text_selector, replace the surrounding single quotes(') with back ticks (`)

    {
        settings: {
         session_replay: {
           enabled: true,
         // block_selector: '[autocomplete="cc-number"], [autocomplete="cc-name"]',
           block_selector: `[autocomplete="cc-number"], [autocomplete="cc-name"]`,
         // mask_text_selector: '.className1, #elementID'`,
           mask_text_selector: `.className1, #elementID`,
        }
      }
    }

Getting Started

Navigate to https://one.newrelic.com, select the Entity Explorer and then select your browser application to monitor metrics of your site.

Support

New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there's a related Community topic in the New Relic Explorers Hub. You can find this project's topic/threads here:

Add the url for the support thread here

Contributing

Full details about how to contribute to Contributions to improve [Project Name] are encouraged! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. To execute our corporate CLA, which is required if your contribution is on behalf of a company, or if you have any questions, please drop us an email at opensource@newrelic.com.

License

gatsby-plugin-newrelic is licensed under the Apache 2.0 License. gatsby-plugin-newrelic also uses source code from third party libraries. Full details on which libraries are used and the terms under which they are licensed can be found in the third party notices document.

changelog

2.9.0 (2025-05-16)

Features

  • Update latest.js to add bot detection (b98c4e8)

2.8.0 (2025-05-06)

Features

2.7.0 (2025-03-05)

Features

  • update actions/cache@v1 to actions/cache@v3 (c51aa96)
  • update browser agents (ec49b60)
  • update workflow (12dd646)

2.6.0 (2024-04-12)

Features

2.5.0 (2024-03-04)

Features

  • add support for custom browser agent settings (6f1cd24)

2.4.0 (2023-11-07)

Features

  • use this to release a new version of the gatsby plugin newrelic (71cebe4)

2.3.0 (2023-04-12)

Features

  • upgrade browser agents to v1.230.0 (76e5b93)

2.2.3 (2023-02-15)

Bug Fixes

  • update react in peer deps to 17-18 (d6e9c18)

2.2.2 (2022-02-09)

Bug Fixes

  • publishes a latest version (c2e68bb)

2.2.1 (2022-02-08)

Bug Fixes

2.2.0 (2022-01-14)

Features

2.1.1 (2022-01-10)

Bug Fixes

  • updated contributing guide (af6aa1c)

2.1.0 (2022-01-06)

Bug Fixes

Features

  • adds support for gatsby 4 (a7b5ba3)

2.0.2 (2021-08-06)

Bug Fixes

  • update default release tag to be latest (a6fef1e)

2.0.1 (2021-08-06)

Bug Fixes

  • update critical dependencies (626bb55)

2.0.0 (2021-04-20)

chore

  • gatsby: update peer deps for gatsby v3 upgrade (6fd5ed5)

BREAKING CHANGES

  • gatsby: Bumping to major release for all Gatsby projects

1.0.6 (2020-12-31)

Bug Fixes

  • upgrade @babel/runtime from 7.10.0 to 7.11.2 (f86b63a)
  • semantic-release: update package version to fix semantic-release's auto-versioning [skip-ci] (f9641a0)

1.0.1 (2020-10-23)

Bug Fixes

  • Issue #16: Update agent code to work with Gatsby script rendering (c4702db), closes #16

1.0.0 (2020-10-22)

Bug Fixes

  • javascript had a bad value in liteAgent causing issues (8f27ec4)
  • main pointer (80725cb)
  • release workflow: Target correct branch (f7b1dfc)
  • previously moved under /src (6935cd3)
  • use a different env variable (GATSBY_NEWRELIC_ENV instead of NODE_ENV) for toggling configs (5cd42e8)
  • release workflow: Sometimes quotes matter (3f35594)
  • release-workflow: Add npm token for semantic-release (af0a31f)
  • release-workflow: steps outputs are job-specific (254c5e0)
  • release-workflow: Update semantic-release config to allow for npm publish from the next branch (7036442)
  • release-workflow: Update set-output syntax (0b6d5ff)
  • release-workflow: Use env instead of with for variables (3f2363a)

Features

  • allow for different configs per environment (6116b7a)
  • initial POC Newrelic Gatsby plugin (7c9fb11)
  • Support general, non-env specific config (23a033c)

Reverts