iOS native application instrumentation


The installation is done through Cocoapods, adding the following line to the Podfile file:

pod 'MarfeelSDK-iOS', '~> 2.3.0'


To use the library you should add the account ID provided by Compass when you registered. Within the file Info.plist, add the following properties:

You only need to change $$YOUR_COMPASS_ACCOUNT_ID_TO_BE_REPLACED$$ placeholder and leave the rest of the code as you see it.


To be able to use the library, import the MarfeelSDK_iOS module:

import MarfeelSDK_iOS

All the library functionalities are done through the CompassTracker class. To access CompassTracker, use the shared variable in any part of the application

let tracker = CompassTracker.shared

Page Tracking

CompassTracker automatically counts the time the user stays on a page. If you want to start tracking a specific page use the method startPageView, indicating the URL of a page.

tracker.trackNewPage(url: {URL})

CompassTracker will keep counting the time on page until a new call is made to trackNewPagewith a different URL. Alternatively you can instruct Compass to stop tracking via stopTracking()

tracker.startPageView() has been deprecated in favor of tracker.trackNewPage()

Scroll tracking

If you want to count the scroll percentage of a user on a page, indicate in the startPageView method the UIScrollView

tracker.trackNewPage(url: {URL}, scrollView: {UIScrollView}})

User identification

To associate the app user to the records generated by the library, use the method serUserId, indicating the user ID in your platform.

tracker.setUserId() has been deprecated in favor of tracker.setSiteUserId()

You can also provide the user type. If the method is not invoked the user will be tracked as Anonymous.


It’s recommended to indicate the ID and the user type before starting to track the user identification.

User page information

tracker.setPageVar(name: "name",  value: "value")

User session information

tracker.setSessionVar(name: "name",  value: "value")

User information

tracker.setUserVar(name: "name", value: "value")

User segments

Adds a new persistent user segment


Replaces existing user segments

tracker.setUserSegments(["segment1", "segment2"])

Removes existing user segment


Clears all user segments


Custom page technology

Overrides default page technology. By default, iOS will be used for categorizing your tracking.

Only values greater than 100 are allowed for using as custom page technology.


If you want to obtain the Compass RFV code, use the method getRFV. This method returns the RFV code within a handler

tracker.getRFV { rfv in
//Returned rfv management

Conversion tracking

If you want to track a conversion, you can call the method track(conversion: String):

tracker.trackConversion(conversion: "{CONVERSION}")
tracker.track(conversion: "{CONVERSION}") has been deprecated in favor of tracker.trackConversion(conversion: "{CONVERSION}")

Multimedia Tracking

All multimedia tracking features are made available through a MultimediaTracking instance. To access MultimediaTracker, use the shared variable in any part of the application

let multimediaTracker =  CompassTrackerMultimedia.shared

Exposed interfaces

public protocol MultimediaTracking {
    func initializeItem(id: String, provider: String, providerId: String, type: Type, metadata: MultimediaMetadata)
    func registerEvent(id: String, event: Event, eventTime: Int)

public enum Event: String, Codable {
    case PLAY = "play"
    case PAUSE = "pause"
    case END = "end"
    case UPDATE_CURRENT_TIME = "updateCurrentTime"
    case AD_PLAY = "adPlay"
    case MUTE = "mute"
    case UNMUTE = "unmute"
    case FULL_SCREEN = "fullscreen"
    case BACK_SCREEN = "backscreen"
    case ENTER_VIEWPORT = "enterViewport"
    case LEAVE_VIEWPORT = "leaveViewport"

public enum Type: String, Codable {
    case VIDEO = "video"
    case AUDIO = "audio"

public struct MultimediaMetadata: Codable {
    var isLive = false
    var title: String?
    var description: String?
    var url: String?
    var thumbnail: String?
    var authors: String?
    var publishTime: Int64?
    var duration: Int?

To initialize a new media

    provider: "youtube",
    providerId: "youtube-video-id",
    type: .VIDEO,
    metadata: MultimediaMetadata.init(
        title: "title",
        description: "description",
        url: URL(string: ""),
        authors: "authors",
        duration: 420

To track a new event

CompassTrackerMultimedia.shared.registerEvent(id: "videoId", event: .UPDATE_CURRENT_TIME, eventTime: 150))
1 Like