lytics / ios-sdk

MIT License
0 stars 0 forks source link

Add Demo App Project #10

Closed mgacy closed 2 years ago

mgacy commented 2 years ago

Adds an iOS SwiftUI app project to /Examples/ using the SDK. Also adds types and default values to LyticsConfiguration and fixes the signature of Lytics.start(_:).

humanchimp commented 2 years ago

I was seeing some errors in Xcode when i was taking a look at the playground. It seems like consent should be a bool instead of a string. I was a bit concerned that the types are not matching, and i was wondering if we are setting ourselves up to only be able to send string values. we want to be able to send any primitive that encodes to JSON, so strings, bools, numbers and null

mgacy commented 2 years ago

Apologies @humanchimp , I failed to add you to #1 ; those errors are specific to the stub that Mark wrote. The actual SDK supports arbitrary user-defined types (so long as they are Encodable to JSON). The idea being that the SDK user would define types representing their data:

// SDK user defines custom types for their data
struct MyIdentifier: Codable {
    var userID: String
    var email: String?
}

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

struct MyAttributes: Codable {
    var firstName: String
    var lastName: String
    var title: String
    var roles: [String]
}

// Usage
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 attributes = MyAttributes(
    firstName: "Mark",
    lastName: "Hayden",
    title: "VP Product",
    roles: ["something", "another thing"]

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

This approach offers flexibility and the type safety Swift developers expect

humanchimp commented 2 years ago

Excellent. I should have noticed that. Thanks