Error Analysis

A newer version of this documentation is available. Switch to the latest version docs.

You must include the Contentsquare SDK first using the same integration method and understand how the SDK works.

Update to the latest SDK version

Section titled Update to the latest SDK version

In order to enable Error Analysis in your app and get the most stable version, it is required to upgrade the SDK to its latest version.

Tracking will start at the 1st screenview event, it is required to have screen tracking implemented. Make sure to follow the iOS Track screens sections.

If you are in the process of implementing the SDK for the 1st time (or choose to take this update as an opportunity to review your Privacy related implementation), make sure to follow the iOS Privacy section and use the Opt-in API to get the user consent, otherwise no data will be collected.

Add Contentsquare Error Analysis to your app

Section titled Add Contentsquare Error Analysis to your app

You should include the Contentsquare SDK first and use the same integration method.

  1. In Xcode, Same as Contentsquare SDK, Add the following link via File > Add Packages…:

    https://github.com/ContentSquare/CS_iOS_SDK.git
  2. In your targets’ General settings tab, in the Frameworks, Libraries, and Embedded Content section, add ContentsquareErrorAnalysisModule.

Add the following line to your Cartfile:

Cartfile
binary "https://raw.githubusercontent.com/ContentSquare/CS_iOS_SDK/master/carthage/ContentsquareErrorAnalysisModule.json"

Then run:

Terminal window
carthage update --platform ios --use-xcframeworks

Drag and drop ContentsquareModuleErrorAnalysis.xcframework from the Carthage/Build folder to your targets’ General settings tab, in the Frameworks, Libraries, and Embedded Content section.

Our SDK can be linked dynamically or statically:

Dynamic linking is the default behavior with use_frameworks!, Add the following line to your Podfile:

Podfile
pod 'CS_ErrorAnalysis'

If you specify static linking in your Podfile with use_frameworks! :linkage => :static, Add the following line to your Podfile:

Podfile
pod 'CS_ErrorAnalysis_STATIC'

Our SDK can be linked dynamically or statically:

Get the manual integration framework
Section titled Get the manual integration framework
  1. Go to the iOS SDK GitHub repository.
  2. Find the newest version available (unless instructed otherwise by your CS contact).
  3. Under Assets you should be able to find ContentsquareErrorAnalysisModuleDynamicManually.xcframework.zip, download the file.
  1. Unzip ContentsquareErrorAnalysisModuleDynamicManually.xcframework.zip and you should see ContentsquareErrorAnalysisModule.xcframework:
  2. Copy ContentsquareErrorAnalysisModule.xcframework to any folder in your project.
  3. In your target -> General -> Frameworks, Libraries and Embedded Content, add ContentsquareErrorAnalysisModule.xcframework by clicking ”+” -> “Add Other…” -> “Add Files…“.
  4. Clean build folder and run.
Get the manual integration framework
Section titled Get the manual integration framework
  1. Go to the iOS SDK GitHub repository.
  2. Find the newest version available (unless instructed otherwise by your CS contact).
  3. Under Assets you should be able to find ContentsquareErrorAnalysisModuleStaticManually.xcframework.zip, download the file.
  1. Unzip ContentsquareErrorAnalysisModuleStaticManually.xcframework.zip and you should see ContentsquareErrorAnalysisModule.xcframework:
  2. Copy ContentsquareErrorAnalysisModule.xcframework to any folder in your project.
  3. In your target -> General -> Frameworks, Libraries and Embedded Content, add ContentsquareErrorAnalysisModule.xcframework by clicking ”+” -> “Add Other…” -> “Add Files…“.
  4. Clean build folder and run.

You do not need to do anything to start the Error Analysis SDK, it will start itself with Contentsquare SDK.

When the SDK starts, you should see a log like this one:

// success case
Contentsquare Error Analysis v[SDKVersionNumber] starting in app:: [your.bundle.id]
// fail case
// << No public fail log

For best implementation practices of our library, explore the Contentsquare for iOS sample app.

API Errors automatically collects failed network requests that use URLSession.

Add custom monitoring for specific network requests

