• /
  • EnglishEspañol日本語한국어Português
  • 로그인지금 시작하기

Add browser monitoring to your Go apps

If you installed New Relic's Go agent for your app, you can also use 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 browser monitoring, 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 monitoring's 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's 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.
txn := newrelic.FromContext(req.Context())
hdr := txn.BrowserTimingHeader()
// 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>")
}
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.