Not receiving Metric Kit payload

Hello all,

I wanted to get MXMetricPayload to analyse some App metrics. And for some reason the method func didReceive(_ payloads: [MXMetricPayload]) from mxMetricManager is not being executed.

For this I created a Class:

import MetricKit

public final class MetricKitManagerImpl: NSObject, MetricKitManager {
	public static let shared: MetricKitManager = MetricKitManagerImpl(mxMetricManager: MXMetricManager.shared)

    private let mxMetricManager: MXMetricManager

    private init(
        mxMetricManager: MXMetricManager
    ) {
        self.mxMetricManager = mxMetricManager
        super.init()
        mxMetricManager.add(self)
    }
    deinit {
        mxMetricManager.remove(self)
    }

    public func didReceive(_ payloads: [MXMetricPayload]) {
        payloads.forEach {
            if let scrollHitchTimeRatio = $0.animationMetrics?.scrollHitchTimeRatio.value {
            	sendToSomeWhere(scrollHitchTimeRatio)
            }
        }
    }
}

Then on the AppDelegate on didFinishLaunchingWithOptions I do:

private(set) var metricsManager: MetricKitManager!

func application(
    _ application: UIApplication, 
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
    
    self.metricsManager = MetricKitManagerImpl.shared
    ...
}

With this setUp I am able to receive the debug playload (triggered from Xcode Menu. Debug -> Simulate Metrik Kit Payload). However, after using the app for some days, I did not receive any real payload.

Did anyone experience this? What am I doing wrong?

Thanks a lot in advance! Miguel Franco

  • In case it wasn't obvious, your app needs some usage. Make sure that you're using it. You should be getting data periodically when the app runs if you're a subscriber.

    One of the best ways I have found to 'make sure it continues to work' during internal team TestFlight builds is to show a notification when ever a metric or diagnostic payload has been received. Every morning like clockwork, when I use the app (or a background feature kicks in), I get a metric push notification.

Add a Comment