Section titled Add custom monitoring for specific network requests

The API Errors automatically collects most network requests for your app. However, some requests might not be collected or you might use a different library to make network requests. In these cases, you can use the following API HTTPMetric to manually collect data.

guard let url = URL(string: "https://www.apple.com") else { return }
let request: URLRequest = URLRequest(url: url)
let metric = HTTPMetric(request: request)
let session = URLSession(configuration: .default)
let dataTask = session.dataTask(with: request) { (urlData, response, error) in
if let httpResponse = response as? HTTPURLResponse {
metric.setStatusCode(httpResponse.statusCode)
}
metric.stop()
}
dataTask.resume()

If in-app features are enabled, a log should appear with the details of the event (see iOS Debugging and Logging section for more details).:

CSLIB ℹ️ Info: API Error - GET 401 https://api.client.com

The way our SDK works is by auto-starting with the application launch and automatically collects failed network requests that use URLSession.

Once started, our SDK fetches its config from our servers. It will start collecting data from network events if the API Errors setting is enabled in the config (this is handled by the Contentsquare team).

The SDK monitors only the API Errors with response code above 400, and generates analytics data. These events are then locally stored, and eventually sent to our servers in batches.

For each network error, a new event will be sent in analytics and Session Replay data. Check the following sections to learn more about how data is processed and sent:

Only network calls with error (response code above 400) will be collected. Here is the list of data collected:

  • URL (without query strings)
  • HTTP method
  • Response code
  • Timestamp of the request
  • Timestamp of the response

Known limitations and recommendations

Section titled Known limitations and recommendations

Automatic collection limitations

Section titled Automatic collection limitations

The auto collection doesn’t work for the following methods:

func data(for request: URLRequest) async throws -> (Data, URLResponse)
func data(from url: URL) async throws -> (Data, URLResponse)
func upload(for request: URLRequest, from bodyData: Data) async throws -> (Data, URLResponse)
func upload(for request: URLRequest, fromFile fileURL: URL) async throws -> (Data, URLResponse)
func download(for request: URLRequest) async throws -> (URL, URLResponse)
func download(from url: URL) async throws -> (URL, URLResponse)
func downloadTask(withResumeData: Data) -> URLSessionDownloadTask
func downloadTask(withResumeData: Data, completionHandler: (URL?, URLResponse?, Error?) -> Void) -> URLSessionDownloadTask
func streamTask(withHostName: String, port: Int) -> URLSessionStreamTask
func streamTask(with: NetService) -> URLSessionStreamTask
func webSocketTask(with: URL) -> URLSessionWebSocketTask
func webSocketTask(with: URLRequest) -> URLSessionWebSocketTask
func webSocketTask(with: URL, protocols: [String]) -> URLSessionWebSocketTask

Workaround: For the async methods, use the corresponding Contentsquare methods:

try await URLSession.shared.cs.data(for: request)
try await URLSession.shared.cs.data(from: url)
try await URLSession.shared.cs.upload(for: request, from: data)
try await URLSession.shared.cs.upload(for: request, fromFile: file)
try await URLSession.shared.cs.download(for: request)
try await URLSession.shared.cs.download(from: url)

For other methods, use the custom monitoring APIs.

Conflict with Firebase Performance SDK on auto-collection

Section titled Conflict with Firebase Performance SDK on auto-collection

API Errors doesn’t compatible with Firebase Performance auto collection.

Workaround: Disable Firebase automatic monitoring:

Performance.sharedInstance().isInstrumentationEnabled = false

It may also not compatible with other network auto collection.

We always strive to be non-intrusive, and transparent to the developers of the client app. We apply this rule on the performance as well. These are the technical specifics we can share on performance, if you have any questions feel free to reach out to us.

The following performance results were obtained under the following conditions:

ConditionValue
Device modeliPhone X 64GB
iOS version16.1
Test App built using Xcode version13.4.1
Test App built with Swift version5.6.1
PropertyValue
SDK size (installed size, no Bitcode)770 KB
Max Ram usage<4Mb
Max SDK CPU peak on event<1%
Data transmitted over network for a default batch size of 50 events