Protocol
PageTrackerProtocol
@objc(PermutivePageTrackerProtocol)
public protocol PageTrackerProtocol: AdTargetable
A protocol defining the interface of a Page Tracker component.
The Page Tracker component is responsible for tracking a user's engagement with a page. Engagement is measured by the time a user stays on a page and the amount of content seen. A trackEvent function is supplied to allow tracking of any event through the PageTrackerProtocol instance. This is recommended to improve segmentation data.
The Page Tracker will start to time the engagement on start, it can be paused and resumed after starting and before stopping.
Custom events will only be tracked once a PageTrackerProtocol instance has been started and before it has been stopped.
PageTracker Usage:
-
Initialise:
var pageTracker: PageTrackerProtocol
do {
let properties = EventProperties(...)
let pageContext = Context(title: "<page title>", url: <page url>)
pageTracker = try Permutive.shared.createPageTracker(properties: properties, context: pageContext)
} catch {
// Handle error
}
-
Start/resume:
do {
try pageTracker.resume()
} catch {
// Handle error
}
-
Track a custom event:
do {
try pageTracker.trackEvent(name: "CTAPressed",
properties: EventProperties(["name": "value"]))
} catch {
// Handle error
}
-
Update percentage of view seen
pageTracker.updateViewed(percentage: 0.5)
Relationships
Conforms To
AdTargetable
Requirements
resume()
func resume() throws
Starts or resumes the PageTracker. Will resume the engagement timer, can be used if the app come back in foreground, or at any other relevant time.
Resuming after stopping has no effect.
pause()
func pause()
Will pause the engagement timer, can be used if the app go in background, or at any other relevant time.
Pausing before starting or after stopping has no effect.
stop()
func stop()
Will stop the engagement timer, can be used when a user transition to another page, or at any other relevant time. The final engagement time will be send to the engine, with the original EventProperties passed in parameter on start.
updateViewed(percentage:)
func updateViewed(percentage: Float)
Once a Page Tracker has been started you can use this method to update the amount of content an user has seen on a page.
Will do nothing once the Page Tracker has been stopped.
Parameters
| Name | Type | Description |
|---|---|---|
| percentage | Float |
The percentage of view which have been seen by the user, expressed in percentage from 0 to 1. |
track(event:properties:)
func track(event: String, properties: EventProperties?) throws
This method tracks an event for this page with the Context supplied on creation of the PageTracker.
Tracking an event may be performed before starting the PageTracker, however tracking an event after
stopping in not permissable and will throw an exception.
Parameters
| Name | Type | Description |
|---|---|---|
| event | String |
The name of the page event to track. |
| properties | EventProperties? |
The optional properties of the page event. |