New Relic Browser Script in Different Enviroments

We currently have a SPA and want to use the New Relic Browser agent. This means that we have to use the copy an paste method to add it to our application.

However, we want to use different application id’s based on the environment that is being used. Is there a way to configure script to use a different application id?

Without have to duplicate the script for each environment.

If you take a look at the very bottom of the script you’ll notice a section that contains the Browser application ID. If you’ve already created multiple apps in the New Relic UI, you can edit the applicationID to point data elsewhere.

Some more info on this can be found here.

@cstanhope To add to Max’s comment above, if you have a way to surface the current code environment in a Javascript variable, you can write some conditional logic to set the app ID dynamically, such as this:

 <script type="text/javascript">
    // The loader script (everything except the config block shown above) goes here
        // … lots of code removed here for ease of viewing …

        ["firstbyte",a()],null,"api");var m=0},{}]},{},["loader",2,9,3]);
    // End loader; begin conditional logic for config
        var appID;
        switch (env) {
            case "production":
                appID = "123456";
            case "staging":
                appID = "4567890";
            case "dev":
                appID = "654321";
    // Config block with appID variable

Note that there are placeholders for the license key and agent version in the config block at the bottom—these should be replaced with the values from your current copy/paste script.