lytics / ios-sdk

MIT License
0 stars 0 forks source link

Public Interface #1

Closed mgacy closed 2 years ago

mgacy commented 2 years ago

Adds a Swift Package with a basic public interface

Usage

The developer could define relevant types for their application to provide type safety and enable autocomplete in Xcode.

struct MyIdentifier: Codable {
    var userID: String
    var email: String?
}

struct MyConsent: Codable {
    var document: String
    var timestamp: String
    var consented: Bool
}

struct MyProperties: Codable {
    var firstName: String
    var lastName: String
    var title: String
}

struct MyCart: Codable {
    var orderId: String
    var total: Int
}

Then ...

Story: developer emits an event with details specific to consent/GDPR and simultaneously opts the app user in

let identifier = MyIdentifier(
    userID: "this-users-known-id-or-something",
    email: "someemail@lytics.com")

let consent = MyConsent(
    document: "gdpr_collection_agreement_v1",
    timestamp: "46236424246",
    consented: true)

let properties = MyProperties(
    firstName: "Mark",
    lastName: "Hayden",
    title: "VP Product")

Lytics.shared.consent(
    stream: "iosIdentify",
    identifiers: identifier,
    properties: properties,
    consent: consent)

Story: developer identifies the current app user

let identifier = MyIdentifier(
    userID: "this-users-known-id-or-something",
    email: "someemail@lytics.com")

let attributes = MyProperties(
    firstName: "Mark",
    lastName: "Hayden",
    title: "VP Product")

Lytics.shared.identify(
    stream: "ios",
    name: "cart_add",
    identifiers: identifier,
    attributes: attributes)

Story: developer wants to track a screen event when the app user navigates to a new view

Lytics.shared.screen(
    stream: "iOS",
    name: "cart_add",
    identifiers: MyIdentifier(userID: "this-users-known-id-or-something"),
    properties: MyCart(orderId: "some-order-id", total: 1995))