• /
  • Log in
  • Free account

recordCustomEvent (iOS SDK API)

Syntax

recordCustomEvent:(NSString*)eventType attributes:(NSDictionary*)attributes;
NewRelic.recordCustomEvent(string $eventType, [string $eventName,] map<string, object> $eventAttributes)

Records a custom mobile monitoring event.

Requirements

As of New Relic iOS agent version 5.12.0, the recordEvent method is deprecated and replaced with recordCustomEvent. The recordEvent method will continue to work for an unspecified period of time, but if your app contains recordEvent methods, New Relic recommends you replace them.

Updating these methods will affect any queries and dashboards that use the deprecated event types. Be sure to adjust your NRQL queries and dashboards as needed.

Description

Creates and records a custom event that you can query using NRQL. The event includes a list of attributes, specified as a map. Unlike using setAttribute, adding attributes to a custom event adds them only to that event; they are not session attributes.

Important considerations and best practices include:

  • Limit the total number of eventType values to approximately five. It is meant to be used for high-level categories, such as Gestures.
  • Do not use eventType to name your custom events. Instead, create attributes to name custom events, or use the optional name parameter.
  • Use the name keyword to display your events in the mobile monitoring UI. To create a useful name, you can combine several attributes. Using the name parameter has the same effect as adding a name key in the attributes dictionary.
  • The elements of the attributes object must be of the type NSString or NSNumber.

Parameters

Parameter

Description

$eventType

string

Required. The type of event. Do not use $eventType to name your custom events; use a custom attribute or the optional name parameter.

$eventName

string

Optional. Use this parameter to name the event. (Using this parameter is equivalent to creating a name parameter.)

$eventAttributes

map<string, object>

Optional. A map that includes a list of attributes that further designate subcategories to the $eventType. The elements of the attributes object must be of the type NSString or NSNumber.

You can create attributes for any event descriptors you think will be useful. To name your custom events, create a name attribute or use the eventName parameter.

Important

When setting the key for your custom attributes, be aware that there are default attributes that cannot be overridden.

Return values

Returns true if the event is recorded successfully, or false if not.

Examples

Objective-C

Methods:

+ (BOOL) recordCustomEvent:(NSString*)eventType attributes:(NSDictionary*)attributes;
+ (BOOL) recordCustomEvent:(NSString*)eventType name:(NSString*)name attributes:(NSDictionary*)attributes;

Examples:

BOOL eventRecorded = [NewRelic recordCustomEvent:@"eventType"
attributes:@{@"attributeName1": @"value1", @"attributeName2": @2}];
BOOL eventRecorded = [NewRelic recordCustomEvent:@"Vehicle" name:@"1908 Ford ModelT"
attributes:@{@"make":@"Ford", @"model":@"ModelT", @"year": @1908, @"color": @"black", @"mileage": @250000}];

Swift

Methods:

NewRelic.recordCustomEvent(eventType: String!, attributes:[NSObject : AnyObject]!) -> Bool
NewRelic.recordCustomEvent(eventType: String!, name: String!, attributes:[NSObject : AnyObject]!) -> Bool

Examples:

let eventRecorded = NewRelic.recordCustomEvent("eventType", attributes: ["attributeName1" : "value1", "attributeName2": 2])
let eventRecorded = NewRelic.recordCustomEvent("Vehicle", name:"1908 Ford ModelT", attributes:["make":"Ford", "model":"ModelT", "year": 1908, "color": "black", "mileage": 250000]);
Create issueEdit page
Copyright © 2022 New Relic Inc.