Syntax
NewRelic.Api.Agent.NewRelic.GetBrowserTimingHeader();NewRelic.Api.Agent.NewRelic.GetBrowserTimingHeader(string nonce);
Generate a browser monitoring HTML snippet to instrument end-user browsers.
Requirements
Compatible with all agent versions.
Must be called inside a transaction.
Description
Returns an HTML snippet used to enable browser monitoring. The snippet instructs the browser to fetch a small JavaScript file and start the page timer. You can then insert the returned snippet into the header of your HTML webpages. For more information, see Adding apps to Browser monitoring.
Tip
Compare DisableBrowserMonitoring()
, which disables the browser script on a page.
Parameters
Parameter | Description |
---|---|
string | The per-request, cryptographic nonce used by Content-Security-Policy policies. |
Tip
This API call requires updates to security allow lists. For more information about Content Security Policy (CSP) considerations, visit the browser monitoring compatibility and requirements page.
Return values
An HTML string to be embedded in a page header.
Examples
With ASPX
<html> <head> <%= NewRelic.Api.Agent.NewRelic.GetBrowserTimingHeader()%> ... </head> <body> ...
<html> <head> <%= NewRelic.Api.Agent.NewRelic.GetBrowserTimingHeader("YOUR_NONCE_VALUE")%> ... </head> <body> ...
With Razor
<!DOCTYPE html><html lang="en"> <head> @Html.Raw(NewRelic.Api.Agent.NewRelic.GetBrowserTimingHeader()) ... </head> <body> ...
<!DOCTYPE html><html lang="en"> <head> @Html.Raw(NewRelic.Api.Agent.NewRelic.GetBrowserTimingHeader("YOUR_NONCE_VALUE")) ... </head> <body> ...
With Blazor
Important
This API is not supported for Blazor Webassembly, because the agent is unable to instrument Webassembly code. The following examples are for Blazor Server applications only. Use the copy-paste method of adding the browser agent to Blazor Webassembly pages.
Important
This API can not be placed in a <HeadContent>
element of a .razor
page. Instead, it should be called from _Layout.cshtml
or an equivalent layout file.
<!DOCTYPE html><html lang="en"> <head> @Html.Raw(NewRelic.Api.Agent.NewRelic.GetBrowserTimingHeader()) ... </head> <body> ...
<!DOCTYPE html><html lang="en"> <head> @Html.Raw(NewRelic.Api.Agent.NewRelic.GetBrowserTimingHeader("YOUR_NONCE_VALUE")) ... </head> <body> ...