Install New Relic Browser for Go apps

If you installed New Relic APM's Go agent for your app, you can also use New Relic Browser to monitor browser performance. To install the Browser agent, use the copy and paste method, or use the Go agent API.

Install with Go agent Browser API

To enable support for New Relic Browser, your HTML pages must include a JavaScript snippet that will load the Browser agent and configure it with the correct application name. This snippet is available with the Transaction.BrowserTimingHeader method. Support for Browser timing headers is available with Go agent versions 2.5.0 or higher.

Include the byte slice returned by Transaction.BrowserTimingHeader().WithTags() as early as possible in the <head> section of your HTML and after any <meta charset> tags.

The JavaScript returned from Transaction.BrowserTimingHeader is request-specific. That is why it must be called on each request.

func indexHandler(w http.ResponseWriter, req *http.Request) {
    io.WriteString(w, "<html><head>")
    // The New Relic browser javascript should be placed as high in the
    // HTML as possible. We suggest including it immediately after the
    // opening <head> tag and any <meta charset> tags.
    if txn := FromContext(req.Context()); nil != txn {
        hdr, err := txn.BrowserTimingHeader()
        if nil != err {
            log.Printf("unable to create browser timing header: %v", err)
        }
        // BrowserTimingHeader() will always return a header whose methods can
        // be safely called.
        if js := hdr.WithTags(); js != nil {
            w.Write(js)
        }
    }
    io.WriteString(w, "</head><body>browser header page</body></html>")
}

For more help

Recommendations for learning more: