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 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 asGestures.
- Do not use
eventType
to name your custom events. Instead, create attributes to name custom events, or use the optionalname
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 thename
parameter has the same effect as adding aname
key in the attributes dictionary. - The elements of the attributes object must be of the type NSString or NSNumber.
Parameters
Parameter | Description |
---|---|
string | Required. The type of event. Do not use |
string | Optional. Use this parameter to name the event. (Using this parameter is equivalent to creating a |
map<string, object> | Optional. A map that includes a list of attributes that further designate subcategories to the You can create attributes for any event descriptors you think will be useful. To name your custom events, create a ImportantWhen 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]);