Apple

Real User Monitoring for mobile

Setup instructions

1. Install the Raygun4Apple package

Download the latest package installer from here. Run the installer and follow the on-screen instructions.

2. Reference Raygun4Apple in your project

To use the framework in an app project, you will need to first select the Project in the Project Navigator. Then select the Target for the Project and scroll down to the Embedded Binaries section.

Next, in Finder, open the Library > Frameworks > raygun4apple directory. Open the folder corresponding to the platform your Target is currently supporting. Select the raygun4apple.framework file and drag it into the Embedded Binaries section.

3. Add the import dependency

For Swift projects you must create an Objective-C bridging header to be able to import the provider's umbrella header file. You can find out how to do this by visiting Apple's documentation for more details.

In your AppDelegate's source file or Objective-C bridging header file, import the umbrella header for your target platform.

For iOS: 

#import <raygun4apple/raygun4apple_iOS.h>

For tvOS: 

#import <raygun4apple/raygun4apple_tvOS.h>

For macOS:

#import <raygun4apple/raygun4apple_macOS.h>

4. Enable Real User Monitoring

In your AppDelegate's application function, add the following code to start the Raygun crash reporter. Your app API key is displayed when you create a new application in your Raygun account, or can be viewed in the application settings.

Objective-C:

RaygunClient *raygunClient = [RaygunClient sharedInstanceWithApiKey:@"YOUR_APP_API_KEY"];
[raygunClient enableRealUserMonitoring];

Swift:

let raygunClient = RaygunClient.sharedInstance(apiKey:"YOUR_APP_API_KEY")
raygunClient.enableRealUserMonitoring()

Unique user tracking

By default, each user will be identified with a unique guid and marked as anonymous. The identifier property on the RaygunUserInformation class is what separates one user from another. Be sure to set it with something unique, for example a database id, username or email address. If the user changes, for instance when logging in or out, be sure to update the user information on the shared Raygun client each time. You can assign user information as described below.

Objective-C:

RaygunUserInformation *userInfo = [[RaygunUserInformation alloc] initWithIdentifier:@"user@raygun.com"
                                                                          withEmail:@"user@raygun.com"
                                                                       withFullName:@"Test User"
                                                                      withFirstName:@"Test"];
RaygunClient.sharedInstance.userInformation = userInfo;

Swift:

let userInformation = RaygunUserInformation(identifier: "user@raygun.com", email: "user@raygun.com", fullName: "Test User", firstName: "Test")
RaygunClient.sharedInstance().userInformation = userInformation

Automatic view performance monitoring

The provider will automatically record the time it took for views to load during a user's session. This information will appear on the Views tab of your Real User Monitoring for mobile dashboard and also when inspecting a user's session.

Manually report timings

You are able to manually report view timing events that will appear with the current session. This can be helpful to provide additional information around a user's experience.

Objective-C:

[RaygunClient.sharedInstance sendTimingEvent:RaygunEventTimingTypeViewLoaded withName:@"MyAppViewController" withDuration:300];

Swift:

RaygunClient.sharedInstance().sendTimingEvent(type: RaygunEventTimingType.viewLoaded, name:"MyAppViewController", duration:300)

Ignoring timings

Since views are automatically detected, there may be views that are not helpful to record and should be ignored. The following snippet can be used to stop the provider from sending timing events for views whose name matches.

Objective-C:

[RaygunClient.sharedInstance ignoreViews:@[@"MyAppViewController"]];

Swift:

RaygunClient.sharedInstance().ignoreViews(["MyAppViewController"])

Automatic network performance monitoring

The provider has the ability to automatically record the time it took to complete network requests. Use the following snippet to enable this feature. Network performance monitoring can only be enabled after enabling Real User Monitoring on the client.

Details about all automatically and manually logged network calls can be found on the Performance tab of your Real User Monitoring for mobile dashboard.

Objective-C:

[RaygunClient.sharedInstance enableNetworkPerformanceMonitoring];

Swift:

RaygunClient.sharedInstance().enableNetworkPerformanceMonitoring()

The provider will track the performance of network calls made with the following methods:

// NSURLSession methods

dataTaskWithURL:
dataTaskWithURL:completionHandler:
dataTaskWithRequest:
dataTaskWithRequest:completionHandler:
downloadTaskWithURL:
downloadTaskWithURL:completionHandler:
downloadTaskWithRequest:
downloadTaskWithRequest:completionHandler:
uploadTaskWithRequest:fromData:
uploadTaskWithRequest:fromData:completionHandler:
uploadTaskWithRequest:fromFile:
uploadTaskWithRequest:fromFile:completionHandler:

// NSURLConnection methods

sendAsynchronousRequest:queue:completionHandler
sendSynchronousRequest:returningResponse:error:

Manually report timings

You are able to manually report network timings to Raygun using the following snippet with duration being measured in milliseconds.

Objective-C:

[RaygunClient.sharedInstance sendTimingEvent:RaygunEventTimingTypeNetworkCall withName:@"www.raygun.com/rum" withDuration:120];

Swift:

RaygunClient.sharedInstance().sendTimingEvent(type: RaygunEventTimingType.networkCall, name:"www.raygun.com/rum", duration:120)

Ignoring timings

Since network requests are automatically detected, there may be network request that are not helpful to record and should be ignored. The following snippet can be used to stop the provider from sending timing events for those requests whose URLs contain specific text.

Objective-C:

[RaygunClient.sharedInstance ignoreURLs:@[@"raygun.com"]];

Swift:

RaygunClient.sharedInstance().ignoreURLs(["raygun.com"])

Documentation missing?

If we don't have documentation about your desired topic, send us a message and we'll create it for you.