• /
  • EnglishEspañol日本語한국어Português
  • Log inStart now

recordCustomEvent

Syntax

newrelic.recordCustomEvent(string $eventType[, JSON object $attributes])

Reports a custom browser event under a specified eventType with custom attributes.

Requirements

Description

This API call sends a custom browser event with your user-defined eventType and optional attributes to dashboards, along with any custom attributes you may have set for your application. This is useful to track any event that is not already tracked automatically by the browser agent enhanced by rules and attribution you control.

  • custom events are sent every 30 seconds.
  • If 1,000 events are observed, the agent will harvest the buffered events immediately, bypassing the harvest cycle interval.

Parameters

Parameter

Description

$eventType

string

Required. The eventType to store the event data under

Avoid using reserved NRQL words or pre-existing eventTypes when you name the attribute or value.

$attributes

JSON object

Optional. JSON object with one or more key/value pairs. For example: {key:"value"}. The key is reported as its own PageAction attribute with the specified values.

Avoid using reserved NRQL words when you name the attribute/value.

Important considerations and best practices include:

You should aim to limit the total number of event types to approximately five. Custom eventTypes are meant to be used to encapsulate high-level categories. For example, you might create an event type Gestures.

Do not use eventType to name custom events. Create eventTypes to house a category of data and attributes within that category to name an event or use the optional name parameter. While you can create numerous custom events, it's important to keep your data manageable by limiting the number of eventTypes reported.

Examples

This example records a custom event whenever a user clicks the Submit button in a form. The event is recorded with an eventType of FormAction, which was used to contain many events related to actions taken on a form:

<a href="/demo" id="try-me">Try Me!</a>
<script>
document.getElementById('submit').addEventListener('click', function (e) {
newrelic.recordCustomEvent('FormAction', {
element: 'submit',
action: 'click',
});
});
</script>

You can then query the number of times the Submit button was clicked with the following NRQL query:

SELECT count(*) FROM FormAction WHERE element = 'submit' AND action = 'click' SINCE 1 hour ago
Copyright © 2024 New Relic Inc.

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