Permutive_iOS v1.4.0 Documentation

Class Permutive

@objc
public final class Permutive: NSObject  
Permutive Permutive NSObject NSObject Permutive->NSObject

Conforms To

NSObject

Properties

shared

@objc
    public static let shared  

segments

@objc
    public var segments: Set<Int>  

The current set of segments entered.

reactions

@objc
    public var reactions: [String: [Int]]  

The current enterd segments for each defined activation.

current​User​Id

@objc
    public var currentUserId: String?  

The current active user id.

trigger​Provider

@objc
    public var triggerProvider: TriggerProviderProtocol?  

An instance which provides TriggerAction instances. Used to watch for changes in segment states. TriggerAction instances are held with weak references in the SDK.

Methods

google​Custom​Targeting(ad​Targetable:​)

@objc
    public func googleCustomTargeting(adTargetable: AdTargetable? = nil) -> [String: String]?  

Permutive custom targeting for GoogleMobileAds for use with ad requests.

This returns current Permutive segment information suitable for custom targeting, e.g. GAMRequest.customTargeting.

Those information can be retrieved without a parameter but if the targeting relates to content being tracked by a PageTracker instance, it is recommended to pass that instance for best results.

Usage:

let banner = GAMBannerView(adSize: kGADAdSizeBanner)
let adRequest = GAMRequest()
adRequest.customTargeting = Permutive.shared.googleCustomTargeting(adTargetable: pageTracker)
banner.load(request)

Parameters

ad​Targetable AdTargetable?

An entity implementing the AdTargetingProtocol, currently a PageTracker

Returns

A dictionary that can be use with GAMRequest.customTargeting, see usage

set​Identity(alias:​priority:​expiry:​)

@objc
    public func setIdentity(alias: String, priority: UInt16, expiry: Date) throws  

set​Identity(alias:​priority:​)

@objc
    public func setIdentity(alias: String, priority: UInt16) throws  

set​Identity(alias:​expiry:​)

@objc
    public func setIdentity(alias: String, expiry: Date) throws  

set​Identity(alias:​)

@objc
    public func setIdentity(alias: String) throws  

set​Identities(aliases:​)

@objc
    public func setIdentities(aliases: [Alias]) throws  

start(with:​context:​completion:​)

@objc
    public func start(with options: Options, context contextVals: Context? = nil, completion: @escaping (_ error: Error?) -> Void)  

Starts the Permutive SDK with the given Options and optional Context. Once started the SDK is ready to track events. A provided callback is executed on completion.

Parameters

options Options

The Options instance containing the organisationId, workspaceId, and apiKey

context​Vals Context?

A Context instance for use when tracking events

completion @escaping (_ error:​ Error?) -> Void

A closure executed asynchronously. On completion without errors, the SDK is ready to accept event tracking requests.

error

An error, if any, encountered when starting the SDK. A nil error represents success.

stop()

@objc
    public func stop()  

Stops the Permutive SDK and releases resources.

track(event:​properties:​)

@objc
    public func track(event: String, properties: EventProperties? = nil) throws  

Tracks an event.

Parameters

event String

The event name. E.g. "Pageview".

properties Event​Properties?

An optional EventProperties instance containing desired metadata to be attached to the event.

Throws

MessagedError.sdkInitialisation if tracking is attempted before the SDK has successfully started.

create​Page​Tracker(properties:​context:​)

@objc
    public func createPageTracker(properties: EventProperties? = nil, context: Context? = nil) throws -> NSObject & PageTrackerProtocol  

Constructs a PageTracker. This allows tracking of events within the context of a single "page" or view. This allows tracking the amount of a page viewed by a user as well as the time spent interacting with the page.

PageTracker Use

A PageTracker's expected use is to be associated with individual "page" or view. It is created with supplied Context information. This context is included with all events tracked through the PageTracker instance for improved tracking of events. Usage is expected to follow the sequence:

  1. A PageTracker instance is created with Context for a "page" or view. This can be done prior or on transition to a view.
  2. On transition to a new view, the associated PageTracker.start(properties:) is called. This tracks a "Pageview" event immediately.
  3. Further information on page events are tracked through PageTracker.track(event:, properties:) at appropriate times.
  4. When about to leave a view, PageTracker.stop() is called and the instance can be released if no longer needed. A PageTracker will not be usable after stop() is called.

Parameters

context Context?

An optional Context instance containing desired context to be attached to the returned PageTrackerProtocol instance.

Throws

MessagedError.sdkInitialisation if tracking is attempted before the SDK has successfully started.

Returns

A instance meeting the PageTrackerProtocol. No strong references are kept by the SDK.

create​Video​Tracker(duration:​properties:​context:​)

@objc
    public func createVideoTracker(duration: TimeInterval = 0,
                                   properties: EventProperties? = nil,
                                   context: Context? = nil) throws -> NSObject & MediaTrackerProtocol  

Constructs a video tracker. This allows tracking of interaction with video content.

Parameters

duration Time​Interval

A TimeInterval denoting video duration. If live streamed or duration unknown at creation, use TimeInteval.infinity.

properties Event​Properties?

A EventProperties instance for the properties of tracker generated events.

context Context?

An optional Context instance containing desired context to be attached to the returned PageTrackerProtocol instance.

Throws

MessagedError.sdkInitialisation if tracking is attempted before the SDK has successfully started.

Returns

A instance meeting the MediaTrackerProtocol. No strong references are kept by the SDK.

reset()

@objc
    public func reset() throws  

Resets persisted data.

Throws

MessagedError.sdkInitialisation if tracking is attempted before the SDK has successfully started.

reserved_0()

@objc
    public func reserved_0() -> String?  

Internal use only.