How to track Video analytics in iOS using SDK?

Hi,

I have been trying for two days to get Video analytics working using the iOS SDK and can’t work out why it doesn’t work. I am using the “custom tracking parameters” example as a basis. I get a success response with a tracked flag set. However it never shows up as a Video event, and mostly it doesn’t even show up at all.

My code:

    var asMatomoEvent : [String:String] {
        var parameters = [String:String]()
        parameters["ma_id"] = uniqueId
        parameters["ma_ti"] = title
        parameters["ma_re"] = url.absoluteString
        parameters["ma_mt"] = type
        parameters["ma_pn"] = player
        if let currentTimeSeconds = currentTimeSeconds, currentTimeSeconds.isNaN == false {
            parameters["ma_st"] = String(format: "%.2f", currentTimeSeconds)
        }
        if let videoSize = videoSize {
            parameters["ma_w"] = "\(videoSize.width)"
            parameters["ma_h"] = "\(videoSize.height)"
        }
        parameters["ma_fs"] = fullscreen ? "1" : "0"
        return parameters
    }

    func trackMediaEvent(action: String, mediaEvent: MediaEvent) {
        
        let trackingParameters = mediaEvent.asMatomoEvent
        
        let event = Event(tracker: self.tracker,
                          action: [action, "custom tracking parameters"],
                          url: mediaEvent.url,
                          eventCategory: "MediaVideo",
                          eventAction: action,
                          customTrackingParameters: trackingParameters)
        
        self.tracker.track(event)
        #if DEBUG
        tracker.dispatch()
        #endif
    }

   trackVideoEvent(action: progress > 0.0 ? "pause" : "play")

I have verbose logging on and am using Charles to verify that the messages are being sent and received by Matomo.

Any help would be greatly appreciated as I have been working on this for days.
Brett

I have found the issues:

  1. “ma_st” is a mandatory field
  2. All parameters must be whole numbers, ie, not “4.56” seconds for ma_st or ma_w etc.

It would have helped if the API could have returned me an error, any kind of error. Instead it tells you it was a success with a 200, a success flag of true, and even a tracked flag of true when it doesn’t get tracked.

Hi @iOSBrett

I just had a look sending eg 4.56 for ma_st should work as it would be simply converted to an integer. In this case 4. The parameter is also not really a mandatory field. it defaults to 0 and should still show up in the reports that the media was viewed, but not played. As soon as the user spent some time watching the media, we’d recognise it as a play.

Hi Thomas,

My testing has shown that not to be the case. The analytics for that event just don’t show up unless I specify the ma_st field and make all time params integer. I spent many hours over 2 days on this. Even if I am wrong about those fields (which I don’t feel I am) the analytics API returns success:1, tracked:1 and 200 and then doesn’t show up anywhere that I can find in the dashboard/events/media etc.

Is there a way for me to see what the Matomo service is receiving in real time, even for things that don’t appear on the dashboard, like a verbose log ? If I can solve what is going on then I am interested in implementing MediaTracking in the iOS SDK for others to use.

:slight_smile:

I double checked my findings and I was right about one thing and wrong about one thing:

  • “ma_st”: If not sent then the analytics never shows up in Matomo
  • All parameters must be Integers: I was wrong. The width and height parameters must be integers and not float, not the seconds parameters as I said earlier.
    In iOS width and height properties are always Float values, so it seemed normal to me to try and send float values for these.

Hi,

Just to quickly answer this question:

In case you don’t know it yet, https://developer.matomo.org/api-reference/tracking-api#debugging-the-tracker might help you as it makes Matomo respond with a verbose log to the matomo.php request.

Hi,

That looks really helpful, thanks Lukas.