Analytics

The PSPDFKit Analytics API allows you to easily collect usage data based on a user’s activity taking place in PSPDFKit components.

The PSPDFKit Analytics API consists of:

  • A PDFAnalytics object that you can access through a shared PSPDFKit instance

  • A PDFAnalyticsClient protocol that you need to implement to capture analytics events

Integration

The PSPDFKit Analytics API comes bundled with PSPDFKitUI.xcframework, so you don’t need to add any external packages. Just ensure you’re importing the PSPDFKitUI module in your file wherever you’re using this API.

Enable Analytics

The PSPDFKit Analytics API is disabled by default, so you first need to enable it to use it:

PSPDFKit.SDK.shared.analytics.enabled = true
PSPDFKitGlobal.sharedInstance.analytics.enabled = YES;

Next, you need to implement the PDFAnalyticsClient protocol. Your PDFAnalyticsClient is a place to process PSPDFKit events and pass them to the analytics service of your choice.

Be aware that events are delivered on a background queue.

Create an instance of your PDFAnalyticsClient when the app launches (preferably at the same time you’re configuring the PSPDFKit license) and register it with PDFAnalytics:

let analyticsClient = YourAnalyticsClient()
PSPDFKit.SDK.shared.analytics.add(analyticsClient)
id<PSPDFAnalyticsClient> analyticsClient = [[YourAnalyticsClient alloc] init];
[PSPDFKitGlobal.sharedInstance.analytics addAnalyticsClient:analyticsClient];

You can find a simple PDFAnalyticsClient implementation in AnalyticsClientExample.swift in the PSPDFKit Catalog app